Skip to content

Fix hung invoke freeze and reap OS children on chat stop - #11

Merged
wu1w merged 1 commit into
mainfrom
cursor/host-invoke-reap-83b9
Aug 18, 2026
Merged

Fix hung invoke freeze and reap OS children on chat stop#11
wu1w merged 1 commit into
mainfrom
cursor/host-invoke-reap-83b9

Conversation

@wu1w

@wu1w wu1w commented Aug 18, 2026

Copy link
Copy Markdown
Owner

One hung WASM invoke or audit write could freeze the whole host, and Stop left isolation_spawn_os children running until a 600s dispatcher tick. This PR keeps the personal-desktop fail-open: no new court asks, capability gates, permission prompts, or tighter allowlists.

What changed

1. A stuck invoke cannot wedge the host

  • wasm_invoke snapshots the compiled module, drops the kernel RwLock, runs the guest, then applies status under a short write lock.
  • wasmtime epoch interruption is enabled. Host TCP/stdio 30s dispatch timeout increments the engine epoch so the guest actually traps (spawn_blocking cannot be cancelled).
  • Audit JSONL append is a bounded background queue. A stuck disk no longer holds the kernel write lock. Full queue drops the line (fail-open) instead of stalling mediate/charge/court.
  • Host also starts a 5s isolation poll loop so exited children are reaped even when the Python dispatcher is idle. max_age stays 600s so long-running intended children are not killed early.

2. Chat stop reaps OS children

  • Chat stop already calls llm_release_by_process (not end_process). That RPC now isolation.drop_process and SIGKILLs the process group.
  • end_process already called drop_process; kill() no longer wait()s on the calling thread, so a wedged child cannot hold the write lock.
  • No new confirm. Default tool permissions unchanged.

3. kernel-ci stale test

  • Confirmed on current main: loop_guard::tests::orch_window_force still expected a trip after ~3 orch rounds. Production window is ≥6 of last 8.
  • Test updated to require allow for 5 orch-heavy rounds and orch_window_thrash on the 6th. Production thresholds were not loosened.

What I verified

  • Static review of current main (cfccbbb) against the C1 / H5 / H7 hypotheses. They held.
  • cargo test -p tevarn-kernel --locked --all-targets: 117 lib + 4 abi_v1 passed (including orch_window_force, wasm_invoke_does_not_hold_kernel_lock, epoch_increment_traps_infinite_loop, end_process_reaps_os_children, llm_release_by_process_reaps_os_children).
  • cargo check -p tevarn-kernel-host --locked succeeded.

Deliberately skipped (smoothness)

  • No court ask list expansion (file_edit / remote_exec / shell_session).
  • No mcp_* allowlist tightening, extra_roots rewrite, steward/_workforce checks, or per-call policy confirmation.
  • No “refuse new WASM until lock free” gate (that would idle-spin the agent). Isolation is unlock + epoch trap.
  • No Python/frontend changes. Chat stop is wired through the existing llm_release_by_process RPC.
  • No test_court_authority.py added to kernel-ci (out of scope; would not fix the cargo-first red).
  • No new crates or drive-by refactors.

How to tell this is done

  • One PR against main
  • Touched kernel tests pass, especially orch_window_force
  • Stop / end_process SIGKILLs isolation_spawn_os children without a new prompt
  • One hung wasm_invoke does not block later mediate/charge/court
Open in Web Open in Cursor 

Drop the kernel write lock across WASM invoke and audit JSONL I/O so one
stuck skill cannot freeze mediate/charge/court. Dispatch timeout now
increments the wasmtime epoch to trap the guest; stdio uses the same 30s
bound. Chat stop (llm_release_by_process) and end_process SIGKILL
isolation_spawn_os children without waiting under the lock. Retarget
orch_window_force to the production 6/8 window so kernel-ci can pass.

Co-authored-by: wu1w <wu1w@users.noreply.github.com>
@wu1w wu1w closed this Aug 18, 2026
@wu1w wu1w reopened this Aug 18, 2026
@wu1w
wu1w marked this pull request as ready for review August 18, 2026 02:45
@wu1w
wu1w merged commit 11d47ab into main Aug 18, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants