- parser `empty` no-target → (ref "me") (was bogus (sym "me"))
- parser `halt` modes distinguish: "all"/"bubbling"/"default" halt execution
(raise hs-return), "the-event"/"the event's" only stop propagation/default.
"'s" now matched as op token, not keyword.
- parser `get` cmd: dispatch + cmd-kw list + parse-get-cmd (parses expr with
optional `as TYPE`). Required for `get result as JSON` in fetch chains.
- compiler empty-target for (local X): emit (set! X (hs-empty-like X)) so
arrays/sets/maps clear the variable, not call DOM empty on the value.
- runtime hs-empty-like: container-of-same-type empty value.
- runtime hs-empty-target!: drop dead FORM branch that was short-circuiting
to innerHTML=""; the querySelectorAll-over-inputs branch now runs.
- runtime hs-halt!: take ev param (was free `event` lookup); raise hs-return
to stop execution unless mode is "the-event".
- runtime hs-reset!: type-aware — FORM → reset, INPUT/TEXTAREA → value/checked
from defaults, SELECT → defaultSelected option.
- runtime hs-open!/hs-close!: toggle `open` attribute on details elements
(not just the prop) so dom-has-attr? assertions work.
- runtime hs-coerce JSON: json-stringify dict/list (was str).
- test-runner mock: host-get on List + "length"/"size" (was only Dict);
dom-set-attr tracks defaultChecked / defaultSelected / defaultValue;
mock_query_all supports comma-separated selector groups.
- generator: emit boolean attrs (checked/selected/etc) even with null value;
drop overcautious "skip HS with bare quotes or embedded HTML" guard so
morph tests (source contains embedded <div>) emit properly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Load sx/sx/geography/cek/ recursively so content/demo/freeze index.sx
pages bind as ~geography/cek/{content,demo,freeze}. Update docs.sx
cek-page dispatch + test-examples cek:content-pages suite to reference
those real names (were stale ~geography/cek/cek-content etc.).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Update test-examples.sx to reference the real path-derived names
(~geography/<domain>/<stem>) instead of short aliases, drop the
alias chains in run_tests.ml, and add marshes/_islands loading so
the migrated one-per-file islands resolve. Fix the try-rerender-page
stub in boot-helpers.sx to accept the 3 args its callers pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Why: the one-per-file migration leaves `defcomp`/`defisland` unnamed in each
file; the test runner now walks `_islands/` recursively and injects a name
derived from the relative path (e.g. `geography/cek/_islands/demo-counter.sx`
→ `~geography/cek/demo-counter`), matching the runtime's path-based naming.
JIT-vs-CEK test parity: both now pass 3938/534 (identical failures).
Three fixes in sx_vm.ml + run_tests.ml:
1. OP_CALL_PRIM: fallback to Sx_primitives.get_primitive when vm.globals
misses. Primitives registered after JIT setup (host-global, host-get,
etc. bound inside run_spec_tests) become resolvable at call time.
2. jit_compile_lambda: early-exit for anonymous lambdas, nested lambdas
(closure has parent — recreated per outer call), and a known-broken
name list: parser combinators, hyperscript parse/compile orchestrators,
test helpers, compile-timeout functions, and hs loop runtime (which
uses guard/raise for break/continue). Lives inside jit_compile_lambda
so both the CEK _jit_try_call_fn hook and VM OP_CALL Lambda path
honor the skip list.
3. run_tests.ml _jit_try_call_fn: catch TIMEOUT during jit_compile_lambda.
Sentinel is set before compile, so subsequent calls skip JIT; this
ensures the first call of a suite also falls back to CEK cleanly when
compile exceeds the 5s test budget.
Also includes run_tests.ml 'reset' form helpers refactor (form-element
reset command) that was pending in the working tree.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- call: use make-symbol for fn name, rest-rest for args (was string + nth)
- on: extract (ref ...) nodes from body as event.detail let-bindings
- host-set!: add ListRef+Number case for array index mutation
- append!: support index 0 for prepend
- hs-put!: branch on list? for array start/end operations
- hs-reset!: form reset restoring defaultValue/checked/textContent
- 522/793 pass (was 493/754)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser:
- halt default/bubbling: match ident type (not just keyword)
- halt the event's: consume possessive marker
Runtime:
- hs-halt! dispatches: default→preventDefault, bubbling→stopPropagation,
event→both
Mock DOM:
- Add event method dispatch: preventDefault, stopPropagation,
stopImmediatePropagation set correct flags on event dict
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cek_run's resolver → cek_resume doesn't propagate values correctly
(likely a kont frame ordering issue in the transpiled evaluator).
Workaround: use _cek_io_suspend_hook which receives the suspended
state and manually steps to completion, handling further suspensions.
- resolve_io: shared function for IO resolution (sleep, fetch, etc.)
- Suspend hook: manual step loop after cek_resume, handles nested IO
- run_with_io: uses req_list extraction (handles ListRef)
- Fixes fetch tests: 10 now pass (response format correct)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The run_with_io suspension handler wasn't matching IO requests because
SX lists can be ListRef (mutable) not just List (immutable). Fixed by
extracting the underlying list first, then pattern matching on elements.
Also:
- Added io-sleep/io-wait/io-settle/io-fetch handlers to run_with_io
- Rebound try-call inside run_spec_tests to use eval_with_io
- io-fetch returns "yay" for text, {foo:1} for json, response dict
This enables perform-based IO (wait, fetch) to work in test execution,
fixing ~30 tests that previously returned empty strings.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
IO Suspension:
- Set _cek_io_resolver in test runner to handle perform/wait/fetch
- io-sleep/io-wait: instant resume (no real delay in tests)
- io-fetch: returns mock {ok:true, status:200, json:{foo:1}} response
- io-wait-for/io-settle: instant resume
- Fixes ~30 tests that were failing with VmSuspended or timeouts
Append command:
- hs-append (pure): string concat or list append
- hs-append! (effectful): DOM insertAdjacentHTML
- Compiler emits set! wrapper for variable targets
Mock DOM:
- dom_stringify handles List → comma-separated string
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Compiler:
- append to symbol → (set! target (hs-append target value))
- append to DOM → (hs-append! value target)
Runtime:
- hs-append: pure function for string concat and list append
- hs-append!: DOM insertAdjacentHTML for element targets
Mock DOM:
- dom_stringify handles List by joining elements with commas
(matching JS Array.toString() behavior)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser:
- Reorder toggle style parsing: target before between clause
- Handle "indexed" keyword, "indexed by" syntax
- Use parse-atom (not parse-expr) for between values to avoid
consuming "and" as boolean operator
- Support 3-4 value cycles via toggle-style-cycle
Compiler:
- Add toggle-style-cycle dispatch → hs-toggle-style-cycle!
Runtime:
- Add hs-toggle-style-between! (2-value toggle)
- Add hs-toggle-style-cycle! (N-value round-robin)
Mock DOM:
- Parse CSS strings from setAttribute "style" into style sub-dict
so dom-get-style/dom-set-style work correctly
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser:
- Relax (number? v) to v in parse-one-transition so (expr)unit works
- Add (match-kw "then") before parse-cmd-list in parse-for-cmd
- Handle "indexed by" syntax alongside "index" in for loops
- Add "indexed" to hs-keywords to prevent unit-suffix consumption
Compiler:
- Use map-indexed instead of for-each for indexed for-loops
Test generator:
- Preserve \" escapes in process_hs_val via placeholder/restore
Mock DOM:
- Coerce insertAdjacentHTML values via dom_stringify (match browser)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- inject_path_name: strip _islands/ convention dirs from path-derived names
- page-functions.sx: fix geography (→ ~geography) and isomorphism (→ ~etc/plan/isomorphic)
- request-handler.sx: rewrite sx-eval-page to call page functions explicitly
via env-get+apply, avoiding provide special form intercepting (provide) calls
- sx_server.ml: set expand-components? on AJAX aser paths so server-side
components expand for the browser (islands stay unexpanded for hydration)
- Rename 19 component references in geography/spreads, geography/provide,
geography/scopes to use path-qualified names matching inject_path_name output
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The handler dispatch (api.* paths) now checks for HX-Request header.
If present, the SX aser output is rendered to HTML via sx_render_to_html
before sending. SX-Request (from SX client navigation) still gets SX
wire format. This makes hx-* attributes work like real htmx — the
server returns HTML fragments that htmx can swap into the DOM.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
htmx sends HX-Request header on AJAX calls. The server now detects this
and renders the SX response to HTML via sx_render_to_html before sending.
SX-Request (from SX client navigation) still gets SX wire format.
Also skip response cache for htmx requests (they need fresh HTML renders).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous commit accidentally lost ~1100 lines from sx_server.ml
due to a git stash conflict resolution that silently deleted the
hash-index, manifest generation, and /sx/h/ route handler code.
Restored from 97818c6d. Only change: added host-* platform primitive
stubs (host-get, host-set!, host-call, etc.) needed because the
callable? fix in boot-helpers.sx now properly loads code paths that
reference these browser-only functions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
callable? in boot-helpers.sx checked for "native-fn" but type-of returns
"function" for NativeFn — broke make-spread and all native fn dispatch
in aser. Restore 20 behavioral tests replaced with NOT IMPLEMENTED stubs
by the test regeneration commit. Add host-* platform primitive stubs to
sx_server.ml so boot-helpers.sx loads without errors server-side.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- htmx-boot-subtree! wired into process-elements for auto-activation
- Fixed cond compilation bug in hx-verb-info (Clojure-style flat cond)
- Platform io-fetch upgraded: method/body/headers support, full response dict
- Replaced perform IO ops with browser primitives (set-timeout, browser-confirm, etc)
- SX→HTML rendering in hx-do-swap with OOB section filtering
- hx-collect-params: collects input name/value for all methods
- Handler naming: ex-{slug} convention, removed perform IO dependencies
- Test runner page at (test.(applications.(htmx))) with iframe-based runner
- Header "test" link on every page linking to test URL
- Page file restructure: 285 files moved to URL-matching paths (a/b/c/index.sx)
- page-functions.sx: ~100 component name references updated
- _test added to skip_dirs, test- file prefix convention for test files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When innerHTML is set on a mock element, textContent now updates to
match (with HTML tags stripped). Many HS tests do `put "foo" into me`
(which sets innerHTML) then check textContent. Previously textContent
stayed empty because only innerHTML was updated.
Also fixes innerHTML="" to fully detach children from parent.
393 → 408/831 HS tests (+15).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Setting innerHTML="" on a mock element now detaches and removes all
children, matching browser behavior. Previously hs-cleanup! (which
sets body.innerHTML="") left stale children attached, causing
querySelector to find elements from prior tests.
Also clears children when textContent is set (browser behavior).
375 → 393/831 HS tests (+18).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
In a real browser, innerHTML/textContent/value are always strings.
The mock was storing raw SX values (Number, Bool, Nil), causing type
mismatches like "Expected 1, got 1" where the value was correct but
Number 1.0 != String "1".
Now coerces to string on host-set! for innerHTML, textContent, value,
outerHTML, innerText. Fixes 10 increment tests that were doing
`put value into me` with numeric results.
367 → 375/831 HS tests (+8 net, +10 new passes, -2 regressions).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The infinite loops in the HS parser are in transpiled native OCaml code,
not in the VM or CEK step loop. Neither step counters (in cek_step_loop,
cek_step, trampoline) nor VM instruction checks caught them because
the loops are in direct OCaml recursion.
Fix: SIGALRM handler raises Eval_error to break out of native loops.
Also sets step_limit flag to catch VM loops. Combined approach handles
both native OCaml recursion (alarm+raise) and VM bytecode (step check).
The alarm+raise can become unreliable after ~13 timeouts in a single
process, but handles the common case well. Reverts the fork-based
approach which lost inter-test state.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two critical fixes for the mock DOM test runner:
1. host-get returns truthy for DOM method names on mock elements.
dom.sx guards like `(and el (host-get el "setAttribute"))` were
silently skipping setAttribute/getAttribute calls because the mock
dict had no "setAttribute" key. Now returns Bool true for known
DOM method names, fixing hs-activate! → dom-set-attr → dom-get-attr
chain. Also adds firstElementChild, nextElementSibling, etc. as
computed properties.
2. Fork-based per-test timeout (5 seconds). The HS parser has infinite
loops on certain syntax ([@attr], complex put targets). Signal-based
alarm doesn't work reliably in OCaml 5. Fork + waitpid + select
gives hard OS-level timeout protection.
Also adds step_limit/step_count to sx_ref.ml trampoline (currently
unused but available for future CEK-level timeout).
Result: 525/963 total, up from 498. Many more add/remove/toggle/set
tests now pass because hs-activate! actually wires up event handlers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the monolithic 500KB <script data-components> block with a 25KB
JSON manifest mapping names to content hashes. Every definition —
components, islands, macros, client libraries, bytecode modules, and
WASM binaries — is now content-addressed and loaded on demand.
Server (sx_server.ml):
- build_hash_index: Merkle DAG over all definitions — topological sort,
hash leaves first, component refs become @h:{hash} in instantiated form
- /sx/h/{hash} endpoint: serves definitions with Cache-Control: immutable
- Per-page manifest in <script data-sx-manifest> with defs + modules + boot
- Client library .sx files hashed as whole units (tw.sx, tw-layout.sx, etc.)
- .sxbc modules and WASM kernel hashed individually
Browser (sx-platform.js):
- Content-addressed boot: inline script loads kernel + platform by hash
- loadDefinitionByHash: recursive dep resolution with @h: rewriting
- resolveHash: 3-tier cache (memory → localStorage → fetch /sx/h/{hash})
- __resolve-symbol extended for manifest-based component + library loading
- Cache API wrapper intercepts .wasm fetches for offline caching
- Eager pre-loading of plain symbol deps for CEK evaluator compatibility
Shell template (shell.sx):
- Monolithic <script data-components> removed
- data-sx-manifest script with full hash manifest
- Inline bootstrap replaces <script src="...?v="> with CID-based loading
Second visit loads zero bytes from network. Changed content gets a new
hash — only that item refetched (Merkle propagation).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add mock DOM layer to run_tests.ml so hyperscript behavioral tests
(spec/tests/test-hyperscript-behavioral.sx) can run in the OCaml test
runner without a browser. Previously these tests required Playwright
which crashed after 10 minutes from WASM page reboots.
Mock DOM implementation:
- host-global, host-get, host-set!, host-call, host-new, host-callback,
host-typeof, host-await — OCaml primitives operating on SX Dict elements
- Mock elements with classList, style, attributes, event dispatch + bubbling
- querySelector/querySelectorAll with #id, .class, tag, [attr] selectors
- Load web/lib/dom.sx and web/lib/browser.sx for dom-* wrappers
- eval-hs function for expression-only tests (comparisonOperator, etc.)
Result: 367/831 HS tests pass in ~30 seconds (was: Playwright crash).
14 suites at 100%: live, component, liveTemplate, scroll, call, go,
focus, log, reactive-properties, resize, measure, attributeRef,
objectLiteral, queryRef.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser/compiler/runtime for focus command. Tokenizer: focus, blur,
precedes, follows, ignoring, case keywords. Test spec: per-test
failure output for diagnosis.
374/831 (45%)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Streaming chunked transfer with shell-first suspense and resolve scripts.
Hyperscript parser/compiler/runtime expanded for conformance. WASM static
assets added to OCaml host. Playwright streaming and page-level test suites.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The shell HTML included closing </body></html> tags. Resolve script
chunks arrived AFTER the document end — browser ignored them
(ERR_INCOMPLETE_CHUNKED_ENCODING). Now strips </body></html> from
shell, sends resolve scripts inside the body, closes document last.
Added live server Playwright tests that hit the actual streaming
endpoint and verify suspense slots resolve with content.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The streaming render matched `List items` but SX's `(list ...)` produces
`ListRef` (mutable list) in the OCaml runtime. Data items were rejected
with "returned list, expected dict or list" — 0 resolve chunks sent.
Fixed both streaming render and AJAX paths to handle ListRef.
Added sandbox test for streaming-demo-data return type validation.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Server (sx_server.ml):
- eval_with_io: CEK evaluator with IO suspension handling (io-sleep, import)
- io-sleep platform primitive: raises CekPerformRequest, resolved by eval_with_io
- Streaming render uses eval_with_io for data + content evaluation
- Data items with "delay" field sleep before resolving (async streaming)
- Removed hardcoded streaming-demo-data — application logic belongs in .sx
Application (streaming-demo.sx):
- streaming-demo-data defined in SX: 3 items with 1s/3s/5s delays
- Each item has delay, stream-id, and display data fields
- Shell renders instantly, slots fill progressively as IO completes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bytecode-serialize/deserialize: sxbc v2 format wrapping compiled code
dicts. cek-serialize/deserialize: cek-state v1 format wrapping suspended
CEK state (phase, request, env, kont). Both use SX s-expression
round-trip via inspect/parse. lib/serialize.sx has pure SX versions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three changes to eliminate the stepper flash:
1. home-stepper.sx: server path reads cookie via (get-cookie) for
step-idx initial value. Client path reads document.cookie via
def-store. Both default to 0 when no cookie exists.
2. sx_server.ml: bypass response cache when sx-home-stepper cookie
is present. Render on main thread (not worker) so get-cookie
sees the parsed request cookies.
3. site-full.spec.js: flash detection test sets cookie=7 via
Playwright context, checks SSR HTML matches hydrated state.
Test: "No flash: SSR=7 hydrated=7 (cookie=7)" — passes.
Tested on fresh stack=site server subprocess.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reset to last known-good state (908f4f80) where links, stepper, and
islands all work, then recovered all hyperscript implementation,
conformance tests, behavioral tests, Playwright specs, site sandbox,
IO-aware server loading, and upstream test suite from f271c88a.
Excludes runtime changes (VM resolve hook, VmSuspended browser handler,
sx_ref.ml guard recovery) that need careful re-integration.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bytecode modules now load correctly in sandbox mode. HS .sxbc modules
use K.load('(load-sxbc ...)') which syncs defines to eval env. Web stack
.sxbc modules use K.loadModule with import suspension drive loop.
K.eval used directly for expression eval (not thunk wrapper) so bytecode-
defined symbols are visible. Falls back to callFn thunk on IO suspension.
Sandbox now reproduces the bytecode repeat bug: source gives 6/6
suspensions, bytecode gives 4/6. Bug is in bytecode compilation of
when/do across perform boundaries, not the runtime wrapper.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
sx_eval now accepts files (smart-loaded by mtime — unchanged files skip),
trace_io (harness-wrapped IO capture), mock (evaluated platform overrides),
and setup params. Definitions survive between calls. sx_harness_eval also
uses smart loading. sx_write_file can create new files.
New lib/hyperscript/debug.sx: mock DOM platform for instant hyperscript
testing — compile and execute HS expressions against simulated elements,
see every DOM mutation and wait in the IO trace.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- jit_compile_lambda: call compile directly via VM when it has bytecode
(100-400x faster JIT compilation, server pre-warm 1.6s vs hung)
- code_from_value: scan bytecode for highest LOCAL_GET/SET slot to
compute vc_locals correctly (fixes hyperscript LOCAL_GET overflow)
- code_from_value: accept both compiler keys (bytecode) and SX VM
keys (vc-bytecode) for interop
- jit_compile_lambda: skip &key/:as params (compiler can't emit them)
- Test runner: seed VM globals with primitives + env bindings,
native vm-execute-module with suspension fallback to SX version,
_jit_refresh_globals syncs globals after module loading,
VmSuspended + "VM undefined" caught and sentineled
3127/3127 without JIT, 3116/3127 with JIT (11 hyperscript on-event
parsing — specific closure/scope issue, not infrastructure).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Break up the 1735-line handle_tool match into 45 individual handler functions
with hashtable-based dispatch. Add mtime-based file parse caching (AST + CST),
consolidated run_command helper replacing 9 bare open_process_in patterns,
require_file/require_dir input validation, and pagination (limit/offset) for
sx_find_across, sx_comp_list, sx_comp_usage. Also includes pending VM changes:
rest-arity support, hyperscript parser, compiler/transpiler updates.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Root cause: pre-compiled compiler helper functions (compile-expr,
compile-cond, etc.) produce bytecode that loops when processing
deeply nested ASTs like tw-resolve-style. The test suite passes
because _jit_compiling prevents compiled function execution during
compilation — all functions run via CEK. The server pre-compiled
helpers, so they ran as bytecode during compilation, triggering loops.
Fix:
- _jit_compiling guard on the "already compiled" hook branch prevents
compiled functions from running during JIT compilation. Compilation
always uses CEK (correct for all AST sizes). Normal execution uses
bytecode (fast).
- "compile" itself marked as jit_failed_sentinel — never JIT compiled.
Runs via CEK, while its helpers use bytecode for normal (non-compile)
execution.
- Server hook uses call_closure (own VM per call) for IO suspension
safety. MCP uses call_closure_reuse (fast, no IO needed).
The underlying bytecode bug in the compiled helpers remains — fixing
it requires diagnosing which specific helper loops and why. This is
tracked as a separate issue. Server now starts in ~30s (pre-warm)
and serves pages correctly.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three interacting JIT bugs caused infinite loops and server hangs:
1. _jit_compiling cascade: the re-entrancy flag was local to each
binary's hook. When vm_call triggered JIT compilation internally,
compiler functions got JIT-compiled during compilation, creating
infinite cascades. Fix: shared _jit_compiling flag in sx_vm.ml,
set in jit_compile_lambda itself.
2. call_closure always created new VMs: every HO primitive callback
(for-each, map, filter) allocated a fresh VM. With 43K+ calls
during compilation, this was the direct cause of hangs. Fix:
call_closure_reuse reuses the active VM by isolating frames and
running re-entrantly. VmSuspended is handled by merging frames
for proper IO resumption.
3. vm_call for compiled Lambdas: OP_CALL dispatching to a Lambda
with cached bytecode created a new VM instead of pushing a frame
on the current one. Fix: push_closure_frame directly.
Additional MCP server fixes:
- Hot-reload: auto-execv when binary on disk is newer (no restart needed)
- Robust JSON: to_int_safe/to_int_or handle null, string, int params
- sx_summarise depth now optional (default 2)
- Per-request error handling (malformed JSON doesn't crash server)
- sx_test uses pre-built binary (skips dune rebuild overhead)
- Timed module loading for startup diagnostics
sx_server.ml fixes:
- Uses shared _jit_compiling flag
- Marks lambdas as jit_failed_sentinel on compile failure (no retry spam)
- call_closure_reuse with VmSuspended frame merging for IO support
Compiled compiler bytecode bug: deeply nested cond/case/let forms
(e.g. tw-resolve-style) cause the compiled compiler to loop.
Workaround: _jit_compiling guard prevents compiled function execution
during compilation. Compilation uses CEK (slower but correct).
Test suite: 3127/3127 passed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>