Skip to content

feat: persistent REPL kernel behind FUSION_CODE_REPL_PERSIST=1 - #470

Merged
dahai80 merged 1 commit into
mainfrom
feat/repl-persistent-kernel
Dec 2, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/repl-persistent-kernel

Conversation

@dahai80

@dahai80 dahai80 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

What

Implements the round-2 Code Mode direction from code-mode-design.md §7 (#468): REPL user variables survive across calls in a per-process vm context. Flag-gated (FUSION_CODE_REPL_PERSIST=1), default off — the stateless AsyncFunction path is unchanged until the bench gate shows a measured delta on the 27B.

Design

  • kernel.ts: per-process context; sloppy mode so implicit globals persist (var/let/const stay IIFE-call-scoped — documented in prompt and tests); __last holds the previous returned value; bindings refreshed per run; 1 MB retained-state budget, oldest-first eviction.
  • Lifecycle: clearSessionCaches drops the kernel on /clear, --resume, and compaction (dynamic import, matches file style).
  • No trust-level change; observability surface unchanged (inner calls keep repl marking via existing logCall).

Bun vm findings (captured in tests)

  • vm.Script parses lazily: bad implicit-return transforms surface at runInContext, and the error is cross-realm (instanceof SyntaxError fails — match on .name).
  • delete contextProxy[name] does not reach the vm's real global object — eviction runs delete globalThis[...] inside the vm.
  • bun test interleaves files in one worker: REPLTool tests pin FUSION_CODE_REPL_PERSIST=0 so the kernel test's env window cannot redirect them into the shared context.

Gates

1925 tests 0 fail / typecheck clean / lint no new findings / build green.

Refs #468, #449

🤖 Generated with Claude Code

Round-2 Code Mode direction (code-mode-design §7, Scroll 2608.21690):
REPL code can keep user variables across calls in a per-process vm
context. Off by default — the stateless AsyncFunction path stays the
default until the bench gate shows a measured delta on the 27B.

- kernel.ts: per-process vm context, sloppy mode so implicit globals
  persist (var/let/const are IIFE-call-scoped), __last holds the
  previous returned value, bindings refreshed per run, 1MB retained-
  state budget dropping oldest-first via in-vm delete (Bun quirk:
  deleting through the context proxy does not reach the vm global)
- REPLTool.ts: flag-gated kernel path; prompt documents persistence
  semantics when on
- clear/caches.ts: resetReplKernel on /clear, --resume, compaction

Bun vm notes captured in tests: lazy Script parsing (SyntaxError
surfaces at runInContext, cross-realm so instanceof fails — match on
name); proxy delete bypass. REPLTool tests pin
FUSION_CODE_REPL_PERSIST=0 — bun interleaves test files in one worker,
the kernel test's flag window otherwise redirects them into the shared
context.

Gates: 1925 tests / typecheck / lint (no new findings) / build.

Co-Authored-By: Claude Code <[email protected]>
@dahai80
dahai80 merged commit e69d5b1 into main Dec 2, 2026
1 check passed
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.

1 participant