Skip to content

fix: Claude CLI forgets announced sub-agent results on the next turn - #164175

Merged
steipete merged 9 commits into
openclaw:mainfrom
etzelm:fix/cli-announce-continuity
Oct 13, 2026
Merged

steipete merged 9 commits into
openclaw:mainfrom
etzelm:fix/cli-announce-continuity

Conversation

@etzelm

@etzelm etzelm commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #171195

Related: #159512 (completion-session isolation), #154716 (native-login history ownership).

What Problem This Solves

A Claude CLI requester can announce a completed sub-agent's result, then resume an older native session on the next user turn and claim that the child has not reported back.

User Impact

The next resumed turn receives recorded completion exchanges when its existing history account boundary permits replay. When content is withheld, the turn receives a metadata-only gap notice that includes those completions. Tool restrictions and account boundaries stay in place.

Why This Change Was Made

The CLI history owner reads pending completion exchanges from the canonical transcript, distinguishing ordinary replies, state-preserving handoffs, and background refreshes. An ordinary reply consumes the carry. The newest eight exchanges use the existing context JSON sanitizer and its 2,000-character string limit. The renderer requires the existing history writer; the existing transport revalidates that authority immediately before disclosure. No parallel store, schema change, or new configuration is introduced.

The wording covers both isolated and already-resumed completion turns, and tells the model to verify current facts before acting on historical records. The original user prompt remains the stored transcript input, and native-history import strips the marked context.

Original fix by @etzelm; maintainer cleanup consolidates rendering in the transcript owner, removes duplicate sanitization and exports, and replaces the large subprocess/live-probe additions with focused owner regressions.

Evidence

PR CI is the test gate under the maintainer's October 13, 2026 proof policy. Local tests, typechecks, negative controls, live Gateway proofs, Crabbox, and Testbox were intentionally skipped. No contributor runtime code executed on the host.

Regression coverage for CI:

  • preserved Claude turns > carries completion exchanges since the last ordinary reply, or counts them when content is withheld: real transcript writes/readback, reply-only announcements, queued provenance, background refreshes, fresh-session exclusion, one-turn consumption, bounded carry and sanitization.
  • CLI resume user context: drift ordering, fresh-session exclusion, and withholding without the history writer.
  • imported Claude history merge > shows a resumed turn carrying unseen exchanges once: marked completion context imports without a duplicate user turn, with and without drift.
  • Existing session-history and routed-prompt tests cover stripping the metadata-only note.

Changed-file oxlint and oxfmt pass. The parent install lacks the unrelated Solid lint plugin, so local lint used the repository's core rules with only the ui/**/*.tsx override omitted; no changed file matches that override. Deslop removed redundant production helpers and duplicate proof scaffolding. Independent Codex autoreview: scoped-clean through P2; no actionable findings. The reviewed production patch is unchanged by the main merge; its only conflict retained main's reduced routed-prompt test matrix and added the new completion-gap case. Exact-head CI run 38468757728 passed on 70b6de0a26bd9ff568cd7700e42748a98bcc3358: changed Node/Bun test lanes, production types, all core test-type shards, lint, docs, source/architecture guards, and openclaw/ci-gate. No failed checks or inherited-failure exceptions. The only merge conflict was the routed-prompt test matrix; main's reduction was retained with one new completion-gap case.

Source/history confirmation: main's renderClaudeSessionGap chooses the latest claude-cli assistant row without distinguishing announce: replies; subagent_announce preserves the requester binding. That combination both loses the carried result and hides the metadata gap. The original gap change is #168726. Collision checks found only this PR for #171195.

ClawSweeper's exact-head review (October 13, 21:21 UTC) reports no code findings and explicitly identifies no concrete account-boundary bypass. The topology-wording finding is resolved; the older live-probe matcher finding is superseded by removal of that optional probe. Its remaining security/merge-risk attention is an evidence request for live completion/resume and final-input authority-denial traces. Per the maintainer's explicit proof policy for this task, PR CI is the proof; those proof-only requests do not add live, negative-control, or local test requirements. Existing writer/account assertions remain intact. Earlier persisted-binding concerns are superseded by the transcript-only design. There were no human review comments.

Diff against merged main: production +136/-19 (net +117), tests +253/-6 (net +247), docs +18/-1 (net +17); 11 files, +407/-26 overall. No new timers, sleeps, subprocesses, or Gateway boots; local test wall time is intentionally unmeasured. CI recorded the transcript regression at 1,297 ms (one test; 14.32 s Vitest / 16.49 s shard wall including imports), the three new renderer cases at 2 ms each (the existing file's full run: eight tests, 43.38 s Vitest / 45.27 s shard wall, dominated by pre-existing runtime imports), and the two import cases at 32 ms and 10 ms. No additional subprocess harness is needed for these owner contracts. Production growth is necessary to classify the previously unrepresented completion boundary and render its bounded context; unrelated deletions were not used to meet a negative-LOC target.

@clawsweeper

clawsweeper Bot commented Oct 3, 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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 3, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR carries recorded completion exchanges into authorized Claude CLI resumes and reports a metadata-only gap when replay is withheld.

Example: A child reports that 17 × 23 equals 391, then the requester resumes its earlier Claude session.

  • Before: The requester says the child has not reported back.
  • After: An authorized resume receives the recorded result; an unverifiable account receives a notice without its contents.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The repair is useful and source-coherent, but supplied evidence does not establish the changed runtime behavior or final-effect account denial.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Claude says a completed child has not reported back even though its result appeared in the conversation.
Reason: The report establishes an official-release failure, and the focused repair retains the existing owners and security contract without new configuration.

Merge readiness

⛔ Blocked before merge - 3 items remain

This PR addresses a documented current bug with a focused transcript-owned repair; no introduced correctness defect was identified.

Priority: P1
Reviewed head: 70b6de0a26bd9ff568cd7700e42748a98bcc3358

Before merge

  • Add real behavior proof - Authority-chain proof required: show the revised transcript owner carrying a recorded result such as 391 through the shipped Claude CLI resume, withholding content for an opaque login, and rejecting reassigned or revoked history authority before final input disclosure. The current body supplies CI regressions and explicitly skips runtime verification; the inspected screenshots show unrelated export fixtures, and earlier review summaries do not provide inspectable traces for this revision. Supply redacted terminal output or logs, removing IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security review attention item - Existing account and live-writer checks remain authoritative, with no concrete bypass identified.
  • Resolve merge risk - Account isolation for the newly carried completion payload remains unproven at the final Claude input boundary.

Findings

None.

Tests

  • Missing end-to-end proof: No inspectable after-fix shipped CLI completion/resume trace or final-input authority-denial trace covers the revised owner; the added regressions were not run against base and head in this review.
Agent review details

How this fits together

The CLI history owner reads canonical conversation rows, prepares bounded context, and passes it through the account-authorized execution transport to Claude.

flowchart LR
  A[Child completion] --> B[Canonical transcript]
  B --> C[CLI history owner]
  D[History account authority] --> C
  C --> E[Resume prompt renderer]
  E --> F[Execution authority check]
  F --> G[Claude CLI session]
Loading

Technical review

Best possible solution:

Keep bounded completion recovery in the canonical transcript owner, preserving native continuity and the existing account boundary.

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

Current-main source matches the linked official-release trace: the announcement preserves the old binding while its assistant row suppresses the gap notice; no target code was executed during this review.

Is this the best way to solve the issue?

The transcript-derived repair avoids competing persistence and preserves account authorization, bounded context, original user text, and native-session continuity.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Provide final-input authority evidence (recommended)
    Show an authorized carried-result input and rejection before Claude receives that payload after account reassignment or history-writer revocation.
  2. Hold the PR pending evidence
    Keep this useful repair open without merging until the disclosure scenarios are demonstrated.

Provenance checked

Testing

Proof path: in-process harness.

Security

Needs attention: Existing account and live-writer checks remain authoritative, with no concrete bypass identified.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 93964e5 adds src/agents/cli-runner/session-history.ts:543 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 93964e5bd082; files: src/agents/cli-runner/session-history.ts)
  • Vito Cappello: Raw commit e20b56c adds src/agents/cli-runner/session-history.ts:413 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e20b56c0b26e; files: src/agents/cli-runner/session-history.ts)
  • Peter Steinberger: Raw commit 3de654b adds src/agents/cli-runner/session-history.ts:303 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3de654bfc844; files: src/agents/cli-runner/session-history.ts)

PR surface

Source +117, Tests +247, Docs +17. Total +381 across 11 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 4 136 19 +117
Tests 5 253 6 +247
Docs 2 18 1 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 407 26 +381

Review metrics

Metric Value Why it matters
Production versus test growth Production +136/-19; tests +253/-6. Production growth classifies completion boundaries and renders bounded historical context; tests cover transcript readback, renderer admission, and import correlation.

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: The patch newly discloses saved completion text to a resumed backend; existing guards remain, but final-effect denial evidence is unavailable.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P1: Official-release traces show delivered child results disappearing from the next requester turn and producing incorrect task status.
  • merge-risk: 🚨 security-boundary: The patch newly discloses saved completion text to a resumed backend; existing guards remain, but final-effect denial evidence is unavailable.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide a shipped CLI trace showing the recorded child result reaching the next resumed turn.
  • Provide final-input denial evidence for an opaque account and for reassigned or revoked history authority.

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 (14 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-11T23:17:32.968Z sha ad81e2b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T07:51:23.363Z sha 3e59e25 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T08:21:46.341Z sha 3e59e25 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T08:35:03.842Z sha 3e59e25 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T09:13:06.007Z sha 3e59e25 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T12:52:59.763Z sha f5f06bc :: needs changes before merge. :: [P2] Recognize reply-only completion records in the live probe
  • reviewed 2026-10-13T15:49:14.237Z sha fb9f374 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-13T17:15:34.266Z sha fb9f374 :: needs changes before merge. :: [P3] [P3] Use topology-neutral wording for completion context

Reviewed October 13, 2026, 5:21 PM ET / 21:21 UTC (Revision 15).

@etzelm
etzelm marked this pull request as ready for review October 3, 2026 08:35
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Oct 3, 2026
@etzelm
etzelm marked this pull request as draft October 3, 2026 15:00
@etzelm
etzelm force-pushed the fix/cli-announce-continuity branch from 265e715 to 1c8fad9 Compare October 3, 2026 15:00
@etzelm
etzelm marked this pull request as ready for review October 3, 2026 15:11
@etzelm

etzelm commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Note for the maintainer: the one open item here is the storage review checkpoint in docs/reference/database-schemas/storage-changes.md, not a code finding. ClawSweeper reports no actionable defects and proof as sufficient.

What triggers the checkpoint: one optional persisted field, unseenTurns, on the stored native CLI binding (src/config/sessions/types.ts). It touches retention and downgrade behavior, so it needs a maintainer to accept it before merge.

The contract to accept, as a whole:

  • one optional field on the stored binding, no schema version bump
  • newest 8 pending exchanges, each prompt and reply capped at 2,000 characters (the cap other context blocks already use)
  • older or longer content stays in the OpenClaw transcript and reaches a fresh Claude session through the existing history reseed; a continuously resumed session sees only the bounded copy
  • an older build opens the state and drops pending exchanges on its next binding write, with no migration (evidence 3)

Alternatives that avoid new persistence, and why this PR does not use them:

  • Derive the unseen turns from the transcript at resume. This could work, but it depends on how transcript coverage advances for off-binding turns, and reinterpreting that existing field would also be a material change.
  • Hold the exchanges in memory only. This adds no stored data, but the bug still reproduces across a Gateway restart.
  • Clear the binding after an off-binding preserved turn so the next turn reseeds from history. This uses an existing path, but it gives up native session continuity and prompt-prefix reuse after every announcement.

What would help: either record acceptance of the contract above, or say which part to change (a smaller bound, prompt-only carry, or one of the alternatives). The carried context has one owner (settlePreservedCliSessionTurn with prependCliSessionResumeUserContext), so a different bound or shape is a local change.

- A preserved inter-session turn that runs outside the bound native CLI
  session reports its prompt and reply; the binding owner stores them on
  that binding, bounded like other context blocks, only when the auth
  identity matches.
- The next turn that resumes the bound session prepends them once as a
  marked context block; any completed turn in that session consumes them,
  and a fresh session recovers them from saved history instead.
- The completion turn's tool projection, MCP configuration, and loopback
  grant are unchanged.
- A real-seam regression covers continuity and denial; store guard,
  resume-context order, and chat-history dedupe tests cover the new
  binding field.
- The Claude CLI Gateway live announce probe now sends one more requester
  turn and checks Claude's transcript for the session it resumed.
- CLI backend and sub-agent tool policy docs describe the contract.
@etzelm
etzelm force-pushed the fix/cli-announce-continuity branch from 2cef489 to ad81e2b Compare October 11, 2026 23:05
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 11, 2026
@clawsweeper clawsweeper Bot removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 13, 2026
…ce probe

The live CLI-backend announce probe searched the resumed Claude session's
user turns for the inter-session prompt envelope. A completion saved without
a user row renders a reply-only record, so the authorized branch failed even
when the resumed session received the result; when the handoff resumed the
bound session instead, the probe matched the handoff prompt itself.

Parse the marked context blocks of the follow-up turn and match the record's
source and reply. Whether the handoff resumed the bound session (prompt drift
only) or ran in its own session (an MCP hash change) is recorded, not
asserted: the follow-up turn owes the record either way.
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 13, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 13, 2026
etzelm and others added 3 commits October 13, 2026 13:55
A completion handoff resumes the requester's bound Claude session when only
prompt content drifted, and runs in its own session when its MCP projection
hashes differently. The transcript does not record which one happened, yet
the carried-completion label told Claude the events arrived in a separate
session, and the session-gap note for a withheld login said they occurred
outside this session. Both were wrong in the resumed case.

Say what is known: the completion events were recorded in the conversation
since the session's last reply here, and the session may already hold some
of them. The gap note counts preserved turns with the same wording, and the
prompt-text stripper recognizes it like the existing notes. The account gate
and the bounded carry are unchanged.
Keep completion recovery in the canonical transcript owner, reuse bounded context rendering, and preserve account-authorized replay. Retain focused history, renderer, and import regressions; remove duplicate live proof scaffolding. Mark historical facts and preserve original user transcript text.

Co-authored-by: Mitchell Etzel <[email protected]>
# Conflicts:
#	src/gateway/cli-session-history.routed-prompts.test.ts
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 13, 2026
@steipete
steipete merged commit d472fc5 into openclaw:main Oct 13, 2026
149 of 152 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@etzelm

etzelm commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @steipete!

@etzelm
etzelm deleted the fix/cli-announce-continuity branch October 13, 2026 22:27
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…penclaw#164175)

* fix(agents): carry isolated CLI completion turns into the next resume

- A preserved inter-session turn that runs outside the bound native CLI
  session reports its prompt and reply; the binding owner stores them on
  that binding, bounded like other context blocks, only when the auth
  identity matches.
- The next turn that resumes the bound session prepends them once as a
  marked context block; any completed turn in that session consumes them,
  and a fresh session recovers them from saved history instead.
- The completion turn's tool projection, MCP configuration, and loopback
  grant are unchanged.
- A real-seam regression covers continuity and denial; store guard,
  resume-context order, and chat-history dedupe tests cover the new
  binding field.
- The Claude CLI Gateway live announce probe now sends one more requester
  turn and checks Claude's transcript for the session it resumed.
- CLI backend and sub-agent tool policy docs describe the contract.

* fix(agents): replay carried CLI exchanges only under the history account boundary

- The resume renderer prepends pending completion exchanges only when the turn holds the CLI history writer, the authority that already gates saved-history recovery
- Settlement keeps no exchange for a binding without an auth epoch (opaque native login)
- Regression covers a named account (carried once), an opaque native login (nothing kept) and an identity-less login whose token is replaced (withheld and dropped)
- The live continuity probe expects the exchange only when the requester's history boundary is known
- Docs state the account requirement

* fix(agents): carry completion replies from the canonical transcript

- Drop the persisted unseenTurns binding field, its settlement
  (settlePreservedCliSessionTurn) and the cliUnseenTurn run meta; the
  native binding contract is back to main's
- Derive the carried context at resume time from the requester transcript:
  completion replies saved after the bound session's last ordinary Claude
  reply, recognized by their announce run id (announce:) or by a saved user
  row with completion provenance, newest 8, each bounded like context JSON
- Replay still requires the turn's CLI history writer; without it the
  session-gap note now counts those completion turns instead of treating
  the completion reply as the last turn the session saw
- Add isAnnounceIdempotencyKey next to buildAnnounceIdempotencyKey
- Regression harness mirrors the Gateway: completions run under the
  announce key and save no user row; credential replacement covers a named
  account as well as an identity-less login
- Move the transcript-derivation unit test to
  session-history.preserved-turns.test.ts (line cap)

* fix(agents): name carried completion turns as delivered events

- Label the carried block as completion events delivered in a separate
  session, each with the reply sent then, and give each record its
  source tool; with only a bare reply, installed Claude answered the
  next message as if no completion had arrived
- Read the transcript run id with asOptionalRecord
- Keep the preserved-turn check inside session-history; input-provenance
  is unchanged
- Publish the runtime config snapshot in the regression harness, as the
  sibling attempt tests do since openclaw#169714
- Pin the newest-8 bound in the preserved-turns test

* test(gateway): match the carried completion record in the live announce probe

The live CLI-backend announce probe searched the resumed Claude session's
user turns for the inter-session prompt envelope. A completion saved without
a user row renders a reply-only record, so the authorized branch failed even
when the resumed session received the result; when the handoff resumed the
bound session instead, the probe matched the handoff prompt itself.

Parse the marked context blocks of the follow-up turn and match the record's
source and reply. Whether the handoff resumed the bound session (prompt drift
only) or ran in its own session (an MCP hash change) is recorded, not
asserted: the follow-up turn owes the record either way.

* fix(agents): describe carried completions without naming where they ran

A completion handoff resumes the requester's bound Claude session when only
prompt content drifted, and runs in its own session when its MCP projection
hashes differently. The transcript does not record which one happened, yet
the carried-completion label told Claude the events arrived in a separate
session, and the session-gap note for a withheld login said they occurred
outside this session. Both were wrong in the resumed case.

Say what is known: the completion events were recorded in the conversation
since the session's last reply here, and the session may already hold some
of them. The gap note counts preserved turns with the same wording, and the
prompt-text stripper recognizes it like the existing notes. The account gate
and the bounded carry are unchanged.

* fix(agents): simplify resumed Claude completion context

Keep completion recovery in the canonical transcript owner, reuse bounded context rendering, and preserve account-authorized replay. Retain focused history, renderer, and import regressions; remove duplicate live proof scaffolding. Mark historical facts and preserve original user transcript text.

Co-authored-by: Mitchell Etzel <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Mitchell Etzel <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 14, 2026
…164175)

* fix(agents): carry isolated CLI completion turns into the next resume

- A preserved inter-session turn that runs outside the bound native CLI
  session reports its prompt and reply; the binding owner stores them on
  that binding, bounded like other context blocks, only when the auth
  identity matches.
- The next turn that resumes the bound session prepends them once as a
  marked context block; any completed turn in that session consumes them,
  and a fresh session recovers them from saved history instead.
- The completion turn's tool projection, MCP configuration, and loopback
  grant are unchanged.
- A real-seam regression covers continuity and denial; store guard,
  resume-context order, and chat-history dedupe tests cover the new
  binding field.
- The Claude CLI Gateway live announce probe now sends one more requester
  turn and checks Claude's transcript for the session it resumed.
- CLI backend and sub-agent tool policy docs describe the contract.

* fix(agents): replay carried CLI exchanges only under the history account boundary

- The resume renderer prepends pending completion exchanges only when the turn holds the CLI history writer, the authority that already gates saved-history recovery
- Settlement keeps no exchange for a binding without an auth epoch (opaque native login)
- Regression covers a named account (carried once), an opaque native login (nothing kept) and an identity-less login whose token is replaced (withheld and dropped)
- The live continuity probe expects the exchange only when the requester's history boundary is known
- Docs state the account requirement

* fix(agents): carry completion replies from the canonical transcript

- Drop the persisted unseenTurns binding field, its settlement
  (settlePreservedCliSessionTurn) and the cliUnseenTurn run meta; the
  native binding contract is back to main's
- Derive the carried context at resume time from the requester transcript:
  completion replies saved after the bound session's last ordinary Claude
  reply, recognized by their announce run id (announce:) or by a saved user
  row with completion provenance, newest 8, each bounded like context JSON
- Replay still requires the turn's CLI history writer; without it the
  session-gap note now counts those completion turns instead of treating
  the completion reply as the last turn the session saw
- Add isAnnounceIdempotencyKey next to buildAnnounceIdempotencyKey
- Regression harness mirrors the Gateway: completions run under the
  announce key and save no user row; credential replacement covers a named
  account as well as an identity-less login
- Move the transcript-derivation unit test to
  session-history.preserved-turns.test.ts (line cap)

* fix(agents): name carried completion turns as delivered events

- Label the carried block as completion events delivered in a separate
  session, each with the reply sent then, and give each record its
  source tool; with only a bare reply, installed Claude answered the
  next message as if no completion had arrived
- Read the transcript run id with asOptionalRecord
- Keep the preserved-turn check inside session-history; input-provenance
  is unchanged
- Publish the runtime config snapshot in the regression harness, as the
  sibling attempt tests do since #169714
- Pin the newest-8 bound in the preserved-turns test

* test(gateway): match the carried completion record in the live announce probe

The live CLI-backend announce probe searched the resumed Claude session's
user turns for the inter-session prompt envelope. A completion saved without
a user row renders a reply-only record, so the authorized branch failed even
when the resumed session received the result; when the handoff resumed the
bound session instead, the probe matched the handoff prompt itself.

Parse the marked context blocks of the follow-up turn and match the record's
source and reply. Whether the handoff resumed the bound session (prompt drift
only) or ran in its own session (an MCP hash change) is recorded, not
asserted: the follow-up turn owes the record either way.

* fix(agents): describe carried completions without naming where they ran

A completion handoff resumes the requester's bound Claude session when only
prompt content drifted, and runs in its own session when its MCP projection
hashes differently. The transcript does not record which one happened, yet
the carried-completion label told Claude the events arrived in a separate
session, and the session-gap note for a withheld login said they occurred
outside this session. Both were wrong in the resumed case.

Say what is known: the completion events were recorded in the conversation
since the session's last reply here, and the session may already hold some
of them. The gap note counts preserved turns with the same wording, and the
prompt-text stripper recognizes it like the existing notes. The account gate
and the bounded carry are unchanged.

* fix(agents): simplify resumed Claude completion context

Keep completion recovery in the canonical transcript owner, reuse bounded context rendering, and preserve account-authorized replay. Retain focused history, renderer, and import regressions; remove duplicate live proof scaffolding. Mark historical facts and preserve original user transcript text.

Co-authored-by: Mitchell Etzel <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Mitchell Etzel <[email protected]>
(cherry picked from commit d472fc5)

Backport note: semantic port onto 2026.10.5. The release line lacks the
Claude session-gap note (#168726/#168781), createCliCurrentPromptRenderer and
cli-session-history.prompt-text.ts, so this keeps only the completion carry:
session-history classifies Claude replies from the canonical transcript and
renders the newest 8 preserved/announce exchanges since the last ordinary reply
for a resumed claude-cli native session; prepare.ts prepends them (after any
drift note) only when the turn holds the CLI history writer, via the renamed
prependCliSessionResumeUserContext. Auth-boundary reasons already return before
the transcript read, so withheld turns carry nothing. Gap-note wording, its
stripper regex and their routed-prompt/dedupe test cases are dropped; docs say
withheld content is not replayed. Renderer tests target the release helper;
the preserved-turns test drops gap-note and admission assertions.
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 gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

2 participants