Skip to content

fix: settle interrupted subagent completions after cleanup - #182065

Merged
steipete merged 2 commits into
openclaw:mainfrom
ericcaiwx-star:codex/native-settle-cleanup-owner-20261024
Oct 24, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
ericcaiwx-star:codex/native-settle-cleanup-owner-20261024

Conversation

@ericcaiwx-star

@ericcaiwx-star ericcaiwx-star commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #182062. Related: #142224, #182046, and #181184.

What Problem This Solves

Fixes a completed requester turn leaving its interrupted child's durable wake dispatching after legitimate cleanup retires the child's transient recovery marker.

User Impact

The same interrupted task can finish completion bookkeeping after cleanup, including when a follow-up already owns the child session. Changed runtime, task, requester, child incarnation, kill state, or terminal result still refuses settlement.

Why This Change Was Made

src/agents/subagents/completion/subagent-completion-admission.store.ts:280 on the inspected main rejected any terminalOwner change. src/agents/subagents/registry/subagent-registry-lifecycle-bookkeeping.ts:166 legitimately clears interrupted-recovery after recording cleanup and the sticky session-effects fence. A retained requester completion therefore lost settlement solely because cleanup succeeded.

The existing admission owner now recognizes that one-way transition only with the cleanup receipt, sticky fence, and identical interrupted terminal timing/outcome. It retains the surrounding owner and requester checks, then commits through the existing registry/SQLite path. Late provider and yield results remain fenced.

Team relevance is bounded: the sanitized journal correlation in merged #181184 records a recovered parent/requester-settle session fa35e3ac, a later yield-cleanup timeout at boot-log line 3744, stale reports at 4113/4265, and six queued-without-run reports at 4542/4635/4928/5435/6569/8395. Those logs establish a related cleanup wedge, but do not identify its retained barrier or prove this exact marker mismatch. This PR fixes the independently reproduced settlement defect; it does not claim to repair every Team cleanup timeout.

Evidence

Maintainer validation uses main 7b71c23797646bed71dc869b83a1c51764c267a6 merged into the original contributor commit, without rebasing or changing the two-file patch.

  • Red on main: with unchanged main production code and the regression test overlaid, the same-terminal case fails at currentCompletionOwner with Subagent completion owner changed before mutation; all 13 changed-state controls pass. The real cleanup controller creates the cleanup state, and the test reopens SQLite to verify durable settlement or unchanged rejected rows. Baseline: 1 failed / 13 passed, 167.82 seconds wall time (158.46 seconds reported by Vitest, dominated by compilation).
  • Fixed head 426650184280128f24b5ae72558cc137804c85cc: all 67 completion/storage cases passed (51 requester-wake, 16 storage/admission), followed by all 3 late-provider/yield controls. The two-file run took 362.21 seconds including cold worker compilation; the changed file reported 59.09 seconds, of which 57% was test execution. The three filtered lifecycle controls took 97.61 seconds including cache validation; skipped cases are not claimed as executed.
  • Core production types passed; changed-test types passed (agents-sessions, 6.9 seconds). Focused typed lint, formatting, and git diff --check passed.
  • Independent Codex autoreview: scoped-clean, no actionable P0–P2 findings on the committed branch. The review covers the patch; executed behavior is established separately above.
  • Exact-head CI watcher: GREEN for 426650184280128f24b5ae72558cc137804c85cc, run 40053463881. Ten superseded same-lane checks are excluded by the native policy. No rerun or inherited-failure exception was needed.

Production delta: +31/-2 lines (net +29). Tests: +119/-0. The added code is the narrow predicate needed to distinguish legitimate marker retirement from a different terminal winner; no new owner, retry loop, schema, config, or authority is introduced. Thanks @ericcaiwx-star; the contributor's commit and patch are preserved.

Accepted limits: this is completion bookkeeping, not requester-source admission (#182046) or pending-parent continuation source recovery (#182043). No live Team/Gateway or real channel was touched. The contributor reported separate combined-patch synthetic Gateway proof, but maintainer acceptance here rests on the executed owner/SQLite regression and final-head CI; it makes no standalone live-provider or business-side-effect claim.

Focused validation commands
pnpm test src/agents/subagents/completion/subagent-completion-admission.requester-wake.test.ts src/agents/subagents/completion/subagent-completion-admission.store.test.ts --maxWorkers=1
pnpm test src/agents/subagents/registry/subagent-registry-lifecycle.test.ts --maxWorkers=1 -t 'keeps a cleaned legacy recovery winner|persists interrupted recovery before task projection'
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental
node scripts/run-tsgo-core-test-shards.mjs --changed-paths-json '["src/agents/subagents/completion/subagent-completion-admission.requester-wake.test.ts"]' --concurrency 1
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/subagents/completion/subagent-completion-admission.store.ts src/agents/subagents/completion/subagent-completion-admission.requester-wake.test.ts
pnpm exec oxfmt --check src/agents/subagents/completion/subagent-completion-admission.store.ts src/agents/subagents/completion/subagent-completion-admission.requester-wake.test.ts

Node 26.12.1; repository-selected Bun test runtime. The baseline uses the first test file with -t 'settles a cleaned interrupted winner' against the unmodified main owner. Skipped cases from filtered runs are not counted as executed.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 24, 2026
@ericcaiwx-star
ericcaiwx-star marked this pull request as ready for review October 24, 2026 00:55
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Allow an interrupted subagent completion to settle after cleanup retires its transient recovery marker.

Example: Gateway recovery interrupts generation 1, then generation 2 continues in the same child session before the original completion settles.

  • Before: Cleanup clears terminalOwner, so the original completion is rejected and its requester wake remains dispatching.
  • After: The unchanged interrupted result settles as delivered and clears its wake while the session-effects suppression fence remains active.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with inspectable Gateway and durable-state evidence; full-process recovery evidence explicitly combines the separate source repair, and no persisted format or migration changes are introduced.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): Published built-Gateway logs and SQLite reopen audits exercise normal completion and active crash/restart through real host subagent tools, a synthetic channel, and a loopback HTTP model. The source-only run remains dispatching; combined commit 0a38fe2ad20e5c1b60051ee42159dffcc24abef5 settles both generations with one parent receipt and preserved transcript rows. Exact-head regression output separately verifies this patch and rejection controls. This satisfies the previous request for inspectable evidence; combined evidence does not establish standalone full recovery, live-channel behavior, or the separate pending-parent scenario.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A parent completion can arrive after restart while the interrupted child’s durable delivery and requester wake remain unsettled.
Reason: This restores legitimate settlement without changing cleanup policy, authorization, configuration, schemas, or the separate recovery-source contract.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current settlement defect with a narrow change that preserves the surrounding ownership checks; no actionable code findings remain.

Priority: P2
Reviewed head: 9aabdbf9fd73965afe18fdded712a93ae1289f6c

Before merge

None.

Findings

None.

Agent review details

How this fits together

The completion admission store checks retained run snapshots against current registry ownership before committing delivery and requester-wake bookkeeping through the existing SQLite worker.

flowchart TD
  A[Interrupted child run] --> B[Cleanup controller]
  B --> C[Registry published row]
  D[Retained completion snapshot] --> E[Completion admission store]
  C --> E
  E --> F[SQLite mutation worker]
  F --> G[Settled delivery and cleared wake]
Loading

Technical review

Best possible solution:

Recognize completed cleanup as preserving the same interrupted result’s settlement custody within the existing admission owner.

Do we have a high-confidence way to reproduce the issue?

Current source exposes the conflicting cleanup and settlement predicates, and published baseline output fails at the intended owner check; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch is the smallest complete repair: refine the existing comparison for the verified one-way cleanup transition while preserving runtime, generation, lifecycle, requester, kill, terminal-time, and outcome checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 05bc4bf5c9fc.

Provenance checked

  • Completion ownership comparison keeps the original intent (3f761a8: Serialize legitimate registry mutations while rejecting genuine owner changes and preserving uncertain-write fences.)
  • Requester-wake settlement and receipt custody keeps the original intent (10e951e: Keep committed settlement and continuation work recoverable without repeating database writes or requester delivery.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +29, Tests +119. Total +148 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 31 2 +29
Tests 1 119 0 +119
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 150 2 +148

Root-cause cluster

Relationship: same_root_cause
Canonical: #182062
Summary: This PR repairs the cleanup-marker settlement defect; requester-source capture and pending-parent recovery remain independently owned work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A bounded restart-recovery defect leaves durable completion bookkeeping unsettled; widespread or urgent impact is not established.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-24T01:21:13.332Z sha 9aabdbf :: needs real behavior proof before merge. :: none

Reviewed October 23, 2026, 9:50 PM ET / October 24, 2026, 01:50 UTC (Revision 2).

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The PR body now includes inspectable archived Gateway/driver log excerpts and exact read-only SQLite audit output for the source-only failure and combined 0a38fe2ad20e5c1b60051ee42159dffcc24abef5 normal/active-restart runs. It shows cleanup receipts, same-child generation-2 continuation, both delivery rows settled with no wake, one matching transport/durable receipt, empty pending input/outbound queue state, and unchanged pre-crash transcript rows. Combined scope and all unrun real-channel/Codex and unresolved pending-delivery limits are explicit. Code remains 9aabdbf9fd73965afe18fdded712a93ae1289f6c; its required code CI is successful.

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 24, 2026
@steipete
steipete merged commit 9230715 into openclaw:main Oct 24, 2026
128 of 130 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: S 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.

[Bug]: Requester settlement rejects the same interrupted task after cleanup

2 participants