Repository navigation
fix: keep inbound metadata in runtime context - #89428
SweetSophia wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR moves current-turn inbound metadata (e.g., Telegram/channel info) out of the visible user prompt text and into the hidden runtime context.
Changes:
- Adds
currentInboundContexttoresolveRuntimeContextPromptParts()and prefixes it intoruntimeContext. - Updates the embedded attempt flow to stop prepending inbound metadata to the prompt text for session/model prompts.
- Adds tests covering prompt text cleanliness and runtime context composition with inbound metadata.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/agents/embedded-agent-runner/run/runtime-context-prompt.ts | Accepts currentInboundContext and merges it into the constructed hidden runtimeContext. |
| src/agents/embedded-agent-runner/run/runtime-context-prompt.test.ts | Adds assertions that inbound metadata is excluded from prompt and included in runtimeContext. |
| src/agents/embedded-agent-runner/run/attempt.ts | Removes buildCurrentInboundPrompt(...) usage so inbound metadata is not prepended to user/model prompt text. |
| CHANGELOG.md | Documents the behavioral change for inbound Telegram/channel metadata handling. |
| @@ -74,6 +74,7 @@ export function resolveRuntimeContextPromptParts(params: { | |||
| effectivePrompt: string; | |||
| transcriptPrompt?: string; | |||
| modelPrompt?: string; | |||
| currentInboundContext?: CurrentInboundPromptContext; | |||
| [ | ||
| buildCurrentInboundPromptContextPrefix(params.currentInboundContext), | ||
| hiddenRuntimeContext, | ||
| extracted.runtimeContext, | ||
| ] |
| @@ -107,7 +108,11 @@ export function resolveRuntimeContextPromptParts(params: { | |||
| ? removeLastPromptOccurrence(extracted.text, transcriptPrompt)?.trim() | |||
| : undefined; | |||
| const runtimeContext = | |||
| [hiddenRuntimeContext, extracted.runtimeContext] | |||
| [ | |||
| buildCurrentInboundPromptContextPrefix(params.currentInboundContext), | |||
|
Codex review: needs maintainer review before merge. Reviewed June 21, 2026, 8:17 AM ET / 12:17 UTC. Summary PR surface: Source +9, Tests +88. Total +97 across 4 files. Reproducibility: yes. Source inspection on current main shows Review metrics: none identified. Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land one canonical hidden-runtime-context routing path that keeps inbound metadata available to the model without storing it as user-authored prompt/session text, either by refreshing this focused PR or folding its coverage into the broader reply-metadata PR. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection on current main shows Is this the best way to solve the issue? Yes, with maintainer coordination. The hidden AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 12c34fc3a951. Label changesLabel justifications:
Evidence reviewedPR surface: Source +9, Tests +88. Total +97 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
6d7ee01 to
d981d3d
Compare
d981d3d to
e059a15
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
e059a15 to
6f5b640
Compare
|
@SweetSophia — this stacks directly on your #89428. That PR's core idea (route The one delta is placement. A runtime-context carrier that is stripped on
Would love your review — this is meant to complete your approach, not compete |
…ntext message for byte-stable prompt caching The active user turn was decorated at request-build time with an inbound metadata block (Conversation info / reply-target / sender / forwarded / chat-history), but the session store persists the bare text and the LLM boundary strips that block from historical replay. So a user message's serialized bytes changed retroactively — decorated as the active turn, bare as history — on every turn, invalidating any prefix/exact-match provider prompt cache from that point onward, every turn. (#90811 fixed the timestamp half of this same asymmetry.) Rework of the earlier "strip the active turn" approach (which lost model-visible context — ClawSweeper's P1) into one that keeps the context AND recovers the cache cost: - Route current-turn inbound metadata out of the user prompt and into the hidden runtime-context custom message (the mechanism from #89428), and relocate that carrier to the ABSOLUTE TAIL of the wire request (after the active user turn and any tool-call scaffolding). The user turn stays bare and byte-identical in both the active and historical positions; the volatile carrier vanishes next turn exactly where the assistant reply begins anyway, so the request is an append-only prefix-extension through the active user turn. - A durable marker (UserMessage.runtimeContextCarrier, set by convertToLlm from the carrier's details) lets the Anthropic SDK transport, the managed Anthropic transport (anthropic-transport-stream / anthropic-payload-policy), and OpenAI-completions skip the carrier when selecting the deepest cache_control breakpoint, keeping the anchor on the last stable user turn. Storage stays BARE (invariant preserved); runtime-only turns (room events) keep their existing inline behavior, which is byte-stable because room-event/system context is not strip-eligible; legacy bare-stored sessions are unchanged. Reviewed with adversarial gpt-5.5/codex sweeps (correctness, byte-identity, compatibility, test adequacy): found + fixed the managed Anthropic transport cache-anchor path and added the missing OpenAI-completions/managed-transport breakpoint tests; a theoretical runtime-only mutation was verified unreachable and pinned with a test. Final sweep clean. Co-authored-by: #89428 (runtime-context handoff approach)
…ntext message for byte-stable prompt caching The active user turn was decorated at request-build time with an inbound metadata block (Conversation info / reply-target / sender / forwarded / chat-history), but the session store persists the bare text and the LLM boundary strips that block from historical replay. So a user message's serialized bytes changed retroactively — decorated as the active turn, bare as history — on every turn, invalidating any prefix/exact-match provider prompt cache from that point onward, every turn. (openclaw#90811 fixed the timestamp half of this same asymmetry.) Rework of the earlier "strip the active turn" approach (which lost model-visible context — ClawSweeper's P1) into one that keeps the context AND recovers the cache cost: - Route current-turn inbound metadata out of the user prompt and into the hidden runtime-context custom message (the mechanism from openclaw#89428), and relocate that carrier to the ABSOLUTE TAIL of the wire request (after the active user turn and any tool-call scaffolding). The user turn stays bare and byte-identical in both the active and historical positions; the volatile carrier vanishes next turn exactly where the assistant reply begins anyway, so the request is an append-only prefix-extension through the active user turn. - A durable marker (UserMessage.runtimeContextCarrier, set by convertToLlm from the carrier's details) lets the Anthropic SDK transport, the managed Anthropic transport (anthropic-transport-stream / anthropic-payload-policy), and OpenAI-completions skip the carrier when selecting the deepest cache_control breakpoint, keeping the anchor on the last stable user turn. Storage stays BARE (invariant preserved); runtime-only turns (room events) keep their existing inline behavior, which is byte-stable because room-event/system context is not strip-eligible; legacy bare-stored sessions are unchanged. Reviewed with adversarial gpt-5.5/codex sweeps (correctness, byte-identity, compatibility, test adequacy): found + fixed the managed Anthropic transport cache-anchor path and added the missing OpenAI-completions/managed-transport breakpoint tests; a theoretical runtime-only mutation was verified unreachable and pinned with a test. Final sweep clean. Co-authored-by: openclaw#89428 (runtime-context handoff approach)
|
This PR is now superseded by #100272. Marvin implemented a good version of the same core idea there: current-turn inbound metadata is carried through runtime context instead of being prepended to the user prompt, with the carrier moved to the tail so prompt caching stays byte-stable. So this branch should not be merged as-is anymore, but it was the right foundation for the landed fix. Thank you, Marvin. |
|
Closing as superseded by #100272, which landed the same runtime-context direction with Marvin's tail-carrier/cache-stability refinements. |
Summary
Fixes the remaining #72704-shaped path where current-turn inbound channel metadata was still prepended into the user prompt text.
Current
mainalready builds ordinary inbound metadata ascurrentInboundContext, butrun/attempt.tsimmediately merged that context back into bothpromptForSessionandpromptForModelviabuildCurrentInboundPrompt(...). That kept TelegramConversation info/Senderblocks on the model-visible user prompt path and could still persist the metadata-heavy prompt shape into active session state.This PR moves
currentInboundContextinto the existing runtime-context channel instead:promptForSession/promptForModelare no longer prefixed with current inbound metadata)Linked Issue
Closes #72704
Real behavior proof (required for external PRs)
Conversation info/Sender) was still being prepended into the user prompt path after it had been assembled ascurrentInboundContext.node --import tsx(no mocks, no test runner).node --import tsx -e 'const { resolveRuntimeContextPromptParts, buildRuntimeContextCustomMessage } = await import("./src/agents/embedded-agent-runner/run/runtime-context-prompt.ts"); const parts = resolveRuntimeContextPromptParts({ effectivePrompt: "Please execute your workflow", transcriptPrompt: "Please execute your workflow", currentInboundContext: { text: ["Conversation info (untrusted metadata):", "```json", JSON.stringify({ channel: "telegram", message_id: "14636" }), "```", "", "Sender (untrusted metadata):", "```json", JSON.stringify({ id: "redacted", name: "Sherina" }), "```"].join("\n") } }); const runtimeMessage = buildRuntimeContextCustomMessage(parts.runtimeContext); console.log(JSON.stringify({ prompt: parts.prompt, modelPrompt: parts.modelPrompt ?? null, promptContainsMetadata: parts.prompt.includes("Conversation info") || parts.prompt.includes("Sender (untrusted metadata)"), runtimeContextContainsMetadata: Boolean(parts.runtimeContext?.includes("Conversation info (untrusted metadata):") && parts.runtimeContext?.includes("Sender (untrusted metadata):")), runtimeMessageCustomType: runtimeMessage?.customType, runtimeMessageDisplay: runtimeMessage?.display }, null, 2));'{ "prompt": "Please execute your workflow", "modelPrompt": null, "promptContainsMetadata": false, "runtimeContextContainsMetadata": true, "runtimeMessageCustomType": "openclaw.runtime-context", "runtimeMessageDisplay": false }prompt/modelPrompt, and the same metadata is preserved in a non-displayedopenclaw.runtime-contextcustom message.main,run/attempt.tscalledbuildCurrentInboundPrompt({ context: params.currentInboundContext, ... })for bothpromptForSessionandpromptForModel, which prepended the metadata context into the prompt text.Tests and validation
node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-embedded-agent.config.ts- 78 files / 1299 tests passednode scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run/runtime-context-prompt.test.ts src/agents/embedded-agent-runner/run/attempt.llm-boundary.test.ts- 35 tests passed across 2 shardspnpm tsgo:core:test- passedpnpm exec oxfmt --check src/agents/embedded-agent-runner/run/attempt.ts src/agents/embedded-agent-runner/run/runtime-context-prompt.ts src/agents/embedded-agent-runner/run/runtime-context-prompt.test.ts src/agents/embedded-agent-runner/run/attempt.spawn-workspace.context-engine.test.ts- passedRegression coverage added:
Conversation info/Sendermetadata remains out ofparts.promptparts.runtimeContextopenclaw.runtime-contextwithout prepending it to the active prompt