compile-match-clauses was a separate define that the JIT VM couldn't
find at runtime ("VM undefined: compile-match-clauses"). Inline it
as a letrec-bound local function inside compile-match so it's
captured in the closure and visible to JIT-compiled code.
1166 passed, 0 failed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The JIT compiler now handles the match special form, emitting the
same DUP/compare/JUMP_IF_FALSE bytecode pattern as case. Supports
literal patterns (string, number, boolean, nil), _ wildcard, symbol
binding, and quoted symbol patterns.
This fixes the infinite JIT retry loop where compile-list (which
used match for dispatch) couldn't be JIT-compiled, causing
parse-loop to endlessly fall back to CEK evaluation.
1166 passed, 0 failed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The match special form in compile-list caused JIT-compiled functions
to fail with "Expected number, got symbol" errors, creating an
infinite retry loop in parse-loop. The JIT compiler can't compile
match expressions, so compile-list fell back to CEK on every call.
Revert to the original cond-based dispatch. The evaluator.sx match
conversions are fine (not used by JIT), only the compiler was affected.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The home stepper's step-idx signal was not persisting across SX
navigation because set-cookie/freeze-to-sx wasn't working in the
WASM kernel. Replace with def-store which uses a global registry
that survives island re-hydration.
Also fix sx_http.exe build: add sx_http back to dune, inline scope
primitives (Sx_scope module was removed), add declarative form
stubs and render stubs, fix /sx/ home route mapping.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
OCaml HTML renderer (sx_render.ml) silently returned "" when env_get
failed for primitive function calls (str, +, len, etc.) inside HTML
elements. The Eval_error catch now falls through to eval_expr which
resolves primitives correctly. Fixes 21 rendering tests.
Rename condition system special form from "signal" to "signal-condition"
in evaluator.sx, matching the OCaml bootstrapped evaluator (sx_ref.ml).
This avoids clashing with the reactive signal function. Fixes 9
condition system tests.
1166 passed, 0 failed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- request-handler.sx: replace all dots (not just `.(`) and auto-quote
undefined symbols as strings so 3-level URLs like
/sx/(geography.(reactive.(examples.counter))) resolve correctly
- sx-platform.js: register popstate handler (was missing from manual
boot sequence) and fetch full HTML for back/forward navigation
- sx_ref.ml: add CEK step limit (10M steps) checked every 4096 steps
so runaway renders return 500 instead of blocking the worker forever
- Rename test-runner.sx → runner-placeholder.sx to avoid `test-` skip
- Playwright config: pin testDir, single worker, ignore worktrees
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Island markers rendered during SX navigation responses had no
data-sx-state attribute, so hydration found empty kwargs and path
was nil in the copyright display. Now adapter-dom.sx serializes
keyword args into data-sx-state on island markers, matching what
adapter-html.sx does for SSR.
Also fix post-swap to use parent element for outerHTML swaps in
SX responses (was using detached old target). Add SX source file
hashes to wasm_hash for proper browser cache busting — changing
any .sx file now busts the cache. Remove stale .sxbc bytecode
cache files.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The handler routes correctly and renders content, but shell statics
(__shell-sx-css etc.) resolve to nil/empty in the handler scope.
use-wasm flag also not working — need to remove sx-browser.js fallback.
Needs: debug shell static resolution in SX handler scope.
Remove sx-browser.js from shell template entirely.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
web/request-handler.sx: configurable SX handler called by OCaml server.
Detects AJAX (SX-Request header) and returns content fragment (no shell)
vs full page with shell. All routing, layout, response format in SX.
OCaml server: http_render_page calls sx-handle-request via CEK.
No application logic in OCaml — just HTTP accept + SX function call.
signal-condition rename: reactive signal works, condition system uses
signal-condition. Island SSR renders correctly (4/5 tests pass).
WASM JIT: no permanent disable on failure. Live globals.
WIP: page-sx empty in SX handler — client routing needs it.
Navigation tests timeout (links not found after boot).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Convert large cond chains doing string equality dispatch to use the
match special form: step-eval-list (42 arms), step-continue (31 arms),
compile-list (30 arms), ho-setup-dispatch (7 arms), value-matches-type?
(10 arms). Also fix test-canonical.sx to use defsuite/deftest format
and load canonical.sx in both test runners.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New web/request-handler.sx: configurable SX function (sx-handle-request)
that receives path + headers + env and returns rendered HTML.
The handler decides full page vs AJAX fragment.
OCaml server: http_render_page now just calls the SX handler.
All routing, layout selection, AJAX detection moved to SX.
Header parsing added. is_sx_request removed from OCaml.
Configurable via SX_REQUEST_HANDLER env var (default: sx-handle-request).
WIP: handler has parse errors on some URL formats. Needs debugging.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The stepper SSR output IS correct (273 bytes, identical to Quart,
no raw ~cssx/tw). The test was checking textContent which included
text outside the island boundary (the code-view documentation text).
Fixed to check innerHTML for HTML elements and class attributes.
5/5 island SSR tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WASM kernel (sx_browser.ml): remove jit_failed_sentinel marking on
JIT runtime errors. Functions stay JIT-compiled and retry on next call.
Errors are data-dependent, not JIT bugs.
signal-condition: rename in CEK dispatcher so reactive 'signal' function
works. The conditions system 'signal' special form is now 'signal-condition'.
adapter-html.sx: remove cek-try wrapping island render. Errors propagate.
Island SSR: 4/5 tests pass. Header renders perfectly. Stepper ~cssx/tw
not expanding because component calls in island body aren't evaluated
by render-to-html — they're serialized as text. Needs SX adapter fix.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Root cause: the new conditions system's 'signal' special form shadowed
the reactive 'signal' function. (signal 0) in island bodies raised
'Unhandled condition: 0' instead of creating a signal dict.
Fix: rename condition special form to 'signal-condition' in the CEK
dispatcher. The reactive 'signal' function now works normally.
adapter-html.sx: remove cek-try that swallowed island render errors.
Islands now render directly — errors propagate for debugging.
sx_render.ml: add sx_render_to_html that calls SX adapter via CEK.
Results: 4/5 island SSR tests pass:
- Header island: logo, tagline, styled elements ✓
- Navigation buttons ✓
- Geography content ✓
- Stepper: partially renders (code view OK, ~cssx/tw in heading)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Server always returns full page. Client sx-select handles extraction.
No application logic in OCaml server.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jit_compile_lambda now uses the live globals table directly instead
of Hashtbl.copy. Closure bindings that aren't already in globals are
injected into the live table. This ensures GLOBAL_GET always sees
the latest define values.
Previously: Hashtbl.copy created a stale snapshot. Functions defined
after the copy (like cssx-process-token from cssx.sx) resolved to nil
in JIT-compiled closures.
JIT error test now passes — 0 CSSX errors during navigation.
7/8 navigation tests pass. Remaining: back button content update.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Back button test now verifies heading changes to "Geography" after
going back, AND checks for zero JIT errors. Catches real bugs:
- 129 JIT "Not callable: nil" errors during navigation (CSSX closure)
- Back button content may not update (to be verified after JIT fix)
New test: "no JIT errors during navigation" — fails with 129 errors,
correctly identifying the CSSX closure capture bug.
6 pass, 2 fail (real bugs, not test issues).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
AJAX fragment: extract #main-panel with matching close tag (depth
tracking) instead of taking everything to end of file. Prevents
shell closing tags from breaking the DOM swap.
Back button test: verifies content actually changes — checks for
"Geography" and "Rendering Pipeline" after going back, not just
that body has >100 chars. Tests forward nav content change too.
7/7 navigation tests pass including back button content verification.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two new tests:
- browser back button works after navigation: URL returns to original,
content renders (not blank), no raw SX visible
- back button preserves layout: heading stays in top area, no side-by-side
All 7 navigation tests pass including forward nav, back button, layout,
content update, header survival, and raw SX checks.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace blocking domain pool with non-blocking architecture:
- Main accept loop handles ALL connections immediately
- Cached responses: served in microseconds from main loop (no queuing)
- Static files: served immediately from main loop
- Cache misses: queued to render worker pool (domain workers)
- Socket timeouts (5s recv, 10s send) prevent connection hangs
- TCP backlog increased to 1024
No more connection resets under load. 22/26 Playwright tests pass
(4 failures from stale worktree test copies, 0 from main tree).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
AJAX navigation: detect SX-Request/HX-Request headers and return just
the #main-panel fragment instead of the full page shell. Fixes layout
break where header and content appeared side-by-side after navigation.
New navigation test suite (tests/playwright/navigation.spec.js):
- layout stays vertical after clicking nav link
- content updates after navigation
- no raw SX component calls visible after navigation
- header island survives navigation
- full page width is used (no side-by-side split)
All 5 tests pass. 14 total Playwright tests pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move client library sources (cssx.sx) before defcomp/defisland
definitions in component-defs so defines are evaluated first.
Identified root cause of CSSX "Not callable: nil" errors:
JIT compiler captures free variable values at compile time instead of
looking them up at runtime from vm_globals. When ~cssx/tw's JIT code
calls cssx-process-token, it uses the compile-time snapshot (nil)
instead of the runtime value (lambda). The function IS in global_env
(type-of returns "lambda") but the JIT bytecode doesn't see it.
Fix needed: JIT compiler should emit GLOBAL_GET instructions for free
variables that reference vm_globals at runtime, not capture at compile.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Switch SSR + shell from native Sx_render to SX adapter (render-to-html
from adapter-html.sx) via CEK evaluator. Handles reactive primitives
(signals, deref, computed) for island bodies. Native renderer as fallback.
Header island SSRs correctly: (<sx>), tagline, copyright, path.
Stepper renders body but ~cssx/tw shows as raw SX (client-affinity
component not expanded server-side, client not expanding either).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Island SSR reverted to placeholder approach (full SSR crashed on
reactive code). Placeholders include SX call expression for client
hydration. CSS hides placeholder text until WASM renders.
Remaining: need SX adapter (adapter-html.sx) for island SSR instead
of native Sx_render — the SX adapter handles signals/deref/computed
via the CEK machine. Native renderer doesn't support reactive primitives.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Include cssx.sx source in component-defs for client CSSX runtime.
Island placeholders now contain SX call expression for client hydration.
escape_sx_string only escapes </script, not all </ sequences.
serialize_value: no (list) wrapper, matching Python serialize() exactly.
Homepage: header renders (<sx>, tagline, copyright), stepper shows
raw SX (cssx/tw not expanding client-side). Geography fully rendered
including island hydration.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
serialize_value: all lists emit (items...) not (list items...), matching
Python serialize() exactly. Empty lists emit (). This fixes let bindings,
fn params, and data structures for client-side parsing.
Component-defs now include named lambdas, macros, dicts, and other named
values from the env — client needs CSSX functions (cssx-process-token,
cssx-colour-props, cssx-spacing-props etc.) for island hydration.
Fixes: cssx-process-token, cssx-colour-props undefined errors.
Geography page: fully rendered with header island hydration working.
Homepage: nav renders, no error banners, stepper silent.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
serialize_value: lists with symbol head emit (fn args...) not (list fn args).
This lets the client SX parser recognise special forms like let, when, cond
inside component-defs. Data lists (starting with non-symbols) keep the
(list ...) wrapper.
Fixes "Undefined symbol: let" WASM error that broke all island hydration.
Header island now reaches the JIT evaluator (fails on for-each VM error,
not parsing). Geography, SXTP, CEK pages fully rendered.
Removed debug logging (ssr-debug, debug dump, debug endpoint).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Homepage fix: path_expr "home" was evaluated as a symbol lookup (returning
the Lambda) instead of a function call. Now wraps bare symbols in a list:
home → (home) → calls the page function → returns component call.
Slug routing: auto_quote converts unknown symbols to strings before eval.
(etc (plan sx-host)) → (etc (plan "sx-host")) — resolves nested slug URLs.
Resilient SSR: render_to_buf catches Eval_error per-element and continues
rendering. Partial SSR output preserved even when some elements fail.
WASM kernel rebuilt (define shorthand + island placeholder changes).
Remaining: WASM kernel "Undefined symbol: let" — pre-existing bug in
client-side component-defs parsing. (list let ...) triggers symbol lookup
instead of special form recognition. Affects island hydration on all pages.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
escape_sx_string now escapes </ as <\\/ inside SX string literals,
matching Python's serialize() behavior. This prevents the HTML parser
from matching </script> inside component-defs strings while keeping
the SX valid for the client parser.
Component-defs back to inline <script data-components> (reverts
external endpoint approach). init-sx triggers client render when
sx-root is empty.
Geography page: fully rendered with header, nav, content, styling.
Header island hydration warning (Undefined symbol: let) is a
pre-existing WASM kernel issue, not related to the HTTP server.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Islands now always emit <span data-sx-island="name"> placeholder
instead of attempting SSR. Island bodies contain client-only symbols
(signals, DOM refs) that cascade errors during native render.
Component-defs moved to /static/sx-components.sx endpoint instead of
inline <script> — avoids </script> escaping issues that broke the
client-side SX parser.
Remaining: client WASM kernel not loading components from external
endpoint (expects inline script tag). Need to configure client boot
to fetch from /static/sx-components.sx.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Escape </script sequences in component-defs (replace </ with <\/ before s/S)
- Build pages-sx registry from defpage definitions (51 routes for client router)
- SSR fallback: emit minimal layout HTML when full SSR fails
- Redirect / → /sx/
- Load sxc/ components for ~docs/page
- Block .wasm.assets/ build artifacts but allow .wasm runtime files
Geography page renders correctly with full styling and content.
Homepage still blank — client boot doesn't render from page-sx on
initial load (only on navigation). Needs homepage SSR to succeed,
which requires fixing the stepper island's <home symbol.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
OCaml HTTP server now serves /static/* files with MIME types, immutable
cache headers, and in-memory caching. Computes MD5 hashes for JS/WASM
files and injects them as ?v= cache-busting query params.
Inline CSS: reads tw.css + basics.css at startup, injects into
<style id="sx-css"> tag. Pages now render with full Tailwind styling.
Shell statics now include real file hashes:
sx-js-hash, body-js-hash, wasm-hash — 12-char MD5 hex
Docker compose: mounts shared/static as /app/static for the container.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Load sx/sxc/ directory for core layout components like ~docs/page,
~docs/section, ~docs/code. Auto-detect Docker (/app/sxc) vs dev
(/project/sx/sxc) paths with SX_SXC_DIR env override.
Fixes pages that use ~docs/page — all content pages now render
correctly with full component expansion.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
docker-compose.dev-sx-native.yml overrides entrypoint to run OCaml
HTTP server inside Docker container (Caddy on externalnet can reach it).
Auto-detect sx component directory: checks /app/sx (Docker) first,
falls back to /project/sx/sx (dev). SX_COMPONENTS_DIR env override.
Live on sx.rose-ash.com via Caddy → Docker → OCaml HTTP server.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Single command to start the native OCaml HTTP server for sx-docs.
No Docker, no Python, no Quart — just the OCaml binary + Caddy.
./dev-sx-native.sh # port 8013
./dev-sx-native.sh 8014 # custom port
./dev-sx-native.sh --build # rebuild first
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Render 5 key pages during startup to trigger JIT compilation of page
functions, aser, render-to-html, and all component paths. Steady-state
performance after warmup:
Homepage: 212-280ms (aser=136-173ms, ssr=44-90ms)
Geography: 282-354ms (aser=215-273ms, ssr=44-61ms)
Reactive: 356-522ms (aser=306-390ms, ssr=38-109ms)
SSR phase is fast (streaming renderer). Aser is the bottleneck —
response caching eliminates it for static pages.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New render_to_buf / render_to_html_streaming in sx_render.ml — writes
HTML directly to a Buffer.t instead of building intermediate strings.
Eliminates hundreds of string concatenations per page render.
Full parallel renderer: render_to_buf, render_element_buf,
render_component_buf, render_cond_buf, render_let_buf, render_map_buf,
render_for_each_buf — all buffer-native.
HTTP server SSR + shell now use streaming renderer.
Performance (warm, 2 worker domains, 2MB RSS):
Homepage: 138-195ms TTFB (Quart: 202ms) — faster
Geography: 218-286ms TTFB (Quart: 144ms)
Throughput: 6.85 req/s at c=5 (Quart: 6.8 req/s) — matched
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
JIT runtime errors now log once per function name via _jit_warned
hashtable, then stay quiet for that function. No more silent swallowing
(which hid real errors) or per-call flooding (which spammed thousands
of lines and blocked the server).
VM-level fallbacks (inside JIT-compiled code calling other JIT code)
are silent — dedup happens at the hook level.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Domain pool with N workers (Domain.recommended_domain_count), mutex+
condition queue for request dispatch. Each domain has its own minor
heap — GC pauses don't block other requests.
expand-components? bound once at startup (always true in HTTP mode)
instead of per-request mutation. Shell rendering uses native
Sx_render.render_to_html for domain safety.
Performance (warm, 2 worker domains, 2MB RSS):
Homepage: 107-194ms TTFB (Quart: 202ms) — faster
Geography: 199-306ms TTFB (Quart: 144ms) — close
Reactive: 351-382ms TTFB (Quart: 187ms) — 2x slower
Concurrent: 5.88 req/s at c=5 (Quart: 6.8 req/s)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Switch SSR from SX adapter to native Sx_render.render_to_html.
Islands that fail SSR emit <span data-sx-island="name"> placeholders
instead of recursing into client-only bodies. Eliminates the <home
symbol error cascade that made the homepage render 23s.
Performance (warm, single process):
Homepage: 131-191ms TTFB (was 202ms on Quart) — faster
Geography: 203-229ms TTFB (was 144ms on Quart) — close
Reactive: 155-290ms TTFB (was 187ms on Quart) — similar
Memory: 2MB RSS (was 570MB on Quart) — 285x reduction
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
JIT runtime errors now silently fall back to CEK without disabling the
compiled bytecode or logging. This prevents render-to-html from being
permanently disabled when one page has an unresolved symbol (e.g. the
homepage stepper's <home).
Load spec/signals.sx and web/engine.sx for reactive primitives.
Skip test files and non-rendering directories (tests/, plans/, essays/).
Performance with JIT active (warm, single process, 2MB RSS):
- Aser (component expansion): 21-87ms — faster than Quart baseline
- SSR + shell: variable due to homepage <home fallback issue
- Geography total: ~500ms when JIT stays active
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Enable lazy JIT in HTTP mode — pre-compile 24 compiler functions at startup
- Load spec/signals.sx + web/engine.sx for reactive primitives
- Recursive directory loading for subdirectory components (geography/, etc.)
- Re-bind native variadic assoc after stdlib.sx overwrites it
- Skip test files, plans/, essays/ directories during HTTP load
- Homepage aser: 21-38ms warm, Geography aser: 39-87ms warm
Remaining: render-to-html JIT gets disabled by <home symbol error on
first request (falls back to CEK). ~docs/page component missing for
some pages. Fix those for full parity with Quart.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reverse hook syncs VM GLOBAL_SET mutations back to global_env so CEK reads
see JIT-written values. Isomorphic nav: store primitives, event-bridge,
client? predicate. Browser JS and bytecode rebuilt.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>