Repository navigation
fix: agent turns recover when database worker exits between operations - #163258
Conversation
|
🦞👀 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. Reviewed October 5, 2026, 4:19 AM ET / 08:19 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR lets pending agent database operations recover from a worker that exited between operations, while keeping previously captured worker-generation claims invalid. Merge readiness✅ Ready for maintainer review Keep open: current main and the latest release retain the recovery gap. The patch has no actionable correctness findings, and the recorded native-worker evidence sufficiently proves the scoped recovery behavior. Priority: P1 Review scores
Verification
How this fits togetherAgent database execution connects session and agent operations to each agent’s SQLite worker. Its lifecycle owner controls preparation, dispatch, native cleanup, and replacement workers. flowchart TD
A[Agent or session operation] --> B[Database execution owner]
B --> C{Retained worker available}
C -->|Yes| F[Guarded operation dispatch]
C -->|No| D[Settle worker and lease cleanup]
D --> E[Recheck caller and database ownership]
E --> G[Prepare replacement worker]
G --> F
F --> H[Operation result]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -2, Tests +43. Total +41 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep recovery inside the existing execution owner, replace only a failed generation before dispatch, and preserve cleanup custody and stale-claim rejection. Do we have a high-confidence way to reproduce the issue? Yes: terminate a retained native worker between operations, then call prepare or runExisting. Current-main source establishes the failure, and the recorded base-restoration experiment makes both regressions fail; this review did not execute them. Is this the best way to solve the issue? Yes: retiring the unavailable generation before dispatch is a narrow lifecycle repair that preserves the existing owner and avoids replaying submitted operations. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b658e685c314. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
Integrate the current native generation contract and adapt the recovery preflight to its failure classification.
Let preparation fall back to the execution owner when its retained native generation has failed. Keep cleanup and authority checks before replacement work, and cover prepare and existing operations with the native worker regression. Co-authored-by: goutamadwant <[email protected]>
|
Merged via squash.
|
openclaw#163258) * fix(state): reopen unavailable agent native owner before dispatch * fix: recover prepared database claims after worker exit Let preparation fall back to the execution owner when its retained native generation has failed. Keep cleanup and authority checks before replacement work, and cover prepare and existing operations with the native worker regression. Co-authored-by: goutamadwant <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: goutamadwant <[email protected]>
#163258) * fix(state): reopen unavailable agent native owner before dispatch * fix: recover prepared database claims after worker exit Let preparation fall back to the execution owner when its retained native generation has failed. Keep cleanup and authority checks before replacement work, and cover prepare and existing operations with the native worker regression. Co-authored-by: goutamadwant <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: goutamadwant <[email protected]> (cherry picked from commit 88095dc)
Adapt the native-generation recovery fix to the extended-stable failed() generation API. Co-authored-by: RomneyDa <[email protected]>
Fixes #163151
What Problem This Solves
Fixes: an agent turn fails when its retained database worker exits between operations, even though the pending operation has not been dispatched.
User Impact
The pending operation can run on a fresh native database generation without requiring the user to resend the turn. Already-dispatched operations are not replayed. No schema, durability, retention, configuration, or migration changes are required.
Why This Change Was Made
The execution owner settles the failed generation's native close and lease cleanup before admitting replacement work, then rechecks owner, source, caller, and cancellation authority. The prepared-generation fast path also reports an unavailable generation as unprepared so its caller can take the existing preparation path. Previously captured generation claims remain invalid after recovery.
Original fix by @goutamadwant; maintainer cleanup simplifies the close call, preserves the retirement invariant in a concise comment, adapts the fix to the current native-generation contract, and extends the existing native-worker regression to both
prepareandrunExisting. Main was integrated through a normal merge commit; contributor history is preserved.Evidence
Current proof is bound to pushed head
051376e82d032b0ecaccdbfae90860e9182ecaed.cbx_6070fd20640d, Linux, Node 24.21.0, pnpm 12.5.1. Trusted-main bootstrap verified the full head and IMDSv2 no-role boundary; no hydration, no Tailscale, isolated HOME, and only CI forwarded. Lease stopped and confirmed released.pnpm tsgo:core— passed in 17.15 seconds on that lease.pnpm test src/state/openclaw-agent-execution.close-wedge.test.ts --maxWorkers=1— 8 passed. The tests terminate a real native worker, recover through both entry points, read through the replacement, and verify the old claim cannot become valid again.src/state/openclaw-agent-execution.tsfrom main commitf12c30cd91c8f952e573536d9a242da0fb68f850, then ranpnpm test src/state/openclaw-agent-execution.close-wedge.test.ts --maxWorkers=1 -t "reopens a native generation lost between operations before dispatch". Both new cases failed withAgent database execution lost its native owner: the prepared-claim path and pre-dispatchrunExistingpath. Restored the pushed production file afterward.git diff --checkpassed. Repository lint/type wrappers refused the shared dependency layout; the remote typecheck and CI supply that proof. Independent review completed with no actionable P0–P2 findings.LOC versus origin/main: production +6/−8 (net −2); tests +43/−0.
Test cost:
pnpm test src/state/openclaw-agent-execution.close-wedge.test.ts --maxWorkers=1took 46.85 seconds wall time in isolated AWS, including compiled-worker preparation; Vitest duration was 20.60 seconds. The two new cases took 1.90 and 1.91 seconds. CI recorded 15.62 seconds of Vitest duration and 43.93 seconds including the test wrapper. Real worker termination and native lease settlement require this boundary; mocks would not establish that custody has ended before replacement.The original production exit cause and long-running live Gateway behavior were not reproduced. This proves the worker-loss transition and recovery of an operation that had not yet been dispatched.