Import hook: verify library registered, re-entry guard

- _import_hook verifies library_loaded_p AFTER load_library_file
  to catch cases where the file loads but define-library doesn't register
- Re-entry guard (_loading_libs) prevents infinite retry loops
- cek_run import patch deferred — retry approach infinite-loops because
  cek_step_loop re-enters deeply nested eval contexts. Root cause:
  eval_expr → cek_run → cek_step_loop processes the ENTIRE remaining
  kont chain after import resolution, which includes rendering code that
  triggers MORE eval_expr calls. Needs architectural solution (step-level
  suspension handling, not run-level).

Server runs with 4 harmless IO suspension errors. These don't affect
functionality — symbols load via the global env.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-05 01:16:03 +00:00
parent 244c669334
commit b8f389ac9b

View File

@@ -807,7 +807,9 @@ let () =
Hashtbl.replace _loading_libs key true;
let result = match resolve_library_path lib_spec with
| Some path ->
(try load_library_file path; true
(try load_library_file path;
(* Verify the library actually registered *)
Sx_types.sx_truthy (Sx_ref.library_loaded_p lib_spec)
with e ->
Printf.eprintf "[import-hook] FAIL %s from %s: %s\n%!"
key path (Printexc.to_string e);