From 1c9622d9404fde5ff486f45efafbe38e027a27ee Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 29 Mar 2026 01:12:53 +0000 Subject: [PATCH] JIT live globals fix + non-blocking server + honest nav tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JIT: use live globals table directly (no Hashtbl.copy snapshot). Fixes CSSX "Not callable: nil" — 0 JIT errors on navigation. Non-blocking server: accept loop serves cached/static instantly, render workers handle cache misses. TCP backlog 1024, socket timeouts. Navigation tests (8 tests): - 6 pass: layout, content update, raw SX check, header survival, back button layout, full width - 1 fail: back button content doesn't update (AJAX fragment issue) - 1 fail: was JIT errors, now passes after fix AJAX fragment extraction: code exists but not working for popstate fetches. Needs investigation — SX-Request header detection or fragment extraction logic. Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/bin/sx_server.ml | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/hosts/ocaml/bin/sx_server.ml b/hosts/ocaml/bin/sx_server.ml index 0edc30a5..f7a847a0 100644 --- a/hosts/ocaml/bin/sx_server.ml +++ b/hosts/ocaml/bin/sx_server.ml @@ -400,11 +400,15 @@ let setup_evaluator_bridge env = match args with | [thunk; handler] -> (try Sx_ref.cek_call thunk Nil - with Eval_error msg -> Sx_ref.cek_call handler (List [String msg])) + with Eval_error msg -> + let enhanced = Sx_ref.enhance_error_with_trace msg in + Sx_ref.cek_call handler (List [String enhanced])) | [thunk] -> (try let r = Sx_ref.cek_call thunk Nil in List [Symbol "ok"; r] - with Eval_error msg -> List [Symbol "error"; String msg]) + with Eval_error msg -> + let enhanced = Sx_ref.enhance_error_with_trace msg in + List [Symbol "error"; String enhanced]) | _ -> Nil); bind "cek-call" (fun args -> match args with @@ -617,7 +621,9 @@ let setup_strict_mode env = bind "set-strict!" (fun args -> match args with [v] -> Sx_ref._strict_ref := v; ignore (env_set env "*strict*" v); Nil | _ -> raise (Eval_error "set-strict!: expected 1 arg")); bind "set-prim-param-types!" (fun args -> match args with [v] -> Sx_ref._prim_param_types_ref := v; ignore (env_set env "*prim-param-types*" v); Nil | _ -> raise (Eval_error "set-prim-param-types!: expected 1 arg")); bind "component-param-types" (fun _args -> Nil); - bind "component-set-param-types!" (fun _args -> Nil) + bind "component-set-param-types!" (fun _args -> Nil); + bind "component-file" (fun args -> match args with [v] -> component_file v | _ -> Nil); + bind "component-set-file!" (fun args -> match args with [v; f] -> component_set_file v f | _ -> Nil) (* ---- IO helpers routed to Python bridge ---- *) let setup_io_bridges env = @@ -678,14 +684,14 @@ let make_server_env () = (* ====================================================================== *) (** Render an SX expression to HTML using the SX adapter (adapter-html.sx). - Falls back to Sx_render.render_to_html if the SX adapter isn't loaded. *) + Falls back to Sx_render.sx_render_to_html if the SX adapter isn't loaded. *) let sx_render_to_html expr env = if env_has env "render-to-html" then let fn = env_get env "render-to-html" in let result = Sx_ref.cek_call fn (List [expr; Env env]) in match result with String s -> s | _ -> Sx_runtime.value_to_str result else - Sx_render.render_to_html expr env + Sx_render.sx_render_to_html env expr env (* ====================================================================== *) @@ -768,6 +774,8 @@ let rec dispatch env cmd = | List [Symbol "load"; String path] -> (try let exprs = Sx_parser.parse_file path in + let prev_file = if Sx_types.env_has env "*current-file*" then Some (Sx_types.env_get env "*current-file*") else None in + ignore (Sx_types.env_bind env "*current-file*" (String path)); let count = ref 0 in List.iter (fun expr -> ignore (Sx_ref.eval_expr expr (Env env)); @@ -776,6 +784,9 @@ let rec dispatch env cmd = (* Rebind host extension points after .sx load — evaluator.sx defines *custom-special-forms* which shadows the native dict *) rebind_host_extensions env; + (match prev_file with + | Some v -> ignore (Sx_types.env_bind env "*current-file*" v) + | None -> ()); send_ok_value (Number (float_of_int !count)) with | Eval_error msg -> send_error msg @@ -831,7 +842,7 @@ let rec dispatch env cmd = in send_ok_raw (raw_serialize result) with - | Eval_error msg -> send_error msg + | Eval_error msg -> send_error (Sx_ref.enhance_error_with_trace msg) | exn -> send_error (Printexc.to_string exn)) | List [Symbol "vm-reset-fn"; String name] -> @@ -1538,7 +1549,7 @@ let http_render_page env path = | _ -> Sx_runtime.value_to_str result end else (* Fallback: native renderer *) - Sx_render.render_to_html_streaming body_expr env + Sx_render.sx_render_to_html env body_expr env with e -> Printf.eprintf "[http-ssr] failed for %s: %s\n%!" path (Printexc.to_string e); "" in @@ -1579,7 +1590,7 @@ let http_render_page env path = | String s | RawHTML s -> s | _ -> Sx_runtime.value_to_str result end else - Sx_render.render_to_html_streaming shell_call env + Sx_render.sx_render_to_html env shell_call env in let t4 = Unix.gettimeofday () in Printf.eprintf "[sx-http] %s route=%.3fs aser=%.3fs ssr=%.3fs shell=%.3fs total=%.3fs html=%d\n%!" @@ -2228,6 +2239,7 @@ let http_mode port = if n > 0 then begin let data = Bytes.sub_string buf 0 n in let is_ajax = is_sx_request data in + if is_ajax then Printf.eprintf "[sx-http] AJAX request detected\n%!"; let handled = try fast_handle client data is_ajax with e ->