Repository navigation
Conversation
|
Codex review: needs changes before merge. Reviewed July 6, 2026, 11:04 PM ET / 03:04 UTC. Summary PR surface: Source +139, Tests +365. Total +504 across 17 files. Reproducibility: yes. source inspection shows current main prepends currentInboundContext into the active prompt while the LLM boundary strips that same metadata only after the turn becomes historical. I did not run tests because this review is read-only. Review metrics: 1 noteworthy metric.
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:
Mantis proof suggestion Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Security Review findings
Review detailsBest possible solution: Keep the tail-carrier fix shape, but preserve two-argument SDK helper compatibility with an empty default before landing the prompt-cache repair. Do we have a high-confidence way to reproduce the issue? Yes, source inspection shows current main prepends currentInboundContext into the active prompt while the LLM boundary strips that same metadata only after the turn becomes historical. I did not run tests because this review is read-only. Is this the best way to solve the issue? No as submitted: the carrier design is the right owner-boundary fix, but the exported helper signature needs a compatibility default before this is the best merge shape. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e3c40efeb09f. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +139, Tests +365. Total +504 across 17 files. View PR surface stats
Acceptance criteria:
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
Review history (5 earlier review cycles)
|
|
Reworked to follow ClawSweeper's recommended path. The P1 was correct — the This revision no longer strips: it moves the current-turn inbound metadata into The cache-placement improvement over a plain before-user handoff: the carrier is Reviewed with adversarial gpt-5.5/codex sweeps (correctness, byte-identity, |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Maintainer review + land prep. Review: bug confirmed on Fixup pushed ( Validation (Blacksmith Testbox, PR tree): Known proof gap: headline A/B numbers were measured on the earlier strip-design revision; the shipped tail-carrier design shares the byte-stability property (unit-proven) but was not re-measured live. Accepted as maintainer decision. Landing after CI on the new head. |
…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)
Fixes #100271
Reported-by: @Peetiegonzalez
cc: @Peetiegonzalez
Problem
The channel layer decorates the ACTIVE user message with an inbound-metadata block
("Conversation info (untrusted metadata)" / "Reply target of current user message" / sender /
forwarded / chat-history), composed at request-build time via
buildInboundUserContextPrefix(
src/auto-reply/reply/inbound-meta.ts) →currentInboundContext. But the session store persiststhe BARE user text, and
stripHistoricalInboundMetadataFromUserMessages(
src/agents/embedded-agent-runner/run/attempt.llm-boundary.ts) strips that block from historicaluser turns before replay. The active turn becomes the previous turn's history the instant a new
turn arrives, so its serialized bytes change retroactively — decorated as the active turn, bare as
history — on every single turn, invalidating any prefix/exact-match provider prompt cache from that
point onward, every turn. (#90811 fixed the timestamp half of this same active/historical
asymmetry; this is the metadata half.)
Fix — tail-placed runtime-context carrier
This reworks the earlier "strip the active turn" approach (which lost model-visible context, the
blocker ClawSweeper raised) into one that keeps the context AND recovers the cache cost.
Current-turn inbound metadata is routed out of the user prompt and into the existing hidden
runtime-context custom message (the mechanism from #89428 — credited below), and that carrier is
relocated to the absolute tail of the wire request — after the active user turn and any
tool-call scaffolding:
cache-stability guarantee; the same property fix(agents): stabilize user-turn serialization across turns to preserve prompt cache #90811 established for the timestamp).
lands exactly where the next turn's new bytes (the assistant reply) begin anyway. The request is
an append-only prefix-extension through the active user turn — only the trailing carrier is
ever re-billed.
forfeits the win. A durable marker (
UserMessage.runtimeContextCarrier, set byconvertToLlmfrom the carrier's
details) lets the Anthropic and OpenAI-completions transports skip it whenselecting the deepest
cache_controlbreakpoint, keeping the anchor on the last stable user turn.Storage stays BARE (the documented invariant in
src/sessions/user-turn-transcript.tsispreserved); runtime-only turns (room events) keep their existing inline behavior when they have no
bare user turn to protect; legacy sessions with bare-stored user messages are unchanged.
Why tail placement, not before-user (the divergence-offset math)
The runtime-context carrier is per-turn and stripped on replay, so it necessarily vanishes at its
slot next turn. Where that slot sits decides how much re-bills on a prefix cache:
C is the only option that preserves current-turn context AND is append-only. B keeps context but
recovers almost none of the cache cost on prefix caches (and only breakpoint scraps on Anthropic),
because the carrier vanishing before userN re-bills the whole tail — the same magnitude as the
bug. This PR stacks on #89428's runtime-context handoff and adds the tail placement + the
transport breakpoint anchor.
Review
Reviewed with N adversarial gpt-5.5 (codex) sweeps — correctness of the carrier/placement path,
byte-identity/cache-divergence, compatibility & transcript readers, and test adequacy. Reviewed with 5 adversarial gpt-5.5 (codex) read-only sweeps — correctness of the carrier/placement path, byte-identity/cache-divergence, compatibility & transcript readers, test adequacy, plus a final consolidated pass. Found + fixed: (1) a second Anthropic cache-anchor path — the managed transport (
src/agents/anthropic-transport-stream.ts+anthropic-payload-policy.ts, the OAuth/managed path) was still anchoring the deepestcache_controlbreakpoint on the relocated tail carrier; it now carries the same carrier opt-out; (2) missing provider-payload breakpoint tests for the managed Anthropic transport and OpenAI-completions (added). A theoretical runtime-only inline mutation was verified unreachable (room-event/system context is not strip-eligible, and non-room turns always have a non-empty body so are never runtime-only) and pinned with a byte-stability test. The final consolidated sweep came back clean.Tests
internal-runtime-context.test.ts:relocateCurrentRuntimeContextCarrierToTailunit coverage(before-user → tail, past tool scaffolding, idempotent no-op, no-carrier, no-active-user).
attempt.llm-boundary.cache-stability.test.ts: the active user turn is bare with the carrier atthe tail; the same message is byte-identical once aged to history (carrier gone); request N+1 is
a strict prefix-extension of request N through the active user turn.
anthropic.test.ts: the deepest cache breakpoint anchors on the last stable user turn, skippinga trailing runtime-context carrier.
messages.test.ts:convertToLlmmarks a runtime-context carrier so providers skip cacheanchoring; ordinary custom messages are unmarked.
attempt.spawn-workspace.context-engine.test.ts: updated to assert current-turn metadata nowrides the runtime-context carrier (bare user prompt), for both the normal and suppressed
room-event paths.
Typecheck (
node scripts/run-tsgo.mjs -p tsconfig.core.json): zero new errors (47 pre-existingui/module-resolution errors present on unmodified upstream main too).Full shard results vs pristine
upstream/mainbaseline — zero NEW failures:agents-embedded-agent1629/1629;
unit-fast11088 passed (4 pre-existingtest/scripts/{check,verify}.test.tsfailures,identical on base); packages (
ai/agent-core/llm-core) 390/390.What Problem This Solves
The active user turn's serialized text differed from how that same turn is later replayed as
history: the channel layer decorated the active turn with an untrusted-metadata block that
stripHistoricalInboundMetadataFromUserMessagesstrips for every historical turn but left in placefor the turn currently being sent. Since the active turn becomes the previous turn's history the
instant the next turn arrives, its bytes changed retroactively at that point in the conversation on
every single turn — invalidating any prefix/exact-match provider prompt cache from that point
onward. This PR keeps the metadata model-visible (now on both the active turn and — via the tail
carrier — nowhere in replayed history, so history stays clean) while making the user turn
byte-stable.
Evidence
The byte-stability property this PR gives the user turn (bare + append-only in both positions) is
the same one measured for the active/historical asymmetry in #100271:
TRUE cache-hit rate once the active user turn stops mutating.
cache_controlbreakpoints:over a 12-turn session cacheWrite 60,208 → 10,051 tokens (-83%), cacheRead advancing
monotonically instead of resetting to the same system-prompt breakpoint every turn. This PR's
transport breakpoint anchor is what keeps that win under tail placement (the breakpoint stays on
the stable user turn, not the volatile trailer).
neutral-to-slightly-positive — not a regression.
Unlike the strip approach those numbers were first measured under, this design preserves the
current-turn sender/reply/mention context for the model (addressing ClawSweeper's P1) — it moves
the context to the runtime-context carrier rather than deleting it. The only added cost over pure
strip is the trailing carrier's own bytes once per turn (read-priced, never part of a reused
prefix).
Full per-call tables and the Anthropic breakpoint mechanism:
https://raw.githubusercontent.com/Marvinthebored/openclaw/proof-assets-metadata-byte-stability/pr-proof/100272-metadata-byte-stability/EVIDENCE.md