Files
LithosAnanake/experiments/std79-doe/std79-doe.fth
T
Robert Allan JamesandClaude Sonnet 5 403a7639e1
Build / build-amd64-iso (push) Waiting to run
Build / build-aarch64-iso (push) Waiting to run
Build / build-riscv64-img (push) Waiting to run
Bracket std79 DoE trial loop with HB-ON/HB-OFF, capture real heartbeat CSVs
Every prior std79-doe.fth run's automatically-extracted CSV
(scripts/extract_doe.sh) was silently empty -- g_doe_log_enabled
(doe_log.c) defaults off, and nothing in the campaign ever called HB-ON.
EXEC-STD79-DOE now calls HB-ON right before its trial loop and HB-OFF
right after, so the per-heartbeat-tick physics/timing CSV (18 columns:
tick_number, hot_word_count, avg_word_heat_q48, apic_ticks, per-VM
heat_q48, etc.) finally covers the run's own window on all three
architectures.

Found and fixed two bugs along the way, one in a comment and one in the
ad hoc QEMU orchestration script used to drive these runs (not part of
this repo):

- std79-doe.fth's own explanatory comment accidentally spelled out the
  literal "[HADES][DOE ]" tag string doe_log.c prefixes each row with --
  the FORTH REPL's compile-time echo of that comment then matched
  scripts/extract_doe.sh's own extraction grep, corrupting the first
  extracted CSV row with comment text instead of real telemetry. Fixed by
  never spelling out the literal substring.

- The harness script's completion-detection watched for "STD79-DOE:
  complete" anywhere in the log since before the whole capsule was fed,
  which matches the colon definition's own compile-time echo of that same
  string literal, not just the real end-of-run print. Without HB-ON the
  entire 27-trial run finished in a few seconds -- faster than one poll
  interval -- so the false match and the real one always landed in the
  same window and this never surfaced. HB-ON's added per-tick console I/O
  slowed real execution enough to expose it: the script sent BYE the
  moment compilation finished, truncating every trial after whatever
  point compilation had reached (aarch64 lost 9 of 27 trials this way on
  the first attempt). Fixed by feeding definitions and invocation as two
  genuinely separate connections, with the completion-watch window opened
  only after compilation is confirmed landed.

Verified 27/27 trials correct on every architecture via the campcampaign's
most distinctive result markers (both M*/M/MOD 18-19 digit values and the
2147483648 2/ result, all exactly 27 occurrences, zero faults) rather than
exact substring reconstruction: HB-ON's async per-tick CSV printer and the
trial loop's own console output share the same serial line with no
locking, so CSV rows can splice mid-token into trial output on the wire
(confirmed live -- cosmetic only, the underlying FORTH execution and
values are unaffected). results-20260912-with-heartbeat-csv/ holds both
the raw logs and their paired heartbeat CSVs; the earlier truncated runs'
logs are kept too (never delete logs) as the record of how this was found.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXieurDfDSsDFdnSyusuWo
2026-09-12 10:44:00 -04:00

198 lines
7.5 KiB
Forth

( std79-doe.4th - 3(arch, fixed per boot) x 9(identity) x 3(rep) )
( randomized full-factorial DoE. Same 24-case content as )
( std79-exerciser.fth, driven via VM-EXEC into each identity's own )
( live VM (all 9 pre-attached before this runs); "zuse" dispatches )
( into "Hera" herself since her power is a session flag on Hera, )
( not a separate registered VM. Fisher-Yates shuffle matches )
( doe.4th's own algorithm/style; seed fixed for cross-architecture )
( reproducibility (same permutation applied on every arch). )
9 CONSTANT N-ID
3 CONSTANT N-REPS
27 CONSTANT N-RUNS
24 CONSTANT N-TESTS
: ID-NAME ( idx -- c-addr u )
CASE
0 OF S" Hera" ENDOF
1 OF S" rajames" ENDOF
2 OF S" 00" ENDOF
3 OF S" 01" ENDOF
4 OF S" 02" ENDOF
5 OF S" 03" ENDOF
6 OF S" 04" ENDOF
7 OF S" 05" ENDOF
8 OF S" 06" ENDOF
ENDCASE ;
: ID-LABEL ( idx -- c-addr u )
CASE
0 OF S" zuse" ENDOF
1 OF S" rajames" ENDOF
2 OF S" 00" ENDOF
3 OF S" 01" ENDOF
4 OF S" 02" ENDOF
5 OF S" 03" ENDOF
6 OF S" 04" ENDOF
7 OF S" 05" ENDOF
8 OF S" 06" ENDOF
ENDCASE ;
( idx 0 (zuse) runs natively on Hera -- never via VM-EXEC targeting )
( "Hera" herself: VM-EXEC's own vm_state_push/pop only saves )
( rsp/exit_colon/ecw_nesting, not input_buffer/input_pos, so a )
( self-targeting call while THIS capsule's own vm_interpret call is )
( still mid-line would risk clobbering the outer parse -- the exact )
( class of bug the idle-tick reentrancy guards (repl.c) exist for, )
( just not covered by VM-EXEC's own narrower state stack. Sidestepped )
( entirely by never dispatching a string back into the caller's own )
( VM; the same 24 cases are just directly-compiled code below. )
: RUN-TEST-NATIVE ( n -- )
CASE
0 OF 7 3 /MOD SWAP . . ENDOF
1 OF -7 3 /MOD SWAP . . ENDOF
2 OF 7 -3 /MOD SWAP . . ENDOF
3 OF -7 -3 /MOD SWAP . . ENDOF
4 OF 2147483647 1 + . ENDOF
5 OF -2147483648 NEGATE . ENDOF
6 OF -2147483648 ABS . ENDOF
7 OF -1 1 RSHIFT . ENDOF
8 OF -8 2 RSHIFT . ENDOF
9 OF 1 31 LSHIFT . ENDOF
10 OF -1 0 < . ENDOF
11 OF -1 0 U< . ENDOF
12 OF 123 456 M* SWAP D. ENDOF
13 OF -123 456 M* SWAP D. ENDOF
14 OF 100000 S>D SWAP 7 M/MOD . . ENDOF
15 OF 7 11 3 */ . ENDOF
16 OF 7 11 3 */MOD SWAP . . ENDOF
17 OF -5 S>D SWAP D. ENDOF
18 OF -5 S>D 3 S>D D+ SWAP D. ENDOF
19 OF -5 S>D DNEGATE SWAP D. ENDOF
20 OF -5 3 MIN . -5 3 MAX . ENDOF
21 OF 5 0 10 WITHIN . ENDOF
22 OF -1 0 AND . -1 0 OR . 5 3 XOR . ENDOF
23 OF -2147483648 2/ . ENDOF
ENDCASE ;
: TEST-CMD ( n -- c-addr u )
CASE
0 OF S" 7 3 /MOD SWAP . ." ENDOF
1 OF S" -7 3 /MOD SWAP . ." ENDOF
2 OF S" 7 -3 /MOD SWAP . ." ENDOF
3 OF S" -7 -3 /MOD SWAP . ." ENDOF
4 OF S" 2147483647 1 + ." ENDOF
5 OF S" -2147483648 NEGATE ." ENDOF
6 OF S" -2147483648 ABS ." ENDOF
7 OF S" -1 1 RSHIFT ." ENDOF
8 OF S" -8 2 RSHIFT ." ENDOF
9 OF S" 1 31 LSHIFT ." ENDOF
10 OF S" -1 0 < ." ENDOF
11 OF S" -1 0 U< ." ENDOF
12 OF S" 123 456 M* SWAP D." ENDOF
13 OF S" -123 456 M* SWAP D." ENDOF
14 OF S" 100000 S>D SWAP 7 M/MOD . ." ENDOF
15 OF S" 7 11 3 */ ." ENDOF
16 OF S" 7 11 3 */MOD SWAP . ." ENDOF
17 OF S" -5 S>D SWAP D." ENDOF
18 OF S" -5 S>D 3 S>D D+ SWAP D." ENDOF
19 OF S" -5 S>D DNEGATE SWAP D." ENDOF
20 OF S" -5 3 MIN . -5 3 MAX ." ENDOF
21 OF S" 5 0 10 WITHIN ." ENDOF
22 OF S" -1 0 AND . -1 0 OR . 5 3 XOR ." ENDOF
23 OF S" -2147483648 2/ ." ENDOF
ENDCASE ;
CREATE RUN-MATRIX N-RUNS CELLS ALLOT
: MATRIX! ( val idx -- ) CELLS RUN-MATRIX + ! ;
: MATRIX@ ( idx -- val ) CELLS RUN-MATRIX + @ ;
VARIABLE SW-I VARIABLE SW-J VARIABLE SW-VI VARIABLE SW-VJ
: SWAP-MTX ( i j -- )
SW-J ! SW-I !
SW-I @ MATRIX@ SW-VI !
SW-J @ MATRIX@ SW-VJ !
SW-VJ @ SW-I @ MATRIX!
SW-VI @ SW-J @ MATRIX! ;
: INIT-MATRIX ( -- ) N-RUNS 0 DO I I MATRIX! LOOP ;
: SHUFFLE-MATRIX ( -- )
N-RUNS 1 - 0 DO
I N-RUNS 1 - RANDOM
I SWAP-MTX
LOOP ;
VARIABLE CURR-ID
VARIABLE CURR-REP
( Boot-batching support, added 2026-09-11 (FABRIC-3.md SXV). Originally a )
( workaround for a real aarch64 Stadium/COOL scaling bug -- root-caused and )
( fixed 2026-09-11/12 (FABRIC-3.md SXVI, src/starkernel/vm/stadium.c): )
( stadium_grant_quota() halves the granting VM's own free list on every )
( birth with no floor, and stadium_admit()'s eviction fallback used to scan )
( the ENTIRE global cell array (stadium_ncells, in the hundreds of )
( thousands on aarch64's larger RAM-scaled Stadium) filtered by owner, )
( instead of walking just the calling VM's own resident cells as its own )
( doc comment already claimed -- fixed by threading a real per-VM resident )
( list. A single boot with all 9 identities simultaneously live now works )
( cleanly on all three architectures (see results-20260911-stadium-fix/), )
( so ACTIVE-LO/ACTIVE-HI is no longer load-bearing -- kept only as general )
( flexibility: every boot shares the SAME seed so INIT-MATRIX/SHUFFLE-MATRIX )
( produce the identical master 27-slot permutation regardless of how many )
( boots this runs across; only the ACTIVE-LO/ACTIVE-HI filter differs if )
( split. The recorded run_id is always I itself (the slot's true position )
( in the master shuffle), never a separately-incremented counter, so row )
( order stays meaningful and comparable across any number of boots. )
VARIABLE ACTIVE-LO
VARIABLE ACTIVE-HI
: ACTIVE? ( idx -- flag )
DUP ACTIVE-LO @ >=
SWAP ACTIVE-HI @ <=
AND ;
: RUN-TEST ( n -- )
CURR-ID @ 0= IF
RUN-TEST-NATIVE
ELSE
TEST-CMD CURR-ID @ ID-NAME VM-EXEC
THEN ;
VARIABLE CURR-RUN-ID
: RUN-TRIAL ( id-idx rep run-id -- )
CURR-RUN-ID !
CURR-REP ! CURR-ID !
." DOE-RUN," CURR-RUN-ID @ . ." ," CURR-ID @ . ." ,"
CURR-ID @ ID-LABEL TYPE ." ," CURR-REP @ . CR
N-TESTS 0 DO I RUN-TEST LOOP ;
( HB-ON/HB-OFF (doe_log.c) bracket the trial loop below so the per-tick )
( DoE-tagged physics/heartbeat CSV -- 18 columns: tick_number, elapsed_ns, )
( hot_word_count, avg_word_heat_q48, window_width, apic_ticks, )
( hera/hermes/artemis heat_q48, etc. -- covers exactly this run's window, )
( not the whole boot. g_doe_log_enabled defaults OFF (doe_log.c), so )
( every prior campaign run's extracted CSV (scripts/extract_doe.sh, run )
( automatically at the end of every `make qemu`) was silently empty; )
( without this bracket there is no per-tick data to analyze the 3x9x3 )
( factorial's physics behavior by, only the DOE-RUN/DOE-HEADER correctness )
( lines already printed below. NOTE: this comment deliberately never )
( spells out the literal tag string doe_log.c prefixes each row with -- )
( writing it here once already corrupted a real extracted CSV live )
( 2026-09-12, since scripts/extract_doe.sh greps the log for exactly that )
( substring and can't tell a real telemetry row from this comment's own )
( compile-time echo saying the same characters. )
: EXEC-STD79-DOE ( seed lo hi -- )
ACTIVE-HI ! ACTIVE-LO !
SEED
INIT-MATRIX SHUFFLE-MATRIX
." DOE-HEADER,run_id,id_idx,id_label,rep" CR
HB-ON
N-RUNS 0 DO
I MATRIX@
DUP N-REPS /
DUP ACTIVE? IF
SWAP N-REPS MOD I RUN-TRIAL
ELSE
DROP DROP
THEN
LOOP
HB-OFF
." STD79-DOE: complete" CR ;