Repository navigation
fix(agents): pin the session system prompt on every Anthropic Messages route - #197925
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR pins session system prompts across Anthropic Messages routes and sends subsequent instruction changes as appended notes. Example: A custom-base-URL Anthropic session receives completion wakes, skill updates, and workspace edits across 11 provider requests.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a demonstrated prompt-cache problem using the existing session owner; the prior typing finding is fixed, and no actionable defects remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded agent runner resolves transport capabilities, prepares a transcript-backed session prompt, and projects instruction updates into provider-compatible messages. flowchart LR
A[Provider and model route] --> B[Transcript policy]
B --> C[Session runtime preparation]
C --> D[Session prompt owner]
D --> E[Transcript checkpoint]
D --> F[Message projection]
F --> G[Anthropic Messages request]
Technical reviewBest possible solution: Use the existing transcript-backed prompt series for Anthropic Messages routes while retaining transport-specific message projection. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the narrow capability gate, and the supplied real Gateway comparison demonstrates the affected proxy flow; this review executed no target code. Is this the best way to solve the issue? Separating prompt pinning from system-message support is the smallest complete repair because the session owner, checkpoint format, and user-role projection already exist. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4e8898bc6cf6. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +13, Tests +38, Docs +4. Total +55 across 7 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 November 12, 2026, 11:12 PM ET / November 13, 2026, 04:12 UTC (Revision 4). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…s route Anthropic caches tools, then system, then messages, so any system-prompt change re-writes the whole conversation. The session prompt series (pinned prompt plus appended section deltas) ran only on direct API-key Claude 5 routes and native OpenAI Responses. Every other Anthropic Messages route (proxies and custom base URLs, OAuth, Vertex, Foundry) re-rendered the prompt each attempt, so wakes, inter-session turns, skill or node changes and workspace edits each re-wrote the conversation. The transcript policy now has a separate pinnedSystemPrompt flag, true for every anthropic-messages route. The series, its retirement check and its checkpoint persistence key on that flag. Where the route cannot send mid-conversation system messages, the existing LLM boundary already projects the delta as a user-role note. The in-history system capability itself is unchanged. Real route (custom base URL proxy, cacheRetention short): one target session through user turns, an exec wake, sessions_send, a skill add, a workspace-file edit and a subagent settle. System prompts per session 6 -> 1; full re-writes 6 -> 2; session cache writes 146.5k -> 76.3k. Co-authored-by: obviyus <[email protected]>
…e preparation The helper-level loop exercised unchanged code. The runtime test resolves the policy for a proxy Anthropic Messages route and fails on the base. Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
73bb9f5 to
e1cac43
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…ranking typing change Co-authored-by: obviyus <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…s route (openclaw#197925) Co-authored-by: obviyus <[email protected]>
…s route (#197925) Co-authored-by: obviyus <[email protected]> (cherry picked from commit d4577ec) Co-authored-by: RomneyDa <[email protected]> Backport-adaptation: Preserve beta.4 transcript branch reader and existing tool-pin lifecycle; exclude main-only usage-ranking and GitHub-listing features. Apply pinned prompt condition and canonical proxy regression only.
Problem
Anthropic caches tools, then system, then messages. Any byte change in the system prompt therefore re-writes the whole conversation at cache-write price.
OpenClaw already has the right mechanism: a per-session system prompt series (
session-prompt-state.ts,prepareSessionSystemPrompt). It pins the admitted prompt and appends only changed, added or removed sections as aprompt-updatedelta after the conversation prefix. But the series was gated oninHistorySystemUpdates, which is true only for direct API-key Claude 5 routes (api.anthropic.com, no OAuth) and native OpenAI Responses (transcript-policy.ts). Every other Anthropic Messages route re-rendered the full prompt on every attempt (attempt-session-runtime-prepare.ts): proxies and custom base URLs, OAuth, Vertex and Foundry.On a production gateway behind a proxy route, 82 of 95 cache breaks that happened within the 5-minute cache window on one day were system-prompt changes. The causes included exec and tool-handoff wakes,
sessions_sendand subagent-settle turns, skill snapshot refreshes (including remote-node availability), and workspace-file edits.Fix
pinnedSystemPromptflag. It is true for everyanthropic-messagesroute and for every route that already hadinHistorySystemUpdates.beginSessionSystemPrompt) and its checkpoint persistence key onpinnedSystemPrompt. Without the checkpoint, the pin would not survive a gateway restart.inHistorySystemUpdateskeeps meaning "this route accepts mid-conversation system messages". Where it is false, the existing LLM boundary already projects the delta as a plain user-role note. No new wire format is needed.Proof
Real route, before vs after. Isolated throwaway Gateway (scratch state, no channels), Claude Opus 5.5 through an Anthropic-compatible custom base URL proxy (the previously ungated case),
cacheRetention: short. A logging proxy recorded the provider's owncache_read_input_tokens/cache_creation_input_tokensand a digest of the sent system prompt. User turns were sent as an operator UI client throughchat.send.One target session went through:
sessions_sendinto it;USER.md) edited;main)sessions_send, skill add, file edit and subagent settle each re-wrote 20–28k tokens (the whole conversation).## Tooling, ## Session routingafter asessions_sendturn and## Skillsafter the skill add.Focused tests:
transcript-policy.test.ts: the route table now assertspinnedSystemPromptfor direct API key, OAuth, proxy base URL, Vertex and Foundry Anthropic Messages, and not for Bedrock.inHistorySystemUpdatesis unchanged.attempt-session-runtime-prepare.test.ts(fails on the base, passes here): with the policy resolved for a proxy Anthropic Messages route (inHistorySystemUpdates: false), session runtime preparation keeps the admitted system prompt when the next turn renders without the task-suggestion grant, and emits the Tooling delta.embedded-agent-runner.prompt-cache.test.ts(existing request-prefix suite, both Anthropic Messages variants) and the session runtime / prompt-phase / LLM boundary suites pass.Not covered (follow-ups)
## Related, so one file edit re-sends that whole duplicate-heading group.