Repository navigation
fix(exec): a conversation waiting on a background command hangs after a Gateway crash - #199499
Conversation
…ng crashes A conversation that ended its turn waiting on an ordinary background command hung silently after a Gateway crash: the command's exit wake lived only in memory. Graceful restarts sent a generic resume input from a shutdown marker instead. The process registry now keeps a best-effort row for each wake-armed ordinary Gateway-host command in the existing durable_background_processes table (kind: "ordinary", generic command summary, no unit) while it runs. On startup the durable owner reports each remaining row once through the existing lost-process completion path, under the session's current authority, then deletes it. The notice says what happened, using the boot record to tell a shutdown from a crash: shutdown and Linux crashes stop the command; on macOS a killed Gateway can leave it running. The restart marker no longer tracks background processes (hadBackgroundExec is gone), so one owner reports lost commands. Commands that would not wake the conversation no longer trigger a restart resume turn. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesPersist running background-command waiters and notify their conversations when a Gateway restart loses their completion wake. Example: A macOS Gateway receives SIGKILL while background command briny-falcon waits for CI.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current silent recovery failure without a blocking defect found; the supplied upgrade run resolves the previous review’s compatibility blocker. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe process registry owns background commands and their restart records; Gateway startup converts surviving ordinary-command records into completion events admitted through the existing session authority and delivery path. flowchart TD
A[Background exec] --> B[Process registry]
B --> C[Existing SQLite process store]
C --> D[Gateway startup recovery]
D --> E[Current session admission]
E --> F[Conversation continuation]
Technical reviewBest possible solution: Use the existing process registry and completion path to report lost ordinary waiters while preserving durable adoption and current session authority. Do we have a high-confidence way to reproduce the issue? Current-main source retains completion state only in memory for ordinary commands and writes their restart marker only during shutdown; the supplied base crash trace shows the resulting stalled conversations. Is this the best way to solve the issue? The change uses the existing storage, startup, notification, and authority owners, removes the superseded marker path, and adds no configuration or schema version. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d9a692869294. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +170, Tests +117, Docs +33. Total +320 across 16 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed November 15, 2026, 2:31 AM ET / 07:31 UTC (Revision 4). |
…indows waiters Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed as 68971b3. A conversation waiting on a background command no longer hangs silently after a Gateway crash: the lost waiter is recorded and reported on startup, incognito conversations write no record, and sandbox/Windows commands keep graceful-restart recovery. |
… a Gateway crash (openclaw#199499) ## What Problem This Solves Fixes: a conversation that ended its turn waiting for a background command to exit never hears about it again when the Gateway crashes or is killed mid-wait. The exit wake lived only in memory, and the restart resume marker is written only by a graceful shutdown, so after a crash the conversation hung silently. ## User Impact User impact: after any Gateway restart, crashes included, each conversation that was waiting on an ordinary background command gets one notice for that command. The notice names the process handle and start time and says what happened to the command, so the agent can check its output and run it again. Durable commands (`durable: true`) keep their existing adopted exit wake and get no notice. Behavior changes: - The generic "Background exec processes were stopped; rerun them if still needed" sentence in the graceful-restart resume input is gone. The per-command notice replaces it. - A background command whose exit would not wake the conversation, such as a service with `notifyOnExit` off, no longer causes a restart resume turn. ## Why This Change Was Made The process registry already owns the `durable_background_processes` table, its startup pass and the lost-process wake. It now also keeps a best-effort row for each running ordinary command whose exit would wake its conversation, on every platform: - The row reuses the existing table with `kind: "ordinary"` and the generic command summary. It needs no new table, column or schema version. - The row is written when the command is backgrounded and deleted when the command exits. - Incognito sessions are never recorded, because their state stays in memory. - Sandbox commands are recorded with a `sandboxed` flag. The Gateway cannot see inside the container, so their notice says the command may still be running. - Windows runs the startup pass too (durable launches stay Linux and macOS only), so Windows waiters keep a restart notice. On startup, the existing durable pass: - reports every remaining row once through the existing completion path, under the session's current authority, then deletes it; - rechecks eligibility as for durable outcomes (reset, archived and hidden subagent sessions, or `notifyOnExit` off, get nothing); - waits for agent database readiness, which finishes after the listener binds after a crash. The graceful-restart marker no longer tracks background processes (`hadBackgroundExec` is removed), so one owner reports lost commands. The notice text follows a measured fact. In each case below, the Gateway process alone was killed and a real agent's background commands were watched: | Host | Gateway killed (SIGKILL) | Graceful stop | | --- | --- | --- | | macOS, plain and under a launchd LaunchAgent | A silent command keeps running as an orphan; one that writes output dies at its next write | All stopped | | Linux (systemd 255 user service with the installed policy, and plain) | All stopped within 2 s | All stopped | The startup pass reads the Gateway boot record to tell a crash from a shutdown. After a shutdown, or a crash on Linux, the notice says the command was stopped. After a crash on macOS it says the command may still be running, but its result will not wake this conversation. No orphan tracking is added; `durable: true` remains the way to keep a command alive. ## Evidence Real-agent E2E on an isolated source Gateway (`openai/gpt-6-astra`, 6 concurrent conversations per arm, automations tool denied). Each conversation waits on a fake CI that turns green about 300 s after its first check. The Gateway is stopped about 90 s after every conversation has started its wait and ended its turn, then a new Gateway starts on the same state. | Arm | Waiting, turn ended | Conversations resumed | Re-armed a waiter | Finished the task | | --- | --- | --- | --- | --- | | base `0a8e0b7d9cd0`, crash (SIGKILL) | 6/6 | **0/6** | 0/6 | 0/6 | | fix, crash (SIGKILL) | 6/6 | **6/6** | 6/6 | 6/6 | | fix, graceful (SIGTERM) | 6/6 | 6/6, one notice each | 6/6 | 5/6 (one model-written loop's pattern never matched "all 15 checks passed") | | fix, `durable: true` waiter, graceful | 6/6 | 0 restart notices, 0 polls; 6/6 woken by the adopted exit | n/a | 6/6 | <details><summary>Public trace, crash on macOS, base vs fix (trial 1, paths redacted)</summary> Base: the conversation waits forever. ``` + 28s exec {"yieldMs": 1000, "timeoutSeconds": 3660} "python3 -u - <<'PY' …" + 29s -> Command still running (session quiet-ocean:…). Its exit wakes this conversation … + 32s sessions_yield (Gateway SIGKILLed at +137 s, new Gateway ready; nothing else ever arrives) ``` Fix: one notice, the agent checks and re-arms, then finishes. ``` + 32s exec {"background": true, "timeoutSeconds": 1830} "python3 -u - <<'PY' …" + 32s -> Command still running (session briny-falcon:…). Its exit wakes this conversation … + 36s sessions_yield +166s USER: Exec failed (briny-fa, unknown exit code, 2m9s): The Gateway restarted unexpectedly while this background command (started 2026-11-15T05:37:58.662Z) was running. It may still be running, but its result will not wake this conversation. Check its output and side effects before running it again. +176s exec "ps -p 13156 …; ./ci-status" +176s -> PR openclaw#4241: 4 checks pending, 11 passed +190s exec {"background": true, "timeoutSeconds": 1830} "python3 -u - <<'PY' …" +326s USER: Exec completed (neat-bre, code 0, 2m15s): … all 15 checks passed … +328s reply: PR openclaw#4241 is ready—all 15 checks passed. Saved and verified the summary in `pr-1/RESULT.md` … ``` Graceful stop with the fix: `Exec failed (vivid-du, unknown exit code, 2m12s): This background command (started …) was stopped when the Gateway shut down, so its result will not arrive. If you still need it, check its output and side effects, then run it again.` </details> Upgrade from latest stable (v2026.11.3, `847611dcaa3b`), real agent, isolated state: 1. A v2026.11.3 Gateway ran 3 waiting conversations, then got a graceful stop. 2. This branch ran `openclaw doctor --fix --yes`, which migrated state schema 22 to 40 (exit 0), then started on the same state. Sessions and transcripts loaded (transcript backfill 3/3 sessions, 122 rows). The startup pass found no `durable_background_processes` table, because the table is created on first use, and logged nothing. 3. A new conversation on the upgraded state started a waiter and ended its turn. The table was created and held one row: `ordinary:cool-ridge:…`. 4. The Gateway got SIGKILL. The next start sent `Exec failed (cool-rid, unknown exit code, 1m5s): The Gateway restarted unexpectedly while this background command (started 2026-11-15T07:22:46.300Z) was running. It may still be running, …`. The agent checked for survivors, re-armed, and finished (`PR openclaw#4249 is ready—all 15 checks passed`). 0 rows remained. v2026.11.3 writes neither restart markers nor process rows. Commands running when it stops therefore get no notice after the upgrade. This PR does not change the legacy upgrade bridge. Tests: - `src/agents/bash-process-durable.test.ts` adds "reports each wake-armed ordinary command a restart lost, once, with what happened to it". It fails on base and passes with the fix. It covers: a command that exits leaves no row; a crashed command and a stopped command are each reported once with the right text; rows are gone afterwards. - Restart marker tests now mark sessions through a live run instead of a background process, because background processes no longer create a marker. - `test/gateway-restart-resume.e2e.test.ts` now expects the stopped background case to receive the per-command notice instead of the resume sentence. It passes 5/5 on 4 consecutive runs. Under heavy host load, both base and this branch hit an intermittent mock-provider `JSON Parse error: Unexpected EOF`. - The durable registry test also records a sandbox command (cautious notice) and an incognito command (no row); removing the incognito check turns it red (4 rows instead of 3). - Focused suites pass: restart resume, session event context, lifecycle state, startup resume, process registry, durable notify, post-attach startup, and the restart recovery integrity suite. Known gaps: - Worker and `host=node` commands are not recorded, as before; their processes are owned elsewhere. - A best-effort row write can fail; the command still runs normally and only the restart notice is missing. - If the boot record is unavailable, a macOS crash would be reported as a shutdown. Co-authored-by: Ayaan Zaidi <[email protected]>
…tely (#202066) Problem: docs/gateway/restart-recovery.md still said a session owning a running background process is marked running at shutdown and resumed, and that a completed reply with background commands resumes. #199499 removed that marker (hadBackgroundExec) and moved lost background commands to their own exit notices; shutdown selection does not select background-process owners. Fix (docs only): an interrupted root gets the ordinary resume input; a finished root with a notifying background command gets the lost-process exit notice instead. Named accepted edge case: an interrupted root that also had a notifying background command gets both and may reply twice (rare, visible, recoverable; kept so restart recovery stays independent of process reporting). Proof: real-Gateway SIGKILL restart on unchanged main showed the two-input case; pnpm docs:list, docs:check-mdx, docs:check-links, format:docs:check, git diff --check; clean exact-head local ClawSweeper review. Co-authored-by: Ayaan Zaidi <[email protected]>
…tely (openclaw#202066) Problem: docs/gateway/restart-recovery.md still said a session owning a running background process is marked running at shutdown and resumed, and that a completed reply with background commands resumes. openclaw#199499 removed that marker (hadBackgroundExec) and moved lost background commands to their own exit notices; shutdown selection does not select background-process owners. Fix (docs only): an interrupted root gets the ordinary resume input; a finished root with a notifying background command gets the lost-process exit notice instead. Named accepted edge case: an interrupted root that also had a notifying background command gets both and may reply twice (rare, visible, recoverable; kept so restart recovery stays independent of process reporting). Proof: real-Gateway SIGKILL restart on unchanged main showed the two-input case; pnpm docs:list, docs:check-mdx, docs:check-links, format:docs:check, git diff --check; clean exact-head local ClawSweeper review. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: a conversation that ended its turn waiting for a background command to exit never hears about it again when the Gateway crashes or is killed mid-wait. The exit wake lived only in memory, and the restart resume marker is written only by a graceful shutdown, so after a crash the conversation hung silently.
User Impact
User impact: after any Gateway restart, crashes included, each conversation that was waiting on an ordinary background command gets one notice for that command. The notice names the process handle and start time and says what happened to the command, so the agent can check its output and run it again. Durable commands (
durable: true) keep their existing adopted exit wake and get no notice.Behavior changes:
notifyOnExitoff, no longer causes a restart resume turn.Why This Change Was Made
The process registry already owns the
durable_background_processestable, its startup pass and the lost-process wake. It now also keeps a best-effort row for each running ordinary command whose exit would wake its conversation, on every platform:kind: "ordinary"and the generic command summary. It needs no new table, column or schema version.sandboxedflag. The Gateway cannot see inside the container, so their notice says the command may still be running.On startup, the existing durable pass:
notifyOnExitoff, get nothing);The graceful-restart marker no longer tracks background processes (
hadBackgroundExecis removed), so one owner reports lost commands.The notice text follows a measured fact. In each case below, the Gateway process alone was killed and a real agent's background commands were watched:
The startup pass reads the Gateway boot record to tell a crash from a shutdown. After a shutdown, or a crash on Linux, the notice says the command was stopped. After a crash on macOS it says the command may still be running, but its result will not wake this conversation. No orphan tracking is added;
durable: trueremains the way to keep a command alive.Evidence
Real-agent E2E on an isolated source Gateway (
openai/gpt-6-astra, 6 concurrent conversations per arm, automations tool denied). Each conversation waits on a fake CI that turns green about 300 s after its first check. The Gateway is stopped about 90 s after every conversation has started its wait and ended its turn, then a new Gateway starts on the same state.669576890a1f, crash (SIGKILL)durable: truewaiter, gracefulPublic trace, crash on macOS, base vs fix (trial 1, paths redacted)
Base: the conversation waits forever.
Fix: one notice, the agent checks and re-arms, then finishes.
Graceful stop with the fix:
Exec failed (vivid-du, unknown exit code, 2m12s): This background command (started …) was stopped when the Gateway shut down, so its result will not arrive. If you still need it, check its output and side effects, then run it again.Upgrade from latest stable (v2026.11.3,
847611dcaa3b), real agent, isolated state:openclaw doctor --fix --yes, which migrated state schema 22 to 40 (exit 0), then started on the same state. Sessions and transcripts loaded (transcript backfill 3/3 sessions, 122 rows). The startup pass found nodurable_background_processestable, because the table is created on first use, and logged nothing.ordinary:cool-ridge:….Exec failed (cool-rid, unknown exit code, 1m5s): The Gateway restarted unexpectedly while this background command (started 2026-11-15T07:22:46.300Z) was running. It may still be running, …. The agent checked for survivors, re-armed, and finished (PR #4249 is ready—all 15 checks passed). 0 rows remained.v2026.11.3 writes neither restart markers nor process rows. Commands running when it stops therefore get no notice after the upgrade. This PR does not change the legacy upgrade bridge.
Tests:
src/agents/bash-process-durable.test.tsadds "reports each wake-armed ordinary command a restart lost, once, with what happened to it". It fails on base and passes with the fix. It covers: a command that exits leaves no row; a crashed command and a stopped command are each reported once with the right text; rows are gone afterwards.test/gateway-restart-resume.e2e.test.tsnow expects the stopped background case to receive the per-command notice instead of the resume sentence. It passes 5/5 on 4 consecutive runs. Under heavy host load, both base and this branch hit an intermittent mock-providerJSON Parse error: Unexpected EOF.Known gaps:
host=nodecommands are not recorded, as before; their processes are owned elsewhere.