Skip to content

fix(agents): preserve recovered task progress and lifecycle ownership - #138785

Merged
steipete merged 1 commit into
mainfrom
codex/review-138394
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/review-138394

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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.

  • 216 focused tests passed: task registry (150), Gateway runtime (7), replacement/recovery/cleanup (59). After moving notice tests, all 59 focused tests passed again without exclusions.
  • Full changed-scope checks passed: formatting, core/test type graphs, core/tooling lint, dead exports, plugin boundaries, schema v15, database-first storage, import cycles, and webhook/pairing guards.
  • Fresh independent Codex P0–P2 review: scoped-clean. The unresolved [Bug]: Recovery cannot adopt accepted run after a transient receipt write failure #138783 is explicitly recorded as an unchanged base defect.

Live OpenAI hard-restart proof

Blacksmith Testbox run, through Crabbox, lease tbx_01m1qjrh3zwpegkvpm39e1qfaf (stopped). The wrapper verified source 1426e49d2b26c5f4a9e8db1c1ed96c15d701643a with 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.

model: gpt-5.6-luna
OpenAI Responses requests: 5, all HTTP 200
SIGKILL -> automatic successor generation: 1 -> 2
canonical task/flow and requester/child identities: preserved
operator prompt required: false
resumption confirmations: 1
completion replies: 1
exec/wait calls before restart: 1/1
exec/wait calls after second restart + 65-second sweep: 1/1
task and flow after reopening: succeeded

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 07f18d5ff74bb361b46e1eacab0bddc28da26752 checked codex-rs/app-server-protocol/src/protocol/common.rs:530-535,982-987 and codex-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.

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.
@clawsweeper

clawsweeper Bot commented Sep 5, 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 docs Improvements or additions to documentation agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 02:23
@steipete steipete self-assigned this Sep 5, 2026
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Verified for landing on head e66d575d99bd56b76cd9100c506b2cebe73a0066.

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.

@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Exact-head CI and native preparation passed for e66d575d99bd56b76cd9100c506b2cebe73a0066. Please review the owner-lifecycle follow-up and recorded real OpenAI hard-restart proof. The native merge gate requires a completed review. The independent acceptance-write bug is tracked separately in #138783 and is not part of this patch.

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 10:44 PM ET / September 5, 2026, 02:44 UTC.

ClawSweeper review

What this changes

Preserves 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
Reviewed head: e66d575d99bd56b76cd9100c506b2cebe73a0066

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with strong recorded restart evidence and relevant regression coverage; no blocking correctness finding remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Captured live output exercises automatic replacement through an ephemeral Gateway and real OpenAI transport after SIGKILL, with preserved identities, one notice/completion, and no repeated recorded tool calls after another restart. Source-reviewed owner regressions cover the added activity and retirement checks; the linked Actions artifact was not independently retrievable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured live output exercises automatic replacement through an ephemeral Gateway and real OpenAI transport after SIGKILL, with preserved identities, one notice/completion, and no repeated recorded tool calls after another restart. Source-reviewed owner regressions cover the added activity and retirement checks; the linked Actions artifact was not independently retrievable.
Evidence reviewed 11 items Pinned introduction and merge ownership: The checkout matches the pinned PR head. The verified test merge records the pinned base first and exact PR head second; its delta contains the same 13 introduced paths, not the unrelated endpoint drift.
Repair remains necessary on reviewed main: The task event listener, accepted-run cleanup, and restart-recovery modules are unchanged between the merge base and fetched main. Main therefore still lacks this PR's canonical-run event correlation and two lifecycle checks.
Activity routing and sibling contracts: The listener resolves successor events through the registry's taskRunId and checks backing generation plus child session before updating activity. The existing direct-run path remains intact for ACP, CLI, and non-registry native children. Inspected the task lookup, backing-authority checks, activity overlay, mutation owner, and sibling tests for direct activity and shared-run session isolation.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source +19, Tests +133, Docs +12. Total +164 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 86 67 +19
Tests 5 279 146 +133
Docs 1 17 5 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 382 218 +164

Review metrics

Metric Value Why it matters
Production versus test growth Production net +19; tests/support net +133, with relocated notice cases discounted The production growth supplies missing canonical-owner correlation and lifecycle fencing while removing unused publication branches; test growth protects those observable boundaries.

Technical review

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

Labels

Label changes:

  • add P2: This is a bounded recovery-progress and lifecycle repair without evidence of an urgent released-user regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Captured live output exercises automatic replacement through an ephemeral Gateway and real OpenAI transport after SIGKILL, with preserved identities, one notice/completion, and no repeated recorded tool calls after another restart. Source-reviewed owner regressions cover the added activity and retirement checks; the linked Actions artifact was not independently retrievable.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured live output exercises automatic replacement through an ephemeral Gateway and real OpenAI transport after SIGKILL, with preserved identities, one notice/completion, and no repeated recorded tool calls after another restart. Source-reviewed owner regressions cover the added activity and retirement checks; the linked Actions artifact was not independently retrievable.

Label justifications:

  • P2: This is a bounded recovery-progress and lifecycle repair without evidence of an urgent released-user regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Captured live output exercises automatic replacement through an ephemeral Gateway and real OpenAI transport after SIGKILL, with preserved identities, one notice/completion, and no repeated recorded tool calls after another restart. Source-reviewed owner regressions cover the added activity and retirement checks; the linked Actions artifact was not independently retrievable.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured live output exercises automatic replacement through an ephemeral Gateway and real OpenAI transport after SIGKILL, with preserved identities, one notice/completion, and no repeated recorded tool calls after another restart. Source-reviewed owner regressions cover the added activity and retirement checks; the linked Actions artifact was not independently retrievable.

Evidence

What I checked:

  • Pinned introduction and merge ownership: The checkout matches the pinned PR head. The verified test merge records the pinned base first and exact PR head second; its delta contains the same 13 introduced paths, not the unrelated endpoint drift. (e66d575d99bd)
  • Repair remains necessary on reviewed main: The task event listener, accepted-run cleanup, and restart-recovery modules are unchanged between the merge base and fetched main. Main therefore still lacks this PR's canonical-run event correlation and two lifecycle checks. (src/tasks/task-registry-lifecycle.ts:35, 116c6c3be399)
  • Activity routing and sibling contracts: The listener resolves successor events through the registry's taskRunId and checks backing generation plus child session before updating activity. The existing direct-run path remains intact for ACP, CLI, and non-registry native children. Inspected the task lookup, backing-authority checks, activity overlay, mutation owner, and sibling tests for direct activity and shared-run session isolation. (src/tasks/task-registry-lifecycle.ts:39, e66d575d99bd)
  • Cleanup retains existing dispatch ownership: Cleanup now stops retrying when its captured Gateway resolver retires. Exact-run abort checks, preserved-session handling, and session-id/lifecycle-revision deletion guards remain unchanged. The Gateway dispatcher already rejects retired bound owners rather than falling back to a new socket. (src/agents/subagents/spawn/subagent-spawn-cleanup.ts:178, e66d575d99bd)
  • Post-delivery notice ownership: The pending-notice path rechecks Gateway generation, exact registry entry, and notice identity immediately after awaited delivery, before clearing debt or resuming monitoring. The accepted-recovery sibling already applies equivalent settlement checks, and the Gateway notice sender checks ownership again at platform dispatch. (src/agents/subagents/registry/subagent-registry-restart-recovery.ts:52, e66d575d99bd)
  • Atomic publication and distinct persistence follow-up: The replacement transaction still compares durable source, task, and flow records before writing, then publishes all memory projections before deferred observers. Removed return values and optional observer branches have no remaining production callers needing them. The accepted-versus-consumed receipt mismatch described at [Bug]: Recovery cannot adopt accepted run after a transient receipt write failure #138783 remains outside these changes. (src/agents/subagents/registry/subagent-registry-replacement-store.ts:78, e66d575d99bd)

Likely related people:

  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 6e82d8a into main Sep 5, 2026
251 checks passed
@steipete
steipete deleted the codex/review-138394 branch September 5, 2026 02:53
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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