fix(providers): cache OpenRouter system prompts - #7634
Conversation
WareWolf-MoonWall
left a comment
There was a problem hiding this comment.
Reviewed at 965761e. The bug is that chat_with_system was constructing system-message content as MessageContent::Text directly, bypassing to_message_content("system", …) — the only path that wraps the content in the content-part array with cache_control: {"type": "ephemeral"}. Every other call site in this file routes through that helper; this one didn't. The fix extracts a build_chat_with_system_request private builder that calls to_message_content for both roles, and routes chat_with_system through it, closing the gap.
🟢 What looks good — SSOT is now enforced structurally
Before this PR, whether a system prompt got cache_control depended on which code path constructed the message — chat went through to_message_content, chat_with_system didn't, and nothing at the type level prevented that drift from recurring. After this PR, both paths go through build_chat_with_system_request, which calls to_message_content for the system role. There is now one place that knows how to construct a system message for OpenRouter; the previous gap is structurally closed.
🟢 What looks good — test upgrade matches the fix
The old chat_request_serializes_with_system_and_user test was constructing MessageContent::Text directly (the same bug the fix patches) and only checking for string substrings in the serialized output, so it would have passed even without cache_control. The updated test calls build_chat_with_system_request and asserts system_parts[0]["cache_control"]["type"] == "ephemeral" explicitly. This test now covers the exact property that was regressing, and it would have caught the original bug.
🟢 What looks good — validation evidence is thorough for the scope
cargo nextest run --locked --workspace --exclude zeroclaw-desktop (8546 passed), full workspace clippy with ci-all, and the targeted 73 openrouter-scoped tests. The rollback SHA in the PR body exactly matches the current head commit, which I verified. No required local step was skipped.
Approving. The fix is correct, the SSOT story is sound, and the test upgrade provides the right regression coverage.
- 965761e fix(providers): cache OpenRouter system prompts
Summary
masterchat_with_systemrequest construction through the existing OpenRouter system-message content helper.cache_control: {"type": "ephemeral"}marker on system prompts for the simple chat-with-system path.zeroclaw-providers. Other providers, config loading, CLI behavior, and channel/runtime routing are unchanged.bug,risk: medium,size: S,provider,provider:openrouterValidation Evidence (required)
chat_with_systemnow uses the shared request builder and that the builder applies the existing OpenRouter system-message content helper. I did not perform a live OpenRouter API call.Security & Privacy Impact (required)
Yes/No for each. Answer any
Yeswith a 1–2 sentence explanation.NoNoNoNoYes, describe the risk and mitigation: None.Compatibility (required)
YesNoNoorYesto either: No upgrade steps are required.Rollback (required for
risk: mediumandrisk: high)git revert 965761e1ebafac9f1baf9d4db552059d167f89d0cache_controlcontent-part shape covered by the regression. No live API or log failure was verified.Supersede Attribution (required only when
Supersedes #is used)#<pr> by @<author>, one per line): None.Co-authored-bytrailers added in commit messages for incorporated contributors?NoNo, why (inspiration-only, no direct code/design carry-over): No superseded PR or contributor code is carried forward.