Repository navigation
fix(agents): inter-session turns rewrite the provider prompt prefix on the next turn - #169238
Conversation
#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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -3, Tests +6. Total +3 across 5 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 11, 2026, 1:33 PM ET / 17:33 UTC. |
|
Merged via squash.
|
#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).
…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)
…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.
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]>
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.tssince #169130.User Impact
User impact: inter-session turns, such as subagent completions and
sessions_sendfollow-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
requestLocaloption that #169130 added.Tradeoff: for these inter-session turns, any
modelPromptenrichment 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. Onorigin/main72f03a4 it fails withturn 5: prefix changed segment=history[9] path=$.content[0].text. With this change it passes.replays an inter-session turn with its stored provenance envelopecases (plain, forwarded-envelope, redacted-hook) now assert three things: the first request's user message carriessourceSession=, the replayed user message is byte-identical to it, and no unredacted hook text reaches the provider. All three cases fail onorigin/mainand 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 testsfails only inui/src/components/session-background.browser.test.tsx(42,5)(configObjectis not inProfilePreferencesReadOptions), which this PR does not touch. Autoreview is clean.