Skip to content

fix: diagnose wedged gateways and resume sessions after SIGKILL - #190964

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-main-thread-wedge-evidence-and-kill-resume-20260919
Nov 2, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-main-thread-wedge-evidence-and-kill-resume-20260919

Conversation

@steipete

@steipete steipete commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes missing diagnostics during an unbounded Gateway JavaScript spin and missing automatic continuation after SIGKILL interrupts a main-session turn.

User Impact

A supported Node Gateway writes a bounded, in-progress stall profile to stderr after 30 seconds, repeating at most once per minute. Interrupted root sessions receive one ordinary resume input after an unclean restart, using the same eligibility and admission path as graceful restart markers. No configuration or schema migration is required; prompt and tool definitions stay unchanged.

The existing consume-before-admit startup interruption window remains. Resume asks the agent to inspect current state before repeating work; it does not guarantee external tool effects exactly once. Native waits that cannot service inspector interrupts can still prevent a JS profile.

Why This Change Was Made

The existing recorder could report only after the main event loop returned. Its observer now interrupts only to rotate the existing bounded native recording, then formats and writes directly from the worker. Starting a new inspector profiler during a spin can miss the active leaf, so this preserves the existing sampler and code map. The old inline worker source is replaced, and profile formatting is shared rather than duplicated.

Turn admission already persists a nonterminal run identity and terminal settlement clears it. Startup consumes orphaned identities and shutdown markers in one decision, with existing owner/eligibility checks and no extra scan, checkpoint, or recovery store. Production delta is +143 lines, including only +11 for resume; tests +221, performance tooling +232. The observer is the necessary new capability behind the growth.

Also removes one unused type export introduced by #190318. The exact main parent reproduces that dead-export regression; the same production scan passes after the correction.

Evidence

  • Baseline regression: an isolated Gateway killed mid-turn retained its run identity without a shutdown marker, then made zero continuation requests. The clean owner-level negative control likewise resumes only the marked session before the fix.
  • Node 26.12.1 endless-spin harness: first profile at 30.266 s, repeat at 90.301 s, both name stallProbeSpin, within the 2 KiB profile budget. Native snapshot rotation was 0.1 ms; this excludes inspector serialization. Exact-base negative control emits no report.
  • Focused restart-resume, event-loop health, main-thread stall, recorder, and prompt-prefix tests pass. pnpm build passes. pnpm check:changed was run; its four failed gates were repaired and rerun successfully (core/script lint, assertion comments, and the inherited dead export). Remaining gates, including typechecks and formatting, passed on the initial run. No changed module is imported by the Control UI.
  • Independent Codex autoreview against 796b14713458, covering the complete local patch at P0–P2: scoped-clean, no actionable findings.

Synthetic measurement uses a 35.13 GiB agent database, 10,000 sessions, one million inline transcript rows, and 62,000 workspace files / 1.116 GB on APFS. Five counterbalanced batches of ten preparations per arm, separate A/A and A/B timing/allocation passes. No production data was used.

Per preparation Before median / p95 After median / p95
Wall, ms 18.997 / 19.491 19.043 / 19.329
Main-isolate CPU, ms 5.811 / 5.890 5.678 / 5.975
Process CPU, ms 24.461 / 28.645 27.050 / 28.042
Sampled main-isolate allocation, B 5,649,606 / 5,683,203 5,675,046 / 5,773,870
History-worker tasks 2 / 2 2 / 2

Mean changes are -0.31% wall, -1.31% main CPU, +2.18% process CPU (A/A +4.08%), and -0.33% sampled allocation. These are neutral results within controls/spread, not claimed savings. Five-batch p95 is the maximum. The measurement excludes model admission, cold integrity scans, worker/native allocation, and btrfs. Reproduce with scripts/perf/restart-resume-measure.ts and the existing session-read-transactions-fixture.mjs.

Actual Node Gateway E2E: all three tests pass, including SIGKILL mid-turn, exactly one continuation, a further idle restart without duplication, and both graceful-restart variants. A separate real-model proof (Node 26.12.1, OpenAI gpt-4.1-mini) killed the Gateway during an actual exec checkpoint: one original user turn produced exactly one restart input, one final completion, and one resumed file effect, completing 14.250 s after SIGKILL. A further idle graceful restart produced no duplicate continuation or effect. The actual Node 26.12.1 dev Gateway, with SIGUSR1 debugging disabled, timed out on readiness while spinning yet emitted named in-progress profiles at 30.039 s and 90.174 s (854 and 1,077-byte lines, native rotation 0.5/0.1 ms), before its deliberate SIGKILL. Healthy observer A/A–A/B results remain pending and will be recorded before landing.

Healthy observer measurement (macOS, packaged worker; synthetic retained 10,800 sessions and 62,000 file paths): five paired 3.6-second steady windows plus A/A controls. Total CPU median/p95 is 8.002/8.409 → 10.518/10.952 ms; mean 8.030 → 10.513 ms (+30.9% relative, +0.069 percentage points of one CPU core). Main CPU is 3.744 → 5.228 ms mean (+0.041 points). Native sample/report mean is 0.245 → 0.370 ms, candidate maximum 0.504 ms. Added worker heap is 4.71 MiB and process RSS 7.90 MiB. Combined sampled main/worker allocation is 595,294 → 541,443 B/window, but A/A variability precludes an allocation-saving claim. This is an explicit small absolute CPU/memory tradeoff for off-main evidence, not a zero-cost or performance-improvement claim. macOS adds one observer; Linux already had that worker, and no Linux overhead extrapolation is claimed. Healthy operation starts no extra profiler or inspector session.

The initial CI run exposed a fixture race in the extended graceful-restart test: its second continuation reused an already-resolved provider gate. The fixture now consumes that gate when releasing its held response. The same failed case passes locally after the repair (1 passed, 2 unselected), and refreshed Codex P0–P2 review is scoped-clean.

A separate CI failure is inherited: test/extension-test-boundary.test.ts rejects the private import in test/decision-baseten-admission.integration.test.ts. The same selected test fails on exact parent 796b14713458a20de36316eff479603dd84c7225 with that sole offender. Direct main commit 91f4975d99f9df8939d84729a4927ed427384de4 introduced the import. This main regression was subsequently repaired by #190958 (50f868506375); the boundary job passes in the refreshed exact-head CI merge. No CI bypass is needed for it.

Report bounded in-progress JavaScript stall evidence from the observer worker and consume persisted orphan run identities through the existing restart-resume decision. Preserve graceful restart eligibility and avoid duplicate continuations when a shutdown marker also exists.
@clawsweeper

clawsweeper Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: XL labels Nov 2, 2026
@steipete
steipete marked this pull request as ready for review November 2, 2026 07:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T07:57:09.370925Z af96cdc Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete enabled auto-merge (squash) November 2, 2026 08:23
@steipete
steipete merged commit b1b6a46 into main Nov 2, 2026
134 of 136 checks passed
@steipete
steipete deleted the steipete/perf-micro-main-thread-wedge-evidence-and-kill-resume-20260919 branch November 2, 2026 08:24
@steipete

steipete commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…claw#190964)

* fix: diagnose wedged gateways and resume sessions after SIGKILL

Report bounded in-progress JavaScript stall evidence from the observer worker and consume persisted orphan run identities through the existing restart-resume decision. Preserve graceful restart eligibility and avoid duplicate continuations when a shutdown marker also exists.

* test: consume restart provider gates between continuations
steipete added a commit that referenced this pull request Nov 5, 2026
Keep completed command input out of the running lifecycle projection instead
of trying to clear it with a synthetic end event. Persist queued runtime starts
through the existing lifecycle owner before lazy chat mapping checks.

Preserve writer and revision guards, existing run timing, and prediction anchors.
Add prior-session, reset, and queued-start regressions. Allocate 104 test lines
for these distinct persistence and event-ordering contracts.

Related: #193508, #190964
steipete added a commit that referenced this pull request Nov 5, 2026
* fix: keep completed chat commands from resuming after crashes

* fix(gateway): preserve crash recovery across chat commands

Keep completed command input out of the running lifecycle projection instead
of trying to clear it with a synthetic end event. Persist queued runtime starts
through the existing lifecycle owner before lazy chat mapping checks.

Preserve writer and revision guards, existing run timing, and prediction anchors.
Add prior-session, reset, and queued-start regressions. Allocate 104 test lines
for these distinct persistence and event-ordering contracts.

Related: #193508, #190964

* fix(gateway): let runtime events own running markers

Capability commands can commit input before producing their reply, so a fallback
persistence override is too late. Keep all input transcript commits activity-only
and let the existing lifecycle owner persist actual runtime starts.

Remove the fallback override plumbing and cover an early approved input commit.
The complete change is production-line neutral. Allocate 116 net regression test
lines for prior turns, reset revisions, early input commits, and queued starts.

* fix(gateway): recover accepted input before runtime start

Commit plain-input recovery and writer identity with the transcript, leaving command persistence activity-only. Preserve ordered runtime starts and settle setup failures against the accepted writer. Document hook-ended and command-to-run recovery limits.

* test(gateway): align settled fallback writer identity

Use the admitted run identity throughout the existing fallback delivery fixture. Preserve the replacement-writer rejection case while reflecting atomic input ownership.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
…#193558)

* fix: keep completed chat commands from resuming after crashes

* fix(gateway): preserve crash recovery across chat commands

Keep completed command input out of the running lifecycle projection instead
of trying to clear it with a synthetic end event. Persist queued runtime starts
through the existing lifecycle owner before lazy chat mapping checks.

Preserve writer and revision guards, existing run timing, and prediction anchors.
Add prior-session, reset, and queued-start regressions. Allocate 104 test lines
for these distinct persistence and event-ordering contracts.

Related: openclaw#193508, openclaw#190964

* fix(gateway): let runtime events own running markers

Capability commands can commit input before producing their reply, so a fallback
persistence override is too late. Keep all input transcript commits activity-only
and let the existing lifecycle owner persist actual runtime starts.

Remove the fallback override plumbing and cover an early approved input commit.
The complete change is production-line neutral. Allocate 116 net regression test
lines for prior turns, reset revisions, early input commits, and queued starts.

* fix(gateway): recover accepted input before runtime start

Commit plain-input recovery and writer identity with the transcript, leaving command persistence activity-only. Preserve ordered runtime starts and settle setup failures against the accepted writer. Document hook-ended and command-to-run recovery limits.

* test(gateway): align settled fallback writer identity

Use the admitted run identity throughout the existing fallback delivery fixture. Preserve the replacement-writer rejection case while reflecting atomic input ownership.
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 6, 2026
…#193558)

* fix: keep completed chat commands from resuming after crashes

* fix(gateway): preserve crash recovery across chat commands

Keep completed command input out of the running lifecycle projection instead
of trying to clear it with a synthetic end event. Persist queued runtime starts
through the existing lifecycle owner before lazy chat mapping checks.

Preserve writer and revision guards, existing run timing, and prediction anchors.
Add prior-session, reset, and queued-start regressions. Allocate 104 test lines
for these distinct persistence and event-ordering contracts.

Related: openclaw#193508, openclaw#190964

* fix(gateway): let runtime events own running markers

Capability commands can commit input before producing their reply, so a fallback
persistence override is too late. Keep all input transcript commits activity-only
and let the existing lifecycle owner persist actual runtime starts.

Remove the fallback override plumbing and cover an early approved input commit.
The complete change is production-line neutral. Allocate 116 net regression test
lines for prior turns, reset revisions, early input commits, and queued starts.

* fix(gateway): recover accepted input before runtime start

Commit plain-input recovery and writer identity with the transcript, leaving command persistence activity-only. Preserve ordered runtime starts and settle setup failures against the accepted writer. Document hook-ended and command-to-run recovery limits.

* test(gateway): align settled fallback writer identity

Use the admitted run identity throughout the existing fallback delivery fixture. Preserve the replacement-writer rejection case while reflecting atomic input ownership.
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…#193558)

* fix: keep completed chat commands from resuming after crashes

* fix(gateway): preserve crash recovery across chat commands

Keep completed command input out of the running lifecycle projection instead
of trying to clear it with a synthetic end event. Persist queued runtime starts
through the existing lifecycle owner before lazy chat mapping checks.

Preserve writer and revision guards, existing run timing, and prediction anchors.
Add prior-session, reset, and queued-start regressions. Allocate 104 test lines
for these distinct persistence and event-ordering contracts.

Related: openclaw#193508, openclaw#190964

* fix(gateway): let runtime events own running markers

Capability commands can commit input before producing their reply, so a fallback
persistence override is too late. Keep all input transcript commits activity-only
and let the existing lifecycle owner persist actual runtime starts.

Remove the fallback override plumbing and cover an early approved input commit.
The complete change is production-line neutral. Allocate 116 net regression test
lines for prior turns, reset revisions, early input commits, and queued starts.

* fix(gateway): recover accepted input before runtime start

Commit plain-input recovery and writer identity with the transcript, leaving command persistence activity-only. Preserve ordered runtime starts and settle setup failures against the accepted writer. Document hook-ended and command-to-run recovery limits.

* test(gateway): align settled fallback writer identity

Use the admitted run identity throughout the existing fallback delivery fixture. Preserve the replacement-writer rejection case while reflecting atomic input ownership.

Source: d4e2ec8

Release adaptation: Selected eight runtime owners plus five focused lifecycle/regression files applied cleanly. Accepted plain input commits writer/recovery marker atomically before optional dispatch; commands remain activity-only and queued starts persist before lazy mapping. Existing transcript persistence consumes supplied lifecycle overrides; no schema bump. Source companion followups are later recovery extensions, not prerequisites. Format/diff checks pass; crash/restart runtime proof remains unavailable in shared setup.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 3bddffae7abd8c48cfeae5c6433ca91c0335200c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant