Skip to content

fix(agents): inter-session turns rewrite the provider prompt prefix on the next turn - #169238

Merged
RomneyDa merged 1 commit into
mainfrom
fix/inter-session-first-send-bytes
Oct 11, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/inter-session-first-send-bytes

Conversation

@RomneyDa

Copy link
Copy Markdown
Member

Related: #169130, #167938

What Problem This Solves

Fixes: after a private subagent completion or another inter-session turn, the next model request rewrites that turn's prompt bytes. This breaks provider prompt-cache prefix reuse. Main has failed src/gateway/gateway.prompt-cache.test.ts since #169130.

User Impact

User impact: inter-session turns, such as subagent completions and sessions_send follow-ups, keep a stable provider prefix across later turns and Gateway restarts. The [Inter-session message] … sourceSession=… safety envelope is visible from the first request on, not only in replay. No config or migration change.

Why This Change Was Made

#169130 restored the provenance envelope in replayed history by keeping the turn's body-only model prompt request-local. That made the first request (routed body) differ from every replay (stored envelope), so the next turn rewrote the prefix. Its request-local capture also needed a live, persisted recorder, and could reject a dispatch with "Model prompt projection requires a live, persisted user turn".

Now, when the model prompt would drop the stored inter-session envelope, the boundary sends the stored, annotated text from the first request on. First send equals replay, the safety text stays visible after its transient runtime-context carrier is gone, and nothing is captured or persisted for these turns. This removes the recorder's requestLocal option that #169130 added.

Tradeoff: for these inter-session turns, any modelPrompt enrichment that does not contain the stored text is not sent. The routed body is already inside the stored text, and hook additions that wrap the stored text still freeze as before. This matches the 2026.10.2 release-line fix (d0a753ef48ae).

Production LOC: +23/-26 (net -3).

Evidence

  • node scripts/run-vitest.mjs src/gateway/gateway.prompt-cache.test.ts. On origin/main 72f03a4 it fails with turn 5: prefix changed segment=history[9] path=$.content[0].text. With this change it passes.
  • The replays an inter-session turn with its stored provenance envelope cases (plain, forwarded-envelope, redacted-hook) now assert three things: the first request's user message carries sourceSession=, the replayed user message is byte-identical to it, and no unredacted hook text reaches the provider. All three cases fail on origin/main and pass here.
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt.llm-boundary src/agents/embedded-agent-runner/run/attempt-prompt-submit src/sessions/user-turn-transcript: all pass.
  • node scripts/check-changed.mjs --staged: format, core typecheck, and guards pass. typecheck core tests fails only in ui/src/components/session-background.browser.test.tsx(42,5) (configObject is not in ProfilePreferencesReadOptions), which this PR does not touch. Autoreview is clean.

#169130 kept an inter-session turn's body-only model prompt request-local
so history replays the stored "[Inter-session message] ..." envelope. The
turn's first request (routed body) and every later replay (stored
envelope) then differ, so a private subagent completion rewrites the
provider prefix on the next turn (gateway.prompt-cache "preserves the
provider prefix across chat.send, completion and Gateway restart", turn 5
history[9]). Its request-local capture could also reject a dispatch with
"Model prompt projection requires a live, persisted user turn".

When the prompt would drop the stored envelope, send the stored annotated
text from the first request on: first send and replay agree, the
source-provenance safety text stays visible after its transient carrier
is gone, and nothing is captured or persisted for these turns. This
removes the recorder's requestLocal option added by #169130.
@clawsweeper

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

@RomneyDa
RomneyDa marked this pull request as ready for review October 11, 2026 17:28
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 11, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR sends stored inter-session provenance text on the first model request so subsequent replay preserves the same bytes.

Example: agent:main:parent sends “Continue the delegated task.” through sessions_send.

  • Before: The first request sends the body; replay adds sourceSession=agent:main:parent, changing the earlier prompt prefix.
  • After: The first request and replay both send the stored provenance envelope and task body.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and appears correct, with useful boundary regressions and a verified no-migration case; behavioral evidence remains in-process.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; reported evidence exercises Gateway restart and provider serialization in process, with no shipped-entry-point run claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Subagent completion and sessions_send turns change earlier model input on replay, wasting provider prompt-cache reuse.
Reason: The maintainer-authored change repairs an evidenced current-main mismatch with less production code and explicitly records its enrichment tradeoff.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a current prompt-prefix regression through the existing projection owner, and no introduced defect was found.

Priority: P2
Reviewed head: 38186f580b73f4ffd2204684b15525587a585c20

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped CLI/Gateway execution for this head is supplied; reported validation uses in-process Gateway and provider fixtures.
Agent review details

How this fits together

The embedded runner combines prepared prompts with canonical transcript messages, then projects them into provider requests while the transcript recorder owns durable enrichment and redaction.

flowchart LR
A[Inter-session input] --> B[Canonical transcript]
B --> C[Prompt projection boundary]
D[Prepared enrichment] --> C
C --> E[Provider request]
B --> F[History replay]
F --> C
Loading

Technical review

Best possible solution:

Use the existing projection boundary to preserve inter-session provenance from first dispatch onward while respecting previously frozen projections.

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

Current-main source shows arrival replacement text differing from stored replay text, and the body reports a failing Gateway serialized-prefix regression that passes with this repair; this read-only review executed no tests.

Is this the best way to solve the issue?

The focused repair restores first-send/replay equality and provenance through the existing owner; its loss of envelope-excluding enrichment is explicitly accepted, while frozen projections and normal durable enrichment remain intact.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Inter-session first-dispatch and replay text changes intended behavior with a stated reason (022959b: Keep provenance visible in replay while sending a redacted request-local body on arrival, explicitly accepting a subsequent prefix-cache miss.)
  • Durable projection capture and immutable replay keeps the original intent (6461c18: Freeze enriched model-facing text before dispatch and replay it without changing displayed transcript content.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 6461c18 adds src/agents/embedded-agent-runner/run/attempt-llm-boundary.ts:452 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6461c186e518; files: src/agents/embedded-agent-runner/run/attempt-llm-boundary.ts)

PR surface

Source -3, Tests +6. Total +3 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 23 26 -3
Tests 1 11 5 +6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 34 31 +3

Review metrics

Metric Value Why it matters
Production versus test growth Production +23/-26; tests +11/-5 The repair removes the temporary capture path and strengthens existing prompt-byte assertions without adding another persistence owner.

Root-cause cluster

Relationship: same_root_cause
Canonical: #164515
Summary: Active and replayed inter-session user text differ; the parallel PR also covers preprocessed bodies and hook preservation.

Members:

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

Labels

Label changes:

  • add P2: Inter-session replay changes provider prompt prefixes, reducing cache reuse without an established outage or message-delivery failure.
  • add merge-risk: 🚨 compatibility: Inter-session modelPrompt enrichment excluding stored text is omitted; the maintainer-authored PR explicitly accepts this behavior change.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Inter-session replay changes provider prompt prefixes, reducing cache reuse without an established outage or message-delivery failure.
  • merge-risk: 🚨 compatibility: Inter-session modelPrompt enrichment excluding stored text is omitted; the maintainer-authored PR explicitly accepts this behavior change.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

Reviewed October 11, 2026, 1:33 PM ET / 17:33 UTC.

@RomneyDa
RomneyDa merged commit 0b9d049 into main Oct 11, 2026
192 of 200 checks passed
@RomneyDa
RomneyDa deleted the fix/inter-session-first-send-bytes branch October 11, 2026 17:41
@RomneyDa

Copy link
Copy Markdown
Member Author

Merged via squash.

RomneyDa added a commit that referenced this pull request Oct 11, 2026
#169130 kept an inter-session replacement request-local so history replays
the stored "[Inter-session message] ..." envelope. That makes the turn's
first request (routed body only) and every later replay (stored envelope)
differ, so a private subagent completion rewrites the provider prefix on
the next turn (gateway.prompt-cache "preserves the provider prefix across
chat.send, completion and Gateway restart", turn 5 history[9]). Main at
022959b fails the same test.

Send the stored, provenance-annotated text as the model-facing user text
from the first request on instead: history and the first dispatch agree,
the source-provenance safety text stays visible after its transient
carrier is gone, and nothing is captured or persisted for these turns.

This also removes the recorder capture calls #169130's release backport
added for request-local text (inter-session turns and fallback retries).
The fallback retry goes back to 9def9c1's uncaptured request-local
path, so neither path can reject a dispatch with "requires a live,
persisted user turn" anymore.

Backport of main 0b9d049 (#169238), adapted for 2026.10.2 (keeps the release-only fallback-retry path from 9def9c1).
RomneyDa added a commit that referenced this pull request Oct 12, 2026
…169238)

#169130 kept an inter-session turn's body-only model prompt request-local
so history replays the stored "[Inter-session message] ..." envelope. The
turn's first request (routed body) and every later replay (stored
envelope) then differ, so a private subagent completion rewrites the
provider prefix on the next turn (gateway.prompt-cache "preserves the
provider prefix across chat.send, completion and Gateway restart", turn 5
history[9]). Its request-local capture could also reject a dispatch with
"Model prompt projection requires a live, persisted user turn".

When the prompt would drop the stored envelope, send the stored annotated
text from the first request on: first send and replay agree, the
source-provenance safety text stays visible after its transient carrier
is gone, and nothing is captured or persisted for these turns. This
removes the recorder's requestLocal option added by #169130.

(cherry picked from commit 0b9d049)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…penclaw#169238)

openclaw#169130 kept an inter-session turn's body-only model prompt request-local
so history replays the stored "[Inter-session message] ..." envelope. The
turn's first request (routed body) and every later replay (stored
envelope) then differ, so a private subagent completion rewrites the
provider prefix on the next turn (gateway.prompt-cache "preserves the
provider prefix across chat.send, completion and Gateway restart", turn 5
history[9]). Its request-local capture could also reject a dispatch with
"Model prompt projection requires a live, persisted user turn".

When the prompt would drop the stored envelope, send the stored annotated
text from the first request on: first send and replay agree, the
source-provenance safety text stays visible after its transient carrier
is gone, and nothing is captured or persisted for these turns. This
removes the recorder's requestLocal option added by openclaw#169130.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 20, 2026
First-parent upstream 0bc7491..408a1f3 (53 commits, including
openclaw#169164 cold session/memory SQL off the Gateway main thread, openclaw#169173
per-turn SQLite bookkeeping, openclaw#169207 coalesced tool-result actor
admissions, openclaw#169238 inter-session envelope bytes, openclaw#168989 ACP replies).

Conflict:
- plugin-sdk-surface-report.mts: upstream budgets 3673/2134; ours stays
  +11/+4 on top (3684/2138).

Drag removed against upstream:
- plugin-sdk-surface-report.mts: dropped the "+1: createSessionHeaderLink"
  budget comments; upstream added them in openclaw#158742 and retired them in
  openclaw#165334, and no such export exists any more.
- normalize-reply.ts: restored upstream's blank line before
  bindNormalizeReplyTransformOwner (formatting-only overlay noise).

Auto-merged files that carry continuation overlay (normalize-reply,
sqlite-entry-store, user-turn-transcript, baselines, vitest paths) keep
the overlay byte-for-byte. Worker access inventory regenerated.

Refs #1475

Co-Authored-By: Claude Opus 5.5 <[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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant