Skip to content

fix(agents): preserve complete ACP subagent answers - #165800

Merged
steipete merged 2 commits into
openclaw:mainfrom
yetval:fix/acp-subagent-final-answer-run-id
Oct 8, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
yetval:fix/acp-subagent-final-answer-run-id

Conversation

@yetval

@yetval yetval commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: successful ACP subagents deliver a truncation notice and only the first 4,096 characters to their parent because their complete transcript answer cannot be found by run ID. The shared CLI fallback writer has the same missing ownership metadata.

Fixes #162777 (the remaining shared CLI fallback writer path). Related: #155119 (answer loss only; duplicate settlement and pending delivery are outside this change). No separate ACP issue was found in the issue search.

User Impact

Parents recover the complete visible answer for the completed ACP or CLI fallback run, including answers longer than 4 KiB and answers followed by another turn in the same child session. No configuration, protocol, schema, or historical-transcript migration changes are required.

Why This Change Was Made

Pass the existing owning run ID from ACP execution and CLI post-run handling through the shared text-turn writer to the canonical transcript persistence owner. The existing exact-run reader then finds the full assistant row; its bounded lifecycle fallback and run-isolation checks remain intact.

Original fix by @yetval; maintainer cleanup simplifies the same writer's usage handling and removes single-use metadata locals. The regression now writes a later answer before recovering the original long answer, so it also protects against delivering another run's result. Documentation names the ACP/CLI guarantee.

Evidence

Maintainer head: 965a7240734a0bfe3374f22291063ef6bcd3a1f7.

Unit, types, static checks, independent review, and exact-head CI passed. Fresh live proof is partial: the real Gateway delivered the full answer to the parent, but the initial fixture compared JSON-escaped context to raw newlines and used capped history. Coordinator timeouts blocked the corrected fixture and fresh main-side Gateway comparison. This PR has not been merged.

Current-main source confirmation: at 278d66f2459a088cd6c770a92fe30a2fa48cc226, the ACP caller and shared writer still omit runId. The completion reader's exact-run lookup therefore misses and falls back to [truncated-by-retention: complete child answer unavailable] plus the terminal snapshot. The shared writer has the same Git blob (98a3ba0c2a680d8b00861aa983cebb100c16764f) at current main and the PR's merge base.

Isolated maintainer proof

AWS lease cbx_b618c3d07a3a (c7a.8xlarge), Node 24.21.0, pnpm 12.5.1. Launched from a clean trusted main worktree with its scripts/crabbox-untrusted-bootstrap.sh, CRABBOX_ENV_ALLOW=CI, --provider aws --fresh-pr openclaw/openclaw#165800 --no-hydrate, and the exact full head SHA. The trusted bootstrap enforced IMDS no-role/404, the package-manager pin, and a fresh temporary HOME. No contributor runtime code executed on the maintainer host.

Unit run: run_058b4a9239883f80a017268114b8ad4c.

Command Result Wall time
pnpm test src/agents/command/transcript-persistence.test.ts --maxWorkers=1 4/4 passed 50.63 s cold
pnpm test src/agents/command src/commands/agent.acp.test.ts src/commands/agent.test.ts --maxWorkers=1 26 files, 472 tests passed 612.86 s
pnpm tsgo:core passed 18.93 s
pnpm tsgo:core:test --changed-paths-json '["src/agents/command/transcript-persistence.test.ts"]' commands graph passed 73.91 s total; graph 16.0 s
Same focused test with only transcript-persistence.ts restored from the merge base both recovery cases failed, original two passed; exit 1 42.51 s

The negative control failed at the real visible-final lookup with Received: undefined. The writer was restored from the candidate afterward and git diff --exit-code passed. Since the reverted writer is byte-identical to current main's writer, this confirms the current-main ownership defect.

ClawSweeper review 6003081889 requested measured wall time and attributable CI seconds. The cold standalone file took 50.63 s, with Vitest reporting 46.83 s and 91% spent transforming modules; its two recovery cases took 190 ms combined. This test needs the actual SQLite transcript writer and finder to protect recovery, rather than merely asserting that a helper receives metadata. The exact-head CI file passed 4/4 with inner parallelism 1, 5.29 s runner wall time, 4.16 s Vitest duration, and 331 ms combined recovery-case time (CLI 280 ms, ACP 51 ms): file-cost log.

Exact-head CI passed, including module tests, production types, core test types, lint, docs, and openclaw/ci-gate. The old head's gate had failed because pr-fail-fast was abandoned; that was not a failure of this test. Targeted local oxfmt, oxlint, and git diff --check passed. Independent Codex autoreview was scoped-clean at P2 and above for the complete committed branch.

Real Gateway observation and remaining gap

Live run: run_57d190c02725de0df158a754efbefb17, on the same fresh secretless candidate-bound lease. The harness used a real child Gateway process, isolated state, an ephemeral port, chat.send, the actual sessions_spawn(runtime: "acp") path, a registered fake external ACP backend, and a loopback OpenAI Responses provider. It emitted three parts totaling 16,881 characters. The normal transcript and completion owners remained real.

Command after preparing the Gateway with pnpm openclaw --help:

ACP_PROOF_EVIDENCE_DIR=/tmp/oc-r6-165800-evidence/live-fixed \
OPENCLAW_E2E_VERBOSE=1 \
node scripts/run-vitest.mjs run \
  --config test/vitest/vitest.e2e.config.ts \
  test/acp-live-proof.e2e.test.ts

The full E2E build completed all 11 stages and built 96 plugins. The Gateway flow reached three provider requests and completed in 23.953 s. Inspection of the captured parent completion request, decoding its existing JSON conversation-data string, showed:

expectedAnswerChars: 16881
expectedAnswerSha256: 8b19a5d8bf74e7aa685264f05be0cbade25add1c843bfb2025a0688eae53ced7
decodedPartsComplete: [true, true, true]
decodedCompleteAnswer: true
retentionNotice: false
providerFailures: []

The first fixture nevertheless exited 1: its mock parent's decision/assertions searched for raw newlines in escaped context, and chat.history used its default display cap. The fixture was corrected to decode that context and request maxChars: 100000; no production change was required. Repeated coordinator GET-lease timeouts prevented the corrected rerun from starting. Therefore the corrected assertion suite, independent uncapped history inspection, and a fresh full-main Gateway comparison remain uncompleted. No external ACP executable or real model provider was tested.

The contributor's earlier in-process Gateway comparison remains separate evidence: on baseline a38b64b2fea, an 11,396-character / 400-line answer delivered only 148 lines and lost its end marker; the original fix delivered all 400 lines and the marker without the retention notice. ClawSweeper accepted that supplied trace. It is not relabeled as a fresh maintainer baseline run.

Change size and disposition

PR numstat against the origin/main merge base a38b64b2fea5b16aa4352147187a8c8ab2e7413a:

File Added Removed
src/agents/command/acp-execution.ts 1 0
src/agents/command/post-run.ts 1 0
src/agents/command/transcript-persistence.ts 6 9
src/agents/command/transcript-persistence.test.ts 56 1
docs/tools/subagents/announce.md 3 1

Production 8 added / 9 removed (net -1); tests 56 / 1 (net +55); docs 3 / 1 (net +2). No changelog edit; this body retains release-note context and human contributor credit. The ClawSweeper cost-reporting finding is addressed; the campaign's remaining fresh-live comparison gap is explicit above. No merge was requested or performed.

ACP-backed subagents (sessions_spawn runtime="acp") delivered only the
4096-character terminal reply head to the parent, prefixed with
[truncated-by-retention: complete child answer unavailable]. The shared
text-turn transcript writer used by ACP turns never attached
__openclaw.runId to the assistant row, so the completion reader's
visible-final lookup by run id could not find the child's answer.

Carry the run id through persistTextTurnTranscript into
persistSessionTranscriptTurn, which already stamps run-owned assistant
rows, and pass it from the ACP execution path and the CLI post-run
transcript mirror. This is the ACP sibling of the claude-cli fix in
openclaw#162843.
@clawsweeper

clawsweeper Bot commented Oct 5, 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 P1 High-priority user-facing bug, regression, or broken workflow. 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 Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 3:25 AM ET / 07:25 UTC (Revision 3).

ClawSweeper review

What this changes

The branch records the owning run ID on ACP and CLI fallback transcript answers so parents can recover the complete answer from the correct child run.

Example: A parent requests a 400-line answer from an ACP child

  • Before: The recorded baseline delivers only 148 lines with a retention notice and loses the final marker.
  • After: The recorded fixed run delivers all 400 lines and the final marker without a retention notice.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with sufficient production-boundary proof, meaningful storage regressions, and the prior review requirement resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Recorded Gateway execution reaches the changed ACP writer, real transcript persistence, exact-run recovery, and the parent's completion request, which contains the full 16,881-character answer without a retention notice. The retained before/after trace corroborates recovery; fixture assertion errors and coordinator-blocked follow-ups are disclosed and do not erase the observed result. Existing optional run metadata is reused without schema changes or historical-row migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A parent receives a shortened child answer even though the complete answer was successfully stored.
Reason: Complete exact-run answers are an established product contract. The narrow producer repair restores that contract for ACP and shared CLI fallback writes.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary and has no identified merge blocker. Current main still contains the answer-recovery defect, the prior timing requirement is resolved, and the recorded production-boundary observations support the repair.

Priority: P1
Reviewed head: 965a7240734a0bfe3374f22291063ef6bcd3a1f7

Before merge

None.

Findings

None.

Agent review details

How this fits together

OpenClaw stores child-agent answers in session transcripts. When a child finishes, its parent retrieves the answer belonging to that exact run, using a bounded snapshot when the complete answer cannot be found.

flowchart TD
 A[ACP or CLI child run] --> B[Complete answer and run identity]
 B --> C[Shared transcript writer]
 C --> D[Session transcript]
 D --> E[Exact-run answer lookup]
 E --> F[Complete answer to parent]
 E --> G[Bounded fallback when unavailable]
Loading

Technical review

Best possible solution:

Supply the owning run ID through the existing transcript writer while preserving exact-run selection, visibility, and retention behavior.

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

Yes: current-main source proves the missing run stamp conflicts with exact-run selection, and the supplied negative control and Gateway comparison corroborate it. This read-only review did not execute a reproduction.

Is this the best way to solve the issue?

Yes: repairing the producer uses the existing storage contract and avoids broadening matching rules or adding a second recovery mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

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

Security

None.

Evidence

What I checked:

  • Verified introduced repair: The pinned introduction delta forwards the existing run ID from both command callers through the shared transcript writer. The usage cleanup preserves the previous cases; diagnostics changes are base drift. (src/agents/command/transcript-persistence.ts:216, 965a7240734a)
  • Current main still needs this repair: The merge-base and fetched-main shared writer have the identical blob 98a3ba0c2a680d8b00861aa983cebb100c16764f, which omits runId from transcript persistence. The inspected v2026.9.8 writer also retains the omission. (src/agents/command/transcript-persistence.ts:213, 017842386a7f)
  • Existing storage and selection contracts: Canonical persistence already stamps assistant rows with options.runId in both append paths. Exact-run selection requires that metadata, while completion recovery retains its owner checks and bounded fallback. This adds existing optional metadata to new writes without DDL, historical rewrites, or a migration. (src/config/sessions/session-accessor.transcript-turn.ts:340, 965a7240734a)
  • Recorded Gateway observation: The captured PR body, sourceRevision d9f8200ef6879609ad7d32149fa656d49874134cc3ff1a5b3ecdc75a61dc394a, reports exact-head run_57d190c02725de0df158a754efbefb17 through chat.send, sessions_spawn(runtime: acp), a real Gateway process, and the normal transcript/completion owners. The decoded parent request contained the complete 16,881-character answer, all three parts, no retention notice, and no provider failures. The synthetic external backend/provider did not bypass the changed persistence boundary. The fixture exited 1 because of escaped-newline comparisons and capped history; the corrected rerun and fresh main Gateway comparison were blocked by coordinator timeouts. Those gaps do not negate the observed complete parent input. This reviewer did not execute the run. (965a7240734a)
  • Retained before-and-after proof: The body preserves the previously accepted Gateway comparison: the same 11,396-character answer yielded 148/400 lines on the baseline and 400/400 with the final marker after the original fix. The prior review confirms the exercised storage and parent-completion path. Downloaded screenshots were inspected, but belong to earlier related PRs and are not counted as proof of this patch. (4655d9fd88f6)
  • Meaningful regression and resolved timing request: Both runtime cases write the long answer and a different later answer, then recover the original text through the real SQLite exact-run finder. The body records 4/4 passing tests, both recovery cases failing when the writer is restored to baseline, 50.63 seconds cold standalone wall time, and 5.29 seconds CI runner wall time with 331 ms combined recovery time. It explains the cold import cost and why actual storage is required. This resolves the previous review's only required next step. (src/agents/command/transcript-persistence.test.ts:63, 965a7240734a)

Likely related people:

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

PR surface

Source -1, Tests +55, Docs +2. Total +56 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 8 9 -1
Tests 1 56 1 +55
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 67 11 +56

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Successful delegated runs can lose most of their answer during the parent handoff, breaking an established agent workflow.
  • 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.
  • 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 (2 earlier review cycles)
  • reviewed 2026-10-05T21:15:15.621Z sha 4655d9f :: needs changes before merge. :: none
  • reviewed 2026-10-08T06:26:03.489Z sha 965a724 :: needs changes before merge. :: none

Preserve the original run-owned ACP and CLI transcript fix, exercise recovery after a later turn, and simplify the shared writer without changing usage semantics.

Co-authored-by: yetval <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 8, 2026
@steipete
steipete merged commit a9ff654 into openclaw:main Oct 8, 2026
148 of 149 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
* fix(agents): preserve complete ACP subagent answers

ACP-backed subagents (sessions_spawn runtime="acp") delivered only the
4096-character terminal reply head to the parent, prefixed with
[truncated-by-retention: complete child answer unavailable]. The shared
text-turn transcript writer used by ACP turns never attached
__openclaw.runId to the assistant row, so the completion reader's
visible-final lookup by run id could not find the child's answer.

Carry the run id through persistTextTurnTranscript into
persistSessionTranscriptTurn, which already stamps run-owned assistant
rows, and pass it from the ACP execution path and the CLI post-run
transcript mirror. This is the ACP sibling of the claude-cli fix in
openclaw#162843.

* fix(agents): harden complete ACP answer recovery proof

Preserve the original run-owned ACP and CLI transcript fix, exercise recovery after a later turn, and simplify the shared writer without changing usage semantics.

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

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: yetval <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 11, 2026
* fix(agents): preserve complete ACP subagent answers

ACP-backed subagents (sessions_spawn runtime="acp") delivered only the
4096-character terminal reply head to the parent, prefixed with
[truncated-by-retention: complete child answer unavailable]. The shared
text-turn transcript writer used by ACP turns never attached
__openclaw.runId to the assistant row, so the completion reader's
visible-final lookup by run id could not find the child's answer.

Carry the run id through persistTextTurnTranscript into
persistSessionTranscriptTurn, which already stamps run-owned assistant
rows, and pass it from the ACP execution path and the CLI post-run
transcript mirror. This is the ACP sibling of the claude-cli fix in
#162843.

* fix(agents): harden complete ACP answer recovery proof

Preserve the original run-owned ACP and CLI transcript fix, exercise recovery after a later turn, and simplify the shared writer without changing usage semantics.

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

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: yetval <[email protected]>
(cherry picked from commit a9ff654)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
* fix(agents): preserve complete ACP subagent answers

ACP-backed subagents (sessions_spawn runtime="acp") delivered only the
4096-character terminal reply head to the parent, prefixed with
[truncated-by-retention: complete child answer unavailable]. The shared
text-turn transcript writer used by ACP turns never attached
__openclaw.runId to the assistant row, so the completion reader's
visible-final lookup by run id could not find the child's answer.

Carry the run id through persistTextTurnTranscript into
persistSessionTranscriptTurn, which already stamps run-owned assistant
rows, and pass it from the ACP execution path and the CLI post-run
transcript mirror. This is the ACP sibling of the claude-cli fix in

* fix(agents): harden complete ACP answer recovery proof

Preserve the original run-owned ACP and CLI transcript fix, exercise recovery after a later turn, and simplify the shared writer without changing usage semantics.

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

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: yetval <[email protected]>
(cherry picked from commit a9ff654)
(cherry picked from commit c0c7b56)

Co-authored-by: RomneyDa <[email protected]>
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: 🐚 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]: claude-cli runtime: subagent final answer always lost (terminal transcript row lacks __openclaw.runId)

2 participants