Repository navigation
fix(agents): preserve exec outcomes across lifecycle races - #125532
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 11:57 PM ET / August 18, 2026, 03:57 UTC. ClawSweeper reviewWhat this changesThe PR makes Gateway and node approval continuations absorb terminal follow-up failures and keeps a sandboxed command foregrounded while its final cleanup determines the real outcome. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessNo blocking findings. This maintainer PR repairs the current detached-approval and sandbox-finalization races at their existing lifecycle owners; keep it open for exact-head CI rather than auto-closing a maintainer-owned item. Priority: P1 Review scores
Verification
How this fits togetherExec requests may await approval and then run through either the Gateway or a remote node, with a later follow-up reporting the terminal result. Separately, the exec tool may promote a long command to a background task unless the process lifecycle is already finalizing a terminal outcome. flowchart LR
A[Exec request] --> B[Approval wait]
B --> C[Gateway or node dispatch]
C --> D[Terminal result]
D --> E[Follow-up delivery]
A --> F[Sandbox cleanup]
F --> G[Foreground or background decision]
G --> D
Before merge
Agent review detailsSecurityNone. PR surfaceSource +8, Tests +170. Total +178 across 6 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the two host-specific dispatch boundaries and the process-owned finalizing state, then land after the rebased head confirms the focused lifecycle coverage and required CI. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main leaves the Gateway callback unawaited and allows the yield path to ignore the process-owned finalizing state. This read-only review did not execute the tests. Is this the best way to solve the issue? Yes. The patch uses the existing shared approval-wait owner, preserves separate Gateway/node dispatch provenance where their execution boundaries differ, and reads the already-owned finalizing fact instead of adding a parallel state path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c75d4dc91142. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Detached Gateway follow-up failures no longer escape after dispatch, and sandbox finalization cannot be falsely backgrounded. Related: #125529
c67bfd4 to
7858620
Compare
|
Addressed the actionable ClawSweeper review on rebased head
Local proof on the rebased head:
Exact-head CI is pending after the force-push. |
|
Merged via squash.
|
…125532) * fix(agents): preserve exec outcomes across lifecycle races Detached Gateway follow-up failures no longer escape after dispatch, and sandbox finalization cannot be falsely backgrounded. Related: openclaw#125529 * fix(agents): own detached approval failures * style(agents): format approval continuation
Related: #125529
What Problem This Solves
Fixes an issue where an approved Gateway command could finish successfully but a failure while registering or delivering its asynchronous follow-up would escape the detached promise chain as an unhandled rejection, obscuring the real execution outcome.
It also fixes a race where a sandboxed command that had already exited could be reported as still running when the foreground yield timer fired while asynchronous sandbox finalization was still in progress. That false promotion also created a background task row that immediately changed to terminal.
Why This Change Was Made
The change builds on main's canonical
resolveExecApprovalWaitOutcomeowner. Gateway request-failure delivery is now awaited, and both Gateway and node detached continuations have terminal non-rejecting recovery handlers. Invocation-start provenance prevents any post-dispatch delivery failure from being reclassified as an execution denial; pre-dispatch failures still make a best-effortapproval-request-faileddelivery whose own failure is consumed.Foreground exec yielding now observes the existing process-owned
finalizingstate, which is set before sandbox cleanup awaits. The command stays foregrounded until finalization produces the real terminal outcome.Session reset/delete ownership was traced separately. The process scope remains reachable through the canonical session key; the unresolved policy is whether reset/delete should preserve or cancel inherited background work. That owner call is intentionally left to #125529 rather than being chosen silently in this PR.
User Impact
Operators no longer lose the real result of an approved Gateway or node command to an unhandled follow-up rejection. Exited sandbox commands also no longer flash as running or create transient background task records while cleanup completes.
There is no behavior change yet for active background commands across session reset or deletion; #125529 records the verified current semantics and recommended policy split.
Evidence
Pre-fix regressions:
synchronous runtime-handoff registration failurerejection.createBackgroundExecTaskonce whilefinalizeExecwas pending (1 failed, 4 passed).Post-fix proof on the rebased head:
node scripts/run-vitest.mjs src/agents/bash-tools.exec-host-gateway.test.ts— 95/95 passed.node scripts/run-vitest.mjs src/agents/bash-tools.exec-host-node.test.ts— 85/85 passed.node scripts/run-vitest.mjs src/agents/bash-tools.exec-task-wiring.test.ts— 5/5 passed.node scripts/run-vitest.mjs src/agents/bash-tools.exec-gateway-approval.e2e.test.ts— 1/1 passed against a real isolated Gateway approval flow.node scripts/check-changed.mjs -- src/agents/bash-tools.exec-host-gateway.ts src/agents/bash-tools.exec-host-node.ts src/agents/bash-tools.exec-run.ts src/agents/bash-tools.exec-host-gateway.test.ts src/agents/bash-tools.exec-host-node.test.ts src/agents/bash-tools.exec-task-wiring.test.ts— core and coreTests lanes passed.pnpm format:check— repository-wide formatting passed.main; the superseding UI fixes are already onmain, so this PR contains no UI files.git diff --check— passed.ClawSweeper's two P1 findings and both rank-up moves are addressed: request-failure delivery is owned, the final recovery handlers cannot reject, and focused Gateway/node double-rejection regressions cover both hosts.
Production LOC: +36/-28 (net +8) for explicit detached lifecycle/provenance ownership. Tests: +184/-14 (net +170).
AI-assisted; the final diff and lifecycle ownership paths were reviewed directly.