Repository navigation
fix(agents): preserve recovered task progress and lifecycle ownership - #138785
Conversation
Follow up on #138394: route successor activity through the canonical task identity, reject stale predecessor activity, stop cleanup after Gateway retirement, and fence notice settlement after awaited delivery. Simplify atomic publication and document hard-kill recovery. The acceptance-receipt persistence cut point is tracked separately in #138783.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Verified for landing on head The owner-level regressions and sibling paths pass (216 tests total); the reorganized 59 recovery/replacement/cleanup tests pass without exclusions. Changed-scope static checks and fresh independent Codex P0–P2 review pass, and the native review artifacts validate with zero findings. Live OpenAI proof is recorded in the PR body and Testbox run: five successful Responses calls, automatic recovery after SIGKILL, stable identities, one notice/completion, and no repeated exec/wait after a second restart and full sweep. The seven changed production modules match the tested candidate byte-for-byte. Both owned leases are stopped. The separate acceptance-receipt persistence failure remains tracked in #138783; this PR does not change transaction validation or claim that issue fixed. Exact-head CI run 33938916347 completed successfully. ClawSweeper has published its acknowledgement but no review findings or rank-up moves; the fresh independent review is clean. |
|
@clawsweeper review Exact-head CI and native preparation passed for |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 10:44 PM ET / September 5, 2026, 02:44 UTC. ClawSweeper reviewWhat this changesPreserves progress updates for recovered background tasks, prevents retired Gateway work from continuing cleanup or settling notices, and simplifies atomic publication helpers with regression coverage and updated recovery documentation. Merge readiness✅ Ready for maintainer review No blocking findings. This remains a useful follow-up against the reviewed main: the ownership and activity gaps are still present there, and the recorded restart proof supports the bounded repair. The separate acceptance-write failure is not introduced or claimed fixed by this PR. Priority: P2 Review scores
Verification
How this fits togetherThe subagent registry owns individual background executions, while tasks and Task Flows retain the logical work identity across restarts. Agent events update operator-visible progress, and Gateway-scoped recovery coordinates requester notices and cleanup. flowchart TD
A[Agent events and restart recovery] --> B[Subagent registry owner]
B --> C{Current execution and Gateway?}
C -->|Yes| D[Canonical task and Task Flow]
D --> E[Visible progress and completion]
C -->|No| F[Ignore retired work]
B --> G[Notice delivery and cleanup]
G --> C
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +19, Tests +133, Docs +12. Total +164 across 13 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep canonical task identities stable while the existing registry supplies current-execution correlation and the Gateway lifecycle controls cleanup and notice settlement. Do we have a high-confidence way to reproduce the issue? Yes, from source: replace an execution while retaining its task run identity, then emit successor and predecessor activity; reviewed main still routes by execution ID alone. The supplied regressions also cover retirement during cleanup and held notice delivery; tests were not executed in this read-only review. Is this the best way to solve the issue? Yes. Correlating events at the existing task listener preserves execution-specific event IDs for sibling runtimes, while reusing captured Gateway ownership avoids a new cleanup mechanism; the publication changes retain the existing transaction and observer ordering. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 116c6c3be399. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…openclaw#138785) Follow up on openclaw#138394: route successor activity through the canonical task identity, reject stale predecessor activity, stop cleanup after Gateway retirement, and fence notice settlement after awaited delivery. Simplify atomic publication and document hard-kill recovery. The acceptance-receipt persistence cut point is tracked separately in openclaw#138783.
* refs/remotes/origin/main: (602 commits) fix(plugins): trace trust refusals and repair legacy provenance (openclaw#138746) perf(sqlite): reuse compiled plugin state point reads (openclaw#138758) refactor: type chat prefetch dependencies and clean loading tests (openclaw#138793) ci: reduce Doctor test startup and core lint jobs (openclaw#138796) feat(update): retain run history and share outcome reports (openclaw#138690) chore(deps): update @openclaw/fs-safe to 0.8.1 (openclaw#138500) fix: preserve global board ownership from pinning to notifications (openclaw#138675) fix(gateway): deliver session catalog updates from slow hosts (openclaw#138674) perf(sessions): index pending conversation replies (openclaw#127182) perf(auth): reuse ordered provider alias entries (openclaw#138805) docs(diagnostics): clarify whole-process CPU metrics (openclaw#138804) perf(memory): narrow source reads and stream embedding cache rows (openclaw#138766) fix: allow older source on newer Testbox checkouts (openclaw#138782) fix(agents): preserve recovered task progress and lifecycle ownership (openclaw#138785) perf(codex): reduce rollout tail scan CPU (openclaw#138784) perf(gateway): stop projecting history deltas at the byte budget (openclaw#138655) fix(build): bound native declaration inputs to checkout (openclaw#138742) fix(cli): preserve foreground Gateway argument handling (openclaw#138765) fix(ui): align task toolbar with side-panel tabs (openclaw#138769) fix(logbook): drain accepted work before closing SQLite (openclaw#138754) ... # Conflicts: # src/agents/embedded-agent-runner/compact.queued.ts
Related: #138394, #137991. Separate persistence follow-up: #138783.
What Problem This Solves
Fixes an issue where automatically recovered subagent tasks stopped showing progress, while late events from their predecessor could overwrite activity or errors. It also fixes cleanup retrying after its Gateway retires and pending resumption notices settling state after lifecycle retirement.
Why This Change Was Made
The registry remains the execution owner, and the task retains its logical identity across replacement runs. Task activity now follows the current registry generation and child session, preserving direct-run ACP/CLI routes. Cleanup uses its existing Gateway-scope liveness predicate; notice settlement revalidates the same owner immediately after awaited delivery.
Atomic publication helpers now require deferred observers where their sole caller already deferred them, discard unused return values, and avoid an unnecessary clone. The recovery notice tests share the existing isolated harness in a focused sibling suite. Recovery docs now describe hard kills and the requester notice.
Production LOC: +86/-67 (net +19). Tests/support: +279/-146 (net +133, including moved notice cases). Docs: +17/-5. The production growth provides current-owner event correlation and lifecycle fencing; unused publication branches were removed. No schema, configuration, dependency, protocol or transaction-validation change.
This follows the restart-recovery work by @fuller-stack-dev in #138394. The separately reproduced acceptance-write failure is tracked in #138783 and is not claimed fixed here.
User Impact
Recovered tasks keep visible assistant/tool progress without accepting stale predecessor updates. Gateway retirement releases pending cleanup, and a notice that finishes after retirement cannot clear the retired owner's recovery state. Existing task, flow, requester and child-session identities remain stable.
Evidence
Before the fixes, real event/registry tests lost successor activity and accepted predecessor activity; the cleanup regression issued a second abort after retirement; both held-send notice cases cleared debt after lifecycle rotation. Those regressions now pass.
Live OpenAI hard-restart proof
Blacksmith Testbox run, through Crabbox, lease
tbx_01m1qjrh3zwpegkvpm39e1qfaf(stopped). The wrapper verified source1426e49d2b26c5f4a9e8db1c1ed96c15d701643awith the candidate changes; all seven changed production modules were compared byte-for-byte with this PR's files. Proof used an ephemeral Gateway, a synthetic QA channel, and a real OpenAI key from the prepared test environment, confined to a loopback provider proxy.The stopped-Gateway failure projection was explicit fault injection; it is not claimed to arise naturally from every SIGKILL. This is bounded recovery/replay evidence, not a general exactly-once guarantee for external effects. Initial remote attempts failed before tests due to missing prepared dependencies and a stale hydration/source mismatch; a matching fresh lease passed without weakening source verification.
Direct Codex dependency inspection at
07f18d5ff74bb361b46e1eacab0bddc28da26752checkedcodex-rs/app-server-protocol/src/protocol/common.rs:530-535,982-987andcodex-rs/app-server/src/request_processors/thread_lifecycle.rs:568-760: thread resume reports/attaches thread state; starting a turn is a separate request. This repair stays in OpenClaw lifecycle ownership.