Diagnostic: enhanced resume error with VM frame names, clear stale reuse on re-suspend

The Not callable: nil error happens on a stub VM (frames=[], sp=0) during
cek_resume with 12 CEK kont frames. The error is from a reactive signal
subscriber (reset! current ...) that triggers during run vm after resume.
The subscriber callback goes through CEK via cek_call_or_suspend and the
CEK continuation tries to call nil.

This is a reactive subscriber notification issue, not a perform/resume
frame management issue. The VM frames are correctly restored — the error
happens during a synchronous reset! call within the resumed VM execution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-17 16:27:04 +00:00
parent 112eed50d0
commit d8fec1305b
4 changed files with 199 additions and 121 deletions

View File

@@ -132,11 +132,15 @@ let rec value_to_js (v : value) : Js.Unsafe.any =
(* Return suspension object — the JS driveAsync caller handles scheduling *)
Js.Unsafe.inject (make_suspension req2 vm2)
| Eval_error msg ->
(* Enhanced error: show pending_cek kont and reuse_stack info *)
let extra = Printf.sprintf " [vm: pending_cek=%b reuse=%d frames=%d]"
(* Enhanced error: show pending_cek kont, reuse_stack, and VM frame info *)
let vm_frame_names = String.concat "," (List.map (fun f ->
match f.Sx_vm.closure.Sx_types.vm_name with Some n -> n | None -> "?"
) v.Sx_vm.frames) in
let extra = Printf.sprintf " [vm: pending_cek=%b reuse=%d frames=[%s] sp=%d]"
(v.Sx_vm.pending_cek <> None)
(List.length v.Sx_vm.reuse_stack)
(List.length v.Sx_vm.frames) in
vm_frame_names
v.Sx_vm.sp in
ignore (Js.Unsafe.meth_call
(Js.Unsafe.get Js.Unsafe.global (Js.string "console"))
"error" [| Js.Unsafe.inject (Js.string ("[sx] resume: " ^ msg ^ extra)) |]);
@@ -549,9 +553,17 @@ let rec make_js_callFn_suspension request vm =
| Sx_vm.VmSuspended (req2, vm2) ->
Js.Unsafe.inject (make_js_callFn_suspension req2 vm2)
| Eval_error msg ->
let vm_frame_names = String.concat "," (List.map (fun f ->
match f.Sx_vm.closure.Sx_types.vm_name with Some n -> n | None -> "?"
) vm.Sx_vm.frames) in
let extra = Printf.sprintf " [vm: pending_cek=%b reuse=%d frames=[%s] sp=%d]"
(vm.Sx_vm.pending_cek <> None)
(List.length vm.Sx_vm.reuse_stack)
vm_frame_names
vm.Sx_vm.sp in
ignore (Js.Unsafe.meth_call
(Js.Unsafe.get Js.Unsafe.global (Js.string "console"))
"error" [| Js.Unsafe.inject (Js.string ("[sx] resume: " ^ msg)) |]);
"error" [| Js.Unsafe.inject (Js.string ("[sx] resume: " ^ msg ^ extra)) |]);
Js.Unsafe.inject Js.null));
obj

View File

@@ -270,6 +270,7 @@ let jit_compile_comp ~name ~params ~has_children ~body ~closure globals =
Saves the suspended CEK state in vm.pending_cek for later resume. *)
let cek_call_or_suspend vm f args =
incr _vm_cek_count;
(* Removed debug trace *)
let a = match args with Nil -> [] | List l -> l | _ -> [args] in
(* Replace _active_vm with an empty isolation VM so call_closure_reuse
inside the CEK pushes onto an empty frame stack rather than the caller's.
@@ -850,7 +851,14 @@ let resume_vm vm result =
push vm (Sx_ref.cek_value final))
| None ->
push vm result);
run vm;
(try run vm
with VmSuspended _ as e ->
(* Re-suspension during resume: the VM hit another perform.
Clear reuse_stack — these entries are stale from the PREVIOUS
suspension and don't apply to the current VM frame state.
The new VmSuspended carries the current VM state correctly. *)
vm.reuse_stack <- [];
raise e);
(* Restore call_closure_reuse continuations saved during suspension.
reuse_stack is in catch order (outermost first from prepend)
reverse to get innermost first, matching callback→caller unwinding. *)

File diff suppressed because one or more lines are too long

View File

@@ -1792,7 +1792,7 @@
blake2_js_for_wasm_create: blake2_js_for_wasm_create};
}
(globalThis))
({"link":[["runtime-0db9b496",0],["prelude-d7e4b000",0],["stdlib-23ce0836",[]],["re-9a0de245",[2]],["sx-7899047a",[2,3]],["jsoo_runtime-f96b44a8",[2]],["js_of_ocaml-651f6707",[2,5]],["dune__exe__Sx_browser-21fac337",[2,4,6]],["std_exit-10fb8830",[2]],["start-f808dbe1",0]],"generated":(b=>{var
({"link":[["runtime-0db9b496",0],["prelude-d7e4b000",0],["stdlib-23ce0836",[]],["re-9a0de245",[2]],["sx-7f504b3c",[2,3]],["jsoo_runtime-f96b44a8",[2]],["js_of_ocaml-651f6707",[2,5]],["dune__exe__Sx_browser-b285d4f3",[2,4,6]],["std_exit-10fb8830",[2]],["start-f808dbe1",0]],"generated":(b=>{var
c=b,a=b?.module?.export||b;return{"env":{"caml_ba_kind_of_typed_array":()=>{throw new
Error("caml_ba_kind_of_typed_array not implemented")},"caml_exn_with_js_backtrace":()=>{throw new
Error("caml_exn_with_js_backtrace not implemented")},"caml_int64_create_lo_mi_hi":()=>{throw new