Skip to content

fix(agents): subagents lose inter-session provenance in replayed history - #169130

Merged
RomneyDa merged 2 commits into
mainfrom
fix/inter-session-provenance-replay
Oct 11, 2026
Merged

RomneyDa merged 2 commits into
mainfrom
fix/inter-session-provenance-replay

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Related: #167938

What Problem This Solves

Fixes: a subagent loses the "this came from another session, not your user" provenance header on earlier sessions_send follow-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_send safety 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 modelPromptProjection and 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 (installModelPromptProjection in src/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 requestLocal capture option that reuses the recorder's redaction, and a shared projection builder). Tests: +90.

Evidence

  • Regression test replays an inter-session turn with its stored provenance envelope (plain, forwarded-envelope, and redacted-hook bodies) in attempt-prompt-submit.projections.test.ts:
    • on origin/main (27212da): the plain and forwarded cases fail; the second request shows history "Continue the delegated task." with no sourceSession=.
    • with a body-prefix-only check: the forwarded-envelope case fails.
    • at the first PR head (ce9072c, which skipped capture): the redacted-hook case fails, and the provider request contains hidden.
    • with this fix: 15/15 in the file pass.
  • 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 unrelated ui/src/** exports this PR does not touch.
  • Autoreview (Codex): the first pass found that a forwarded envelope could get past a body-prefix check. That is fixed and covered. ClawSweeper found the skipped-redaction gap, also fixed and covered. The final autoreview pass is clean.
  • The live symptom was found by 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-layout e2e) by #169182 / 345f400. The current head is rebased onto 345f400.

@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 13:44
@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: 🚨 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 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.

  • Before: Replayed history contains the task body without sourceSession=agent:main:parent.
  • After: Replayed history retains the parent source envelope, while the arrival request uses the redacted routed body.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch appears correct and its regressions protect meaningful boundaries; behavioral evidence remains an in-process harness rather than a shipped Gateway flow.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence exercises storage and provider serialization in process, and the body explicitly states that no live run was performed.
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 child agent replaying an earlier sessions_send turn loses the warning that its instructions came from another session.
Reason: The maintainer-authored change restores intended source context with a small repair and explicitly records its cache tradeoff.

Regression provenance

Possible 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
Reviewed head: 35d0331c0bdef7012b514f778c8348639d2f027e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No after-fix Gateway cold-restart run is supplied; the new regression reconstructs history in process with mocked provider streaming.
Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • Durable user prompt capture and replay changes intended behavior with a stated reason (6461c18: Preserve enriched first-request text across follow-ups and reopened sessions without rewriting visible transcript content.)
  • Capture-time redaction keeps the original intent (6461c18: Redact enriched model-facing text before its first dispatch and durable capture.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +15, Tests +90. Total +105 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 26 11 +15
Tests 1 90 0 +90
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 116 11 +105

Review metrics

Metric Value Why it matters
Production versus test growth Production +26/-11; tests +90/-0 The focused growth reuses recorder redaction and adds three distinct provenance/redaction regression cases without a new persistence owner.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Inter-session history loses meaningful source context, but the evidence establishes a bounded agent replay regression rather than a demonstrated authorization bypass.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-11T13:50:25.403Z sha ce9072c :: blocked before merge. :: [P1] Redact request-local replacements before provider dispatch
  • reviewed 2026-10-11T14:15:15.238Z sha b150009 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-11T14:46:11.903Z sha de63462f258b56dbb63f72d9a8a7a2bb48608977 :: needs changes before merge. :: none

Reviewed October 11, 2026, 11:13 AM ET / 15:13 UTC (Revision 4).

@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@RomneyDa
RomneyDa force-pushed the fix/inter-session-provenance-replay branch from b150009 to de63462 Compare October 11, 2026 14:31
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 11, 2026
@RomneyDa
RomneyDa force-pushed the fix/inter-session-provenance-replay branch from de63462 to 35d0331 Compare October 11, 2026 14:54
@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 11, 2026
#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.
@RomneyDa
RomneyDa force-pushed the fix/inter-session-provenance-replay branch from 35d0331 to 19666be Compare October 11, 2026 15:29
@RomneyDa
RomneyDa merged commit 022959b into main Oct 11, 2026
127 checks passed
@RomneyDa
RomneyDa deleted the fix/inter-session-provenance-replay branch October 11, 2026 15:41
@RomneyDa

Copy link
Copy Markdown
Member Author

Merged via squash.

RomneyDa added a commit that referenced this pull request Oct 11, 2026
…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)
RomneyDa added a commit that referenced this pull request Oct 11, 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.
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
…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.
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
…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.
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 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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