Skip to content

fix(agents): preserve exec outcomes across lifecycle races - #125532

Merged
steipete merged 3 commits into
mainfrom
steipete/bold-wiles-be1d8d
Aug 18, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/bold-wiles-be1d8d

Conversation

@steipete

@steipete steipete commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

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 resolveExecApprovalWaitOutcome owner. 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-effort approval-request-failed delivery whose own failure is consumed.

Foreground exec yielding now observes the existing process-owned finalizing state, 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:

  • Gateway completed outcome: the test recorded the real terminal outcome but failed with an unhandled synchronous runtime-handoff registration failure rejection.
  • Gateway pre-dispatch recovery: rejecting both the original follow-up and its fallback produced an unhandled rejection (1 failed, 93 passed).
  • Node pre-dispatch recovery: the same double-rejection path produced an unhandled rejection (1 failed, 84 passed).
  • Sandbox finalization race: the yield timer incorrectly called createBackgroundExecTask once while finalizeExec was 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.
  • The previously failing core lint stripe passed on current main; the superseding UI fixes are already on main, so this PR contains no UI files.
  • Fresh branch Codex autoreview — clean, no accepted/actionable findings.
  • 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.

@steipete steipete self-assigned this Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 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 the agents Agent runtime and tooling label Aug 18, 2026
@steipete
steipete marked this pull request as ready for review August 18, 2026 02:43
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 18, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 11:57 PM ET / August 18, 2026, 03:57 UTC.

ClawSweeper review

What this changes

The 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 provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No 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
Reviewed head: 7858620ddf2649c429f297d71162f05c010b28ce

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with meaningful regression coverage and no remaining correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal lifecycle repair is not subject to the external-contributor proof gate; its PR body also reports an isolated real Gateway approval-flow run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal lifecycle repair is not subject to the external-contributor proof gate; its PR body also reports an isolated real Gateway approval-flow run.
Evidence reviewed 5 items Current-main approval defect: Current main invokes the request-failure callback without awaiting it, while the detached Gateway continuation can reject from its own recovery path.
PR preserves dispatch outcome: The proposed Gateway path awaits request-failure delivery, records that invocation has started before local dispatch, and terminates the final recovery promise without reclassifying a post-dispatch failure as denial.
Shared lifecycle owner: Sandbox runtime sets finalizing before awaiting cleanup and clears it only before the terminal session transition; the PR makes the yield decision respect that owner state.
Findings None None.
Security None None.

How this fits together

Exec 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
Loading

Before merge

  • Resolve merge risk (P1) - The repair is production net +8 lines; the host-specific invocation provenance is justified because Gateway dispatches a local process while node dispatches a remote invocation, so no smaller shared terminal-recovery owner was identified.
  • Resolve merge risk (P1) - Exact-head CI was still in progress in the supplied PR state; merge only after it completes successfully.
  • Complete next step (P2) - No repair lane is needed: the reviewed maintainer PR has no actionable finding and only awaits normal exact-head validation.
Agent review details

Security

None.

PR surface

Source +8, Tests +170. Total +178 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 36 28 +8
Tests 3 184 14 +170
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 220 42 +178

Review metrics

Metric Value Why it matters
Production versus regression coverage production +36/-28 (net +8); tests +184/-14 (net +170) The small production increase establishes terminal ownership across two distinct execution hosts; the larger test change covers the prior unhandled-rejection and finalization-race boundaries.

Merge-risk options

Maintainer options:

  1. Confirm the rebased lifecycle proof (recommended)
    Require successful exact-head CI and the focused approval/finalization suites before merge because this code determines whether command completion remains observable.

Technical review

Best 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.

Labels

Label justifications:

  • P1: The repaired lifecycle races can hide a completed exec result or temporarily misrepresent a terminal command as running.
  • merge-risk: 🚨 availability: A regression in detached exec completion can leave command outcomes unobservable or create incorrect transient task state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal lifecycle repair is not subject to the external-contributor proof gate; its PR body also reports an isolated real Gateway approval-flow run.

Evidence

What I checked:

Likely related people:

  • steipete: Available history and blame place Peter Steinberger on the recent shared approval-decision and approval-wait refactors, as well as this PR head. (role: recent area contributor and approval-flow refactor owner; confidence: high; commits: b485f0c6270c, 4ed01969e86c, 7858620ddf26; files: src/agents/bash-tools.exec-host-gateway.ts, src/agents/bash-tools.exec-host-node.ts, src/agents/bash-tools.exec-run.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for exact-head CI to complete before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-18T02:51:31.909Z sha c67bfd4d057a4dd289e96e95beeb850d948bfc15 :: needs changes before merge. :: [P1] Terminate rejected fallback delivery | [P1] Do not leave the outer recovery catch rejectable

Detached Gateway follow-up failures no longer escape after dispatch, and sandbox finalization cannot be falsely backgrounded.

Related: #125529
@steipete
steipete force-pushed the steipete/bold-wiles-be1d8d branch from c67bfd4 to 7858620 Compare August 18, 2026 03:51
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the actionable ClawSweeper review on rebased head 7858620ddf2649c429f297d71162f05c010b28ce.

  • Kept current main's resolveExecApprovalWaitOutcome as the canonical approval owner.
  • Gateway now awaits request-failure delivery before the detached continuation can settle.
  • Gateway and node both terminally consume a rejected final recovery delivery; invocation-start provenance prevents post-dispatch failures from becoming false denials.
  • Added focused Gateway and node regressions where both the original follow-up and fallback delivery reject, plus the completed-outcome and sandbox-finalization race coverage.
  • Applied both Rank-up moves: with no skips.

Local proof on the rebased head:

  • Gateway host: 95/95
  • Node host: 85/85
  • Exec task wiring: 5/5
  • Real isolated Gateway approval E2E: 1/1
  • check-changed core/coreTests: passed
  • Repository formatting and the previously failing core lint stripe: passed
  • Fresh branch autoreview: clean

Exact-head CI is pending after the force-push.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@steipete
steipete merged commit d2be70d into main Aug 18, 2026
226 of 227 checks passed
@steipete
steipete deleted the steipete/bold-wiles-be1d8d branch August 18, 2026 04:08
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant