Repository navigation
fix(agents): subagents lose inter-session provenance in replayed history - #169130
Conversation
|
🦞👀 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 keeps inter-session prompt replacements request-local so later history retains the stored source envelope. 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 fixes a current replay regression, resolves the earlier redaction finding, and introduces no remaining actionable defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe embedded agent’s prompt boundary receives canonical transcript messages and prepared prompt text, then produces model-facing messages while the transcript recorder owns durable projections and redaction. flowchart LR
A[Inter-session input] --> B[Canonical transcript]
B --> C[Prompt projection boundary]
C --> D[Recorder redaction]
D --> E[Current provider request]
B --> F[Later history replay]
F --> E
Technical reviewBest possible solution: Retain the narrow provenance repair and handle the independently evidenced CI failure through the repository’s inherited-failure landing workflow. Do we have a high-confidence way to reproduce the issue? Current main’s prompt assembly removes the source envelope from active text, and its projection boundary persists that replacement for replay; the supplied regression results match this path, but no reproduction was executed during this review. Is this the best way to solve the issue? The existing projection and recorder owners provide a focused repair with shared redaction, and the maintainer-authored PR explicitly accepts the cache tradeoff rather than claiming to solve cache stability. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5da9eae07c5a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +15, Tests +90. Total +105 across 5 files. Added test files: 0. View PR surface stats
Review metrics
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 HistoryReview history (3 earlier review cycles)
Reviewed October 11, 2026, 11:13 AM ET / 15:13 UTC (Revision 4). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
b150009 to
de63462
Compare
de63462 to
35d0331
Compare
#167938 freezes a user turn's first model-facing text as a projection and replays it as history. For inter-session input (e.g. a sessions_send follow-up) the stored transcript text carries the "[Inter-session message] sourceSession=... sourceTool=..." safety envelope, while the active request moves that envelope into a transient runtime-context carrier and sends only the routed body. Capturing the body as the projection meant that once the turn became history the envelope disappeared from the model's view, so a child resumed after a Gateway restart no longer saw that the earlier message came from another session rather than its user. When the prompt does not contain the whole stored inter-session text, keep the replacement request-local so history replays the stored, provenance-annotated text. Comparing the full stored text (not the body's prefix) also covers forwarded bodies that carry their own envelope. Other enriched prompts still freeze their first projection.
Keeping an inter-session replacement request-local skipped the recorder's capture, which is also where configured and registered-secret redaction is applied before the first provider dispatch. Route request-local text through the same capture with a requestLocal option: it is redacted exactly like a durable projection but the stored user record is left unchanged.
35d0331 to
19666be
Compare
|
Merged via squash.
|
…ory (#169130) * fix(agents): keep inter-session provenance in replayed history replays it as history. For inter-session input (e.g. a sessions_send follow-up) the stored transcript text carries the "[Inter-session message] sourceSession=... sourceTool=..." safety envelope, while the active request moves that envelope into a transient runtime-context carrier and sends only the routed body. Capturing the body as the projection meant that once the turn became history the envelope disappeared from the model's view, so a child resumed after a Gateway restart no longer saw that the earlier message came from another session rather than its user. When the prompt does not contain the whole stored inter-session text, keep the replacement request-local so history replays the stored, provenance-annotated text. Comparing the full stored text (not the body's prefix) also covers forwarded bodies that carry their own envelope. Other enriched prompts still freeze their first projection. * fix(agents): redact request-local inter-session prompts before dispatch Keeping an inter-session replacement request-local skipped the recorder's capture, which is also where configured and registered-secret redaction is applied before the first provider dispatch. Route request-local text through the same capture with a requestLocal option: it is redacted exactly like a durable projection but the stored user record is left unchanged. Adapted for 2026.10.2: request-local also covers the release-only fallback retry after an unprojected dispatch (9def9c1), and both paths now go through the recorder's redaction; capture keeps this line's rewriteTranscriptMessageAtAnchor with the inline active-row check. Supersedes a9c22375 (not included). (cherry picked from commit 022959b)
…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.
#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).
…ory (#169130) * fix(agents): keep inter-session provenance in replayed history replays it as history. For inter-session input (e.g. a sessions_send follow-up) the stored transcript text carries the "[Inter-session message] sourceSession=... sourceTool=..." safety envelope, while the active request moves that envelope into a transient runtime-context carrier and sends only the routed body. Capturing the body as the projection meant that once the turn became history the envelope disappeared from the model's view, so a child resumed after a Gateway restart no longer saw that the earlier message came from another session rather than its user. When the prompt does not contain the whole stored inter-session text, keep the replacement request-local so history replays the stored, provenance-annotated text. Comparing the full stored text (not the body's prefix) also covers forwarded bodies that carry their own envelope. Other enriched prompts still freeze their first projection. * fix(agents): redact request-local inter-session prompts before dispatch Keeping an inter-session replacement request-local skipped the recorder's capture, which is also where configured and registered-secret redaction is applied before the first provider dispatch. Route request-local text through the same capture with a requestLocal option: it is redacted exactly like a durable projection but the stored user record is left unchanged. (cherry picked from commit 022959b) Backport notes: test-only import conflict in attempt-prompt-submit.projections.test.ts: added the annotateInterSessionPromptText import; the finalizeRuntimePromptImages import in the conflict context belongs to main-only tests and is not used on the branch, so it is not added.
…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)
…ory (openclaw#169130) * fix(agents): keep inter-session provenance in replayed history openclaw#167938 freezes a user turn's first model-facing text as a projection and replays it as history. For inter-session input (e.g. a sessions_send follow-up) the stored transcript text carries the "[Inter-session message] sourceSession=... sourceTool=..." safety envelope, while the active request moves that envelope into a transient runtime-context carrier and sends only the routed body. Capturing the body as the projection meant that once the turn became history the envelope disappeared from the model's view, so a child resumed after a Gateway restart no longer saw that the earlier message came from another session rather than its user. When the prompt does not contain the whole stored inter-session text, keep the replacement request-local so history replays the stored, provenance-annotated text. Comparing the full stored text (not the body's prefix) also covers forwarded bodies that carry their own envelope. Other enriched prompts still freeze their first projection. * fix(agents): redact request-local inter-session prompts before dispatch Keeping an inter-session replacement request-local skipped the recorder's capture, which is also where configured and registered-secret redaction is applied before the first provider dispatch. Route request-local text through the same capture with a requestLocal option: it is redacted exactly like a durable projection but the stored user record is left unchanged.
…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 19fe879..0bc7491 (100 commits, including openclaw#169090 entry-writer postimages, openclaw#169201 transcript projection facts, openclaw#169113/openclaw#169107/openclaw#169125 session-actor admission, openclaw#169110 bounded worker heaps, openclaw#169130 inter-session provenance, openclaw#168931 Solid session UI). Conflicts: - session-accessor.sqlite-entry-mutation.ts: openclaw#169090 moved postimage publication into writeSessionEntry and replaced the revision-equality no-op check with postimages.changed. Took upstream's form; kept our recipient-authority advance on visibility narrowing (same transaction, after the write, before the no-op return). - session-accessor.sqlite-entry-store.ts: import union (upstream dropped withProjectedParticipants/SessionEntryWindowFacts imports; ours adds the recipient-authority advance). Overlay vs upstream is now 2 lines. - openclaw-tools.types.ts: import union (our RequestCompactionToolOpts, upstream's SessionsYieldRuntimeClaim). - plugin-sdk-surface-report.mts: upstream raised the budgets to 3672/2133; ours stays +11/+4 on top (3683/2137). - worker-access-inventory.md: regenerated on the merged tree. Auto-merged files that carry continuation overlay (21) keep the overlay byte-for-byte (interdiff of the +/- lines vs upstream before and after). Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #167938
What Problem This Solves
Fixes: a subagent loses the "this came from another session, not your user" provenance header on earlier
sessions_sendfollow-ups once those turns become history (for example after a Gateway cold restart).User Impact
User impact: child sessions keep seeing the
[Inter-session message] sourceSession=… sourceTool=sessions_sendsafety envelope on every replayed inter-session turn, so parent-sent instructions are never re-presented to the model as direct user instructions. No config or migration change.Why This Change Was Made
#167938 ("keep enriched user prompt history stable") freezes a turn's first model-facing text as a durable
modelPromptProjectionand replays it as history. For inter-session input the stored transcript text carries the provenance envelope, but the active request moves the envelope into a transient runtime-context message and sends only the routed body. Freezing that body meant the envelope vanished from history entirely once the transient carrier was gone.The model prompt projection boundary (
installModelPromptProjectioninsrc/agents/embedded-agent-runner/run/attempt-llm-boundary.ts) now keeps such a replacement request-local: when the prompt does not contain the whole stored inter-session text, the current request still sends the routed body, but no projection is captured and runtime state is not rewritten, so history replays the stored, annotated text. The check compares the full stored text rather than the body's prefix, so a forwarded body that carries its own envelope cannot stand in for the real outer hop. Other enriched prompts still freeze their first projection.Request-local text still goes through the recorder's capture (
captureModelPromptProjection(text, assertCurrent, { requestLocal })), so it gets the same configured and registered-secret redaction as a durable projection before provider dispatch; only the durable write is skipped.Tradeoff: like pre-#167938 behavior, an inter-session turn's history bytes differ from its arrival-request bytes, costing one prefix-cache miss on the next turn. Correct provenance outranks that cache hit.
Production LOC: +26/-11 (net +15: one predicate in the boundary, a
requestLocalcapture option that reuses the recorder's redaction, and a shared projection builder). Tests: +90.Evidence
replays an inter-session turn with its stored provenance envelope(plain, forwarded-envelope, and redacted-hook bodies) inattempt-prompt-submit.projections.test.ts:origin/main(27212da): the plain and forwarded cases fail; the second request shows history"Continue the delegated task."with nosourceSession=.hidden.node scripts/run-vitest.mjs src/sessions/user-turn-transcript src/agents/embedded-agent-runner/run/attempt.llm-boundary src/agents/embedded-agent-runner/run/attempt-prompt-submit: all pass.node scripts/check-changed.mjs --staged: format, typecheck for core and core tests, and guards pass. The dead-export scan fails only on unrelatedui/src/**exports this PR does not touch.test/gateway-subagent-restart.live.test.ts, which fails at the second cold-restart recovery on the 2026.10.2 release line. This PR has no live run; the unit boundary test reproduces the exact replay loss.CI note
Earlier heads went red only on UI breakage inherited from main. The Solid panel type errors were fixed by 2899226, the row-event param types by a098586, and the hidden terminal viewport (
chat-panel-layoute2e) by #169182 / 345f400. The current head is rebased onto 345f400.