Skip to content

fix(fasl): replay per-form value echo on a warm load hit (#40)#41

Merged
pyrex41 merged 1 commit into
mainfrom
fix/fasl-load-echo
Jul 21, 2026
Merged

fix(fasl): replay per-form value echo on a warm load hit (#40)#41
pyrex41 merged 1 commit into
mainfrom
fix/fasl-load-echo

Conversation

@pyrex41

@pyrex41 pyrex41 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Problem

(load FILE) prints each top-level form's evaluated value (klambda/load.klshen.eval-and-print on the raw path, shen.work-through on the tc path) before returning loaded. On a warm FASL-cache hit, boot.lua returned loaded straight out of fasl_replay without re-running the kernel load, so that echo was dropped. (load ...) stdout therefore depended on cache state:

  • cross-port divergence — warm shen-lua vs shen-rust / shen-go / shen-cl (which always echo);
  • intra-port nondeterminism — shen-lua cold (SHEN_FASL=off) ≠ shen-lua warm.

Fixes #40. Surfaced by Bifrost cases/divergences.json → load-toplevel-echo.

Fix

Capture the echo faithfully rather than re-deriving it:

  • During a miss, the per-form echo is the only pr to (stoutput) that fires while inside shen.load-help with rec.in_chunk false. (A form's own (output ...) side effects fire with in_chunk true and already replay by re-running the chunk.) Record those bytes as a new "e" record in stream order, right after each form's "c" chunk.
  • On a hit, fasl_replay re-prs each "e" record to (stoutput).

Consequences that fall out for free:

  • Interleaving with side-effect output is preserved (echo record follows its chunk in the stream).
  • Going through the live pr keeps *hush* gating at replay time — a -q hit stays silent, exactly like a -q cold load. Bytes are captured even under *hush* (the string is computed regardless), so a miss recorded under -q still replays correctly to a non-hushed hit.
  • The cosmetic run time: / typechecked in N inferences banners are emitted by load outside shen.load-help, so rec.echoing excludes them — they stay dropped by design (per-run timing noise that would break cross-port comparison).

FASL_FORMAT bumped 3 → 4; stale caches miss and recompile cleanly.

Verification

🤖 Generated with Claude Code

`(load FILE)` prints each top-level form's evaluated value (klambda/load.kl
shen.eval-and-print / shen.work-through) before returning `loaded`. On a warm
FASL-cache hit boot.lua returned `loaded` straight out of fasl_replay without
re-running the kernel `load`, so that echo was dropped: `(load ...)` stdout
depended on cache state — a cross-port divergence (shen-rust/shen-go always
echo) and an intra-port nondeterminism (cold != warm).

Capture the echo faithfully instead of re-deriving it. During a miss, the
per-form echo is the only pr to (stoutput) that fires while inside
shen.load-help with rec.in_chunk false (the form's own (output ...) side
effects fire with in_chunk true and already replay via the chunk). Record
those bytes as a new "e" record in stream order, right after each form's "c"
chunk, and re-pr them on replay. Interleaving with side-effect output is
preserved for free, and going through the live `pr` keeps *hush* gating at
replay time (a -q hit stays silent, like a -q cold load).

The cosmetic "run time"/"typechecked in N inferences" banners are emitted by
`load` OUTSIDE shen.load-help, so rec.echoing excludes them — they stay
dropped by design (per-run timing noise breaks cross-port comparison).

FASL_FORMAT bumped 3 -> 4 (old caches miss and recompile cleanly).

Verified: warm == cold == shen-rust == shen-go for the probe (raw and tc
paths); -q hit stays silent; kernel tests 134/134; port specs 489/489
(cli_spec grows a #40 regression that drives a private-dir miss -> hit).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@pyrex41
pyrex41 merged commit 312ca9f into main Jul 21, 2026
2 checks passed
@pyrex41
pyrex41 deleted the fix/fasl-load-echo branch July 21, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

load: warm FASL-cache hit drops canonical per-form value echo (cross-port divergence + nondeterminism)

1 participant