Skip to content

fix(subagents): late older completion receipt delivers the superseded child answer - #166139

Merged
steipete merged 3 commits into
openclaw:mainfrom
Yun-0000:fix/subagent-older-equivalent-receipt
Oct 8, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
Yun-0000:fix/subagent-older-equivalent-receipt

Conversation

@Yun-0000

@Yun-0000 Yun-0000 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #142850

What Problem This Solves

Fixes: a requester can receive superseded child text when an older completion receipt for the same run arrives after a newer one.

User Impact

Pending completion delivery retains the newer answer or intentional silence. Equal producer end times retain the first accepted reply; corrections with a newer end time can replace it. Different child runs retain their existing generation fencing.

Why This Change Was Made

The completion owner already preserves newer terminal timing for an older equivalent receipt, but previously merged the older receipt's reply into both stored reply fields. Reply selection now respects that existing producer end-time ordering while duplicate callbacks can still finish cleanup. First producer evidence remains admissible when terminal timing exists without a reply.

The maintainer revision also consolidates duplicate completion-state access and identical capture-failure handling in the same owner. No schema, public protocol, configuration, or receipt-revision contract changes.

Original fix by @Yun-0000; maintainer cleanup by @steipete adds timestamp-tie coverage, first-evidence coverage, documentation, and isolated runtime verification. Contributor commit and verified human credit are preserved.

Evidence

Candidate: 3427c68a01086341c6257487b417ebb7bd8b72d2, after merging main a06612710e674f493a3ae8fe1158f60bb56d3924 without rebase or force-push. The docs conflict preserves main’s ACP/CLI and per-run answer wording together with receipt ordering. Original before-fix baseline: bddfdd59022dd71421ce7b6a6b7e6406bf5e69f4. Node 24.21.0, pnpm 12.5.1. All contributor-code execution used fresh Untrusted AWS leases, the trusted main bootstrap, exact-head verification, IMDS no-role admission, public networking without Tailscale, and no credential hydration.

  • Merged-head full lifecycle file: 239 passed, 69.89 s wall time (Vitest 44.92 s). The eleven added/expanded ordering and first-evidence cases are milliseconds each; existing lifecycle and worker integration setup dominates the file.
  • Prior-head negative control (0a0d7caaeb54), retaining the new tests and reverting only production: 6 expected failures, 5 passed; 30.94 s wall time. Older/tied visible, silent, and empty replies expose the defect.
  • Original pinned-main production with only the regression test patch: the same 6 failures, 5 passed; 38.13 s wall time. This confirms the remaining defect on main.
  • Earlier full registry module proof at 0a0d7caaeb54: 1,415 passed, one existing opt-in 5,000-session benchmark skipped, across 78 discovered files. The sibling invocation took 2,054.02 s including its full E2E build prerequisites; no unexpected test failures occurred.
  • Merged-head pnpm tsgo:core passed in 16.58 s; pnpm tsgo:core:test --ci-graphs-json '["core-test-agents-sessions"]' passed in 15.56 s. The earlier docs link audit checked 14,921 internal links with zero broken links; this merge adds no links, and formatting/whitespace checks passed.
  • Formatting, focused oxlint, and git diff --check passed locally; no contributor runtime code ran on the maintainer host.
  • Merged-head CI passed on 3427c68a01086341c6257487b417ebb7bd8b72d2.

Fresh merge validation: one new secretless AWS lease, cbx_c273a343f8dc (r7a.4xlarge, 128 GiB nominal; 129,108,512 KiB reported), ran all three requested commands and the fixed live comparison sequentially. Run run_6598439f0220bf3b0faae5661b509c4a exited 0 with MERGED_PROOF_PASS 3427c68a01086341c6257487b417ebb7bd8b72d2. The three real-Gateway cases passed again in 101.98 s: the parent received only RECEIPT-NEWER for the older receipt, only RECEIPT-FIRST for a tie, and RECEIPT-CORRECTED for the newer receipt. Main changed receipt publication and announcement composition, so the live fixed proof was rerun; the original failing-main comparison below remains historical evidence. The lease was released after proof. The first release request timed out; a fresh coordinator read confirmed it remained active before the successful retry.

The merged-head commands were:

pnpm test src/agents/subagents/registry/subagent-registry-lifecycle.test.ts --maxWorkers=1
pnpm tsgo:core
pnpm tsgo:core:test --ci-graphs-json '["core-test-agents-sessions"]'
node --import ./scripts/tsx.mjs /tmp/rel6-166139-live-merged.mts fixed

The launch used the clean trusted-main bootstrap with --provider aws --id cbx_c273a343f8dc --fresh-pr openclaw/openclaw#166139 --no-hydrate --script scripts/crabbox-untrusted-bootstrap.sh -- 3427c68a01086341c6257487b417ebb7bd8b72d2. Its first coordinator lookup timed out before admission; empty lease history was verified before retrying the same lease. No test or live failure occurred in this merge validation.

Original real Gateway before/after at 0a0d7caaeb54: lease cbx_21b67824feca, run run_8a42e5253ec5a560e0dc3421003b3df5, exit 0. Three cases passed on the fixed head (115.21 s), then the same fixture reproduced the old behavior on pinned main (113.79 s). Each case verifies both the persisted registry result and the parent's persisted chat.history.

Receipt arriving after the first completion Parent on main Parent with fix
Older producer end time RECEIPT-OLDER (superseded answer) RECEIPT-NEWER only
Equal producer end time RECEIPT-TIE-LOSER RECEIPT-FIRST only
Newer producer end time RECEIPT-CORRECTED RECEIPT-CORRECTED

The fixture starts a real Gateway on an ephemeral loopback port with an isolated state directory and the QA mock OpenAI provider. Real RPC and sessions_spawn create the parent and child; the child reads a synthetic workspace file and completes. The public sessions.compact RPC with maxLines: 1 removes that child's full transcript, and the native announcement reader verifies that delivery will use the retained receipt. This is a relevant supported path: when a full transcript is available, it can mask a bad bounded receipt.

For deterministic receipt ordering, a scheduling wrapper delays the target child's real runSubagentAnnounceFlow, then calls the original with unchanged arguments and returns its actual result. A passive native lock-release observer joins the injected lifecycle receipt. Neither persistence nor delivery is mocked; native authority checks, SQLite, announcement, the parent model, and transcript persistence all execute. The fixture then releases delivery and asserts that the losing marker is absent from the parent history. No new production seam was added.

Sanitized excerpts:

main older: producerEndedAt=1791444613052 injectedEndedAt=1791444613051
canonicalEndedAt=1791444613052 registryResult=RECEIPT-OLDER
parent Result: [truncated-by-retention: complete child answer unavailable] RECEIPT-OLDER

fixed older: producerEndedAt=1791444488090 injectedEndedAt=1791444488089
canonicalEndedAt=1791444488090 registryResult contains RECEIPT-NEWER
parent Result contains RECEIPT-NEWER; excludes RECEIPT-OLDER

RECEIPT_PROOF_PASS mode=fixed cases=3
RECEIPT_PROOF_PASS mode=main cases=3
LIVE_COMPARISON_PASS

Proof limits: lifecycle receipt replay and scheduling are synthetic fault injection; the child execution and full requester-delivery stack are real. This tests same-run ordering, not network transport reordering. Two discarded fixture attempts exposed that intact transcripts mask receipt text and that a synthetic descendant causes another child turn; neither was counted as bug reproduction. The final fixture removes that descendant and proves the supported retained-result path. Fleet admission initially returned 429; two later coordinator lookup timeouts were reconciled before retrying. No bootstrap or product failure was hidden by retries.

Commands and cost

Unit lease: cbx_7dd97f17265b.

pnpm test src/agents/subagents/registry/subagent-registry-lifecycle.test.ts --maxWorkers=1
pnpm test src/agents/subagents/registry/subagent-registry-lifecycle.test.ts -t 'completion receipt ordering|first producer reply after terminal timing' --maxWorkers=1

The second command is the negative control and pinned-main reproduction. The remaining registry files were selected with the following command (the changed file had already run in full):

mapfile -t siblings < <(rg --files src/agents/subagents/registry | rg '\.test\.ts$' | rg -v '^src/agents/subagents/registry/subagent-registry-lifecycle.test.ts$' | sort)
pnpm test "${siblings[@]}" --maxWorkers=1
pnpm tsgo:core
pnpm tsgo:core:test --ci-graphs-json '["core-test-agents-sessions"]'
pnpm docs:check-links

Original live fixture commands, on the original exact-head untrusted lease:

# Candidate checkout, isolated Gateway/state created by the temporary fixture:
node --import ./scripts/tsx.mjs /tmp/rel6-166139-live.mts fixed
# Separate detached checkout at bddfdd59022dd71421ce7b6a6b7e6406bf5e69f4:
node --import ./scripts/tsx.mjs /tmp/rel6-166139-live.mts main

The original lanes launched from a clean trusted main worktree using crabbox run --provider aws --fresh-pr openclaw/openclaw#166139 --no-hydrate --script scripts/crabbox-untrusted-bootstrap.sh -- 0a0d7caaeb5453b037efad1f9e4c414f6200a765 .... Unit run: run_71636731b8f42bcd0e209c3714b8e455, exit 0. Both task-owned leases were released after proof.

The eleven ordering/first-evidence cases measured 5–7 ms each. These owner-boundary cases protect publication behavior rather than helper implementation; existing persistence/lifecycle cases dominate the full-file cost. The broad sibling cost is existing module coverage, not new test startup.

Exact numstat against the merged main base (main now contains the earlier cleanup, so the unchanged ordering guard is +5 production lines):

File Added Removed Net
subagent-registry-lifecycle-completion.ts (production) 6 1 +5
subagent-registry-lifecycle.test.ts 61 1 +60
docs/tools/subagents/announce.md 5 0 +5

Prior-head CI timings include shared setup and additional tests; they are not attributable per-file costs. Selected changed-test jobs took 138–217 s; production typecheck 239 s; test-type coordinator 202 s; docs 177 s.

Review decisions

The earlier full ClawSweeper review (revision 3, head 0a0d7caaeb54, October 8 at 06:39 UTC) reported no introduced correctness finding. Its two blocking asks required current-head real persistence/requester-delivery proof and a corrected body. The evidence above supplies that proof, and this body now describes equal-time retention and current-head validation.

Fresh independent Codex review of the merged candidate was scoped-clean, with no actionable P0–P2 findings.

The earlier independent Codex review identified a valid edge case: terminal timing may exist before the first producer reply. The guard now requires existing reply evidence, with older/equal first-evidence regressions. A second suggestion to introduce separate ordering against the accepted reply's own timestamp was rejected: the selected contract uses the retained run receipt endedAt. For example, a correction at 3999 is still older than the retained receipt at 4000, even if missing reply evidence was first filled by a receipt at 3998. Changing that watermark would expand the ordering contract beyond this repair. No accepted actionable review finding remains.

An older equivalent terminal receipt kept the newer end time but replaced
the stored reply, so a late replay could deliver the superseded child answer.

Co-authored-by: fangyun1008 <[email protected]>
@Yun-0000

Yun-0000 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Older equivalent completion receipts now keep a newer visible answer or intentional silence. Proof is in the PR body, on head fcb88a1.

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 6, 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 4:06 AM ET / 08:06 UTC (Revision 5).

ClawSweeper review

What this changes

Preserves accepted subagent replies when older or equal-time completion receipts arrive, while allowing newer corrections and first reply evidence.

Example: A child’s older completion receipt arrives while its newer answer awaits delivery.

  • Before: The parent receives RECEIPT-OLDER despite the registry retaining the newer completion time.
  • After: The parent receives RECEIPT-NEWER and excludes RECEIPT-OLDER.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, valuable repair with meaningful regressions, real delivery proof, and no remaining actionable finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Supplied before/after logs exercise the completion owner through a real isolated Gateway, native SQLite, retained-receipt announcement, and persisted parent chat.history for older, tied, and newer receipts. The proven candidate's ordering path is unchanged by integration; no stored-format migration is needed.
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 can receive an older child answer after a newer completion has already been accepted.
Reason: The narrow repair addresses the linked issue's remaining established defect. The existing area's contributor revised the patch and recorded the end-time ordering contract.

Merge readiness

✅ Ready for maintainer review

This PR fixes a remaining current-main defect and has sufficient real Gateway proof. No introduced correctness finding remains; the prior conflict blocker is resolved.

Priority: P1
Reviewed head: 3427c68a01086341c6257487b417ebb7bd8b72d2

Before merge

None.

Findings

None.

Agent review details

How this fits together

Subagents report completed work through a shared registry before OpenClaw delivers the result to their parent. This owner combines producer reply evidence, completion timing, persistence, and cleanup.

flowchart TD
 A[Child completion receipts] --> B[Shared completion owner]
 C[Accepted reply and end time] --> B
 B --> D{Existing evidence and incoming time}
 D -->|Older or equal| E[Retain accepted reply]
 D -->|Newer or first evidence| F[Merge producer reply]
 E --> G[Persist registry and finish cleanup]
 F --> G
 G --> H[Deliver result to parent]
Loading

Technical review

Best possible solution:

Keep receipt freshness at the shared completion owner, preserving intentional silence, newer corrections, and existing cleanup and generation fencing.

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

Yes: process a newer then older same-run receipt while delivery is pending and the full transcript is unavailable. Supplied Gateway before/after output demonstrates the failure on pinned main, and fetched current-main source retains the same mechanism; this review did not execute it.

Is this the best way to solve the issue?

Yes: the guard repairs freshness where producer evidence is accepted, without weakening terminal-evidence precedence or adding another ordering owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 1.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +5, Tests +60, Docs +5. Total +70 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 1 +5
Tests 1 61 1 +60
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 72 2 +70

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #142850
Summary: This PR repairs the linked issue's narrowed remaining same-run receipt-ordering defect.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The source-backed defect delivers superseded child answers through an existing parent workflow.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-06T14:29:48.702Z sha fcb88a1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-06T14:35:53.494Z sha fcb88a1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-08T06:39:07.066Z sha 0a0d7ca :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-08T07:41:30.775Z sha 0a0d7ca :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 6, 2026
Keep accepted producer reply evidence when an older or equal-time receipt
arrives, while allowing newer corrections and first evidence after terminal
timing. Duplicate receipts still drain the existing cleanup tail.

Cover visible, silent, and empty replies plus first producer evidence, and
consolidate completion-state/capture handling in the same owner.

Fixes openclaw#142850
Original fix by @Yun-0000; maintainer cleanup and ordering coverage.

Co-authored-by: Yun. <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S and removed size: XS labels Oct 8, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 8, 2026
Merge main at a066127 while preserving
contributor ancestry and the same-run receipt ordering guard and regressions.
Keep main's ACP/CLI transcript and per-run answer text together with the
producer end-time ordering paragraph.
@steipete
steipete merged commit 4dc4755 into openclaw:main Oct 8, 2026
138 checks passed
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
… child answer (openclaw#166139)

* fix(subagents): keep newer completion text when an older receipt arrives

An older equivalent terminal receipt kept the newer end time but replaced
the stored reply, so a late replay could deliver the superseded child answer.

Co-authored-by: fangyun1008 <[email protected]>

* fix(subagents): retain newest same-run completion reply

Keep accepted producer reply evidence when an older or equal-time receipt
arrives, while allowing newer corrections and first evidence after terminal
timing. Duplicate receipts still drain the existing cleanup tail.

Cover visible, silent, and empty replies plus first producer evidence, and
consolidate completion-state/capture handling in the same owner.

Fixes openclaw#142850
Original fix by @Yun-0000; maintainer cleanup and ordering coverage.

Co-authored-by: Yun. <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: fangyun1008 <[email protected]>
Co-authored-by: Yun. <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 11, 2026
… child answer (#166139)

* fix(subagents): keep newer completion text when an older receipt arrives

An older equivalent terminal receipt kept the newer end time but replaced
the stored reply, so a late replay could deliver the superseded child answer.

Co-authored-by: fangyun1008 <[email protected]>

* fix(subagents): retain newest same-run completion reply

Keep accepted producer reply evidence when an older or equal-time receipt
arrives, while allowing newer corrections and first evidence after terminal
timing. Duplicate receipts still drain the existing cleanup tail.

Cover visible, silent, and empty replies plus first producer evidence, and
consolidate completion-state/capture handling in the same owner.

Fixes #142850
Original fix by @Yun-0000; maintainer cleanup and ordering coverage.

Co-authored-by: Yun. <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: fangyun1008 <[email protected]>
Co-authored-by: Yun. <[email protected]>
(cherry picked from commit 4dc4755)
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

fix(subagents): revised completion serves stale terminalReply; updates carry no ordering so late refreshes regress newer results

2 participants