Repository navigation
fix(agents): keep prompt history append-only mid-session for prompt-cache stability - #102610
Merged
Merged
Conversation
Session-scoped tool-result projection freeze (shrink-only, stable fallback identities for ambiguous tool ids) and a sent-watermark so late-resolving inbound media appends a new user turn instead of rewriting an already-sent slot. Stops Anthropic prompt-cache tail invalidation on busy/media-heavy embedded sessions.
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jul 10, 2026
) (openclaw#102610) Session-scoped tool-result projection freeze (shrink-only, stable fallback identities for ambiguous tool ids) and a sent-watermark so late-resolving inbound media appends a new user turn instead of rewriting an already-sent slot. Stops Anthropic prompt-cache tail invalidation on busy/media-heavy embedded sessions.
steipete
added a commit
that referenced
this pull request
Jul 11, 2026
…02610) Session-scoped tool-result projection freeze (shrink-only, stable fallback identities for ambiguous tool ids) and a sent-watermark so late-resolving inbound media appends a new user turn instead of rewriting an already-sent slot. Stops Anthropic prompt-cache tail invalidation on busy/media-heavy embedded sessions. (cherry picked from commit fd34019)
zooqueen
pushed a commit
to zooqueen/openclaw
that referenced
this pull request
Sep 11, 2026
) (openclaw#102610) Session-scoped tool-result projection freeze (shrink-only, stable fallback identities for ambiguous tool ids) and a sent-watermark so late-resolving inbound media appends a new user turn instead of rewriting an already-sent slot. Stops Anthropic prompt-cache tail invalidation on busy/media-heavy embedded sessions. (cherry picked from commit fd34019)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #99495
What Problem This Solves
On the embedded agent runner, two mechanisms mutated already-sent history messages between provider requests, invalidating the Anthropic prompt-cache tail mid-session (reported with
diagnostics.cacheTracefingerprint evidence in #99495; measured at ~26% of Anthropic spend on a media-heavy deployment):ToolResultPromptProjectionState) was created per attempt, so it never spanned turns. The same historical web-search result oscillated between fuller and shorter renderings request to request. Results with ambiguous/missing tool ids were never frozen at all.updateMode: "inline"), flipping a text turn into a media turn at the same index and invalidating the whole tail.Why This Change Was Made
Prompt history must be append-only within a session once bytes have been sent:
src/agents/embedded-agent-runner/session-prompt-state.ts): frozen tool-result projections now live in a bounded (64-entry LRU) process-local map keyed by session id, disposed on session reset (clearSessionResetRuntimeState). Prechecks operate on clones; only the provider-dispatch transform freezes emitted bytes. Frozen bytes are shrink-only: they move only after fresh output is exhausted and the aggregate guard still overflows, starting from the frozen projection — never re-expanding when pressure drops. Ambiguous/missing tool ids get a stable hashed fallback identity so they freeze too.src/sessions/user-turn-transcript.ts): the provider-dispatch transform marks the current user turn sent. Media that resolves after that point is persisted as a new appended turn (:late-mediaidempotency key) instead of an inline rewrite, so the wire prefix and the transcript stay byte-identical. Media resolving before first serialization keeps the existing inline merge.Both fixes respect the existing byte-stability invariants (#3658 canonicalization layer, #100272 tail runtime-context carrier). No config surface added; CLI-runner and channel code untouched.
User Impact
Anthropic (and any prefix-cached provider) deployments stop paying repeated 25–75K-token tail re-writes at the 2× TTL write rate on busy/media-heavy sessions. Worst case after a process restart is one deliberate re-shape, then stable. No behavior change for sessions that never hit aggregate pressure or mid-run media.
Evidence
summarizeMessagesfromcache-trace.ts); early media keeps inline merge; projection disposal on session reset.tool-result-truncation.test.ts61 passed,attempt.llm-boundary.cache-stability.test.ts13 passed,user-turn-transcript.test.ts34 passed,session-reset-cleanup.test.ts6 passed; fullsrc/agents/embedded-agent-runnerproject run 5595 passed (6 unrelated flakes passed in isolation).pnpm check:changed: exit 0 ontbx_01kx31g1safq928g9fxs7qh0y2(typecheck core + core tests, oxlint shards, import cycles, security/package guards)