fix(openrouter): gate prompt cache markers by endpoint#60761
Conversation
Greptile SummaryThis PR fixes a bug where OpenRouter Anthropic prompt-cache Key changes:
Confidence Score: 4/5Safe to merge; the fix is logically correct, well-scoped, and backed by targeted regression tests. The core change is sound: endpoint class from resolveProviderRequestPolicy is the right signal to gate cache marker injection, and the three new tests lock in all the relevant scenarios. The wrapper is now unconditionally installed for all providers in applyPostPluginStreamWrappers but its fast-path is cheap. The only deductions are a minor style issue with test model constants and the fact that isOpenRouterAnthropicModelRef may now be unused in this path. src/agents/pi-embedded-runner/proxy-stream-wrappers.test.ts — update test model constants per repo guideline. Optionally audit isOpenRouterAnthropicModelRef in anthropic-family-cache-semantics.ts for any now-dead callers. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/pi-embedded-runner/proxy-stream-wrappers.test.ts
Line: 57
Comment:
**Test model constant out of sync with repo guideline**
`CLAUDE.md` says: _"When tests need example Anthropic/OpenAI model constants, prefer `sonnet-4.6` and `gpt-5.4`; update older Anthropic/GPT examples when you touch those tests."_ The same model string appears in all three new test cases (`anthropic/claude-sonnet-4`). Since these are OpenRouter-prefixed model refs the standalone `sonnet-4.6` constant doesn't apply directly, but the spirit of the rule is to keep test constants current. Consider using `anthropic/claude-sonnet-4-5` (or whatever the current canonical OpenRouter Anthropic path is) so the tests don't require updating again soon.
This applies to the same `id` field at lines 57, 82, and 106.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Merge branch 'main' into fix/openrouter-..." | Re-trigger Greptile |
b0625de to
99c0c30
Compare
* fix(openrouter): gate prompt cache markers by endpoint * test(openrouter): use claude sonnet 4.6 cache model
* fix(openrouter): gate prompt cache markers by endpoint * test(openrouter): use claude sonnet 4.6 cache model
* fix(openrouter): gate prompt cache markers by endpoint * test(openrouter): use claude sonnet 4.6 cache model
* fix(openrouter): gate prompt cache markers by endpoint * test(openrouter): use claude sonnet 4.6 cache model
* fix(openrouter): gate prompt cache markers by endpoint * test(openrouter): use claude sonnet 4.6 cache model
AI-assisted: Codex
Testing: focused test + build
Session log: available in Codex session history
Summary
Describe the problem and fix in 2–5 bullets:
cache_controlmarkers were keyed to provider/plugin identity instead of endpoint classification.provider: openrouteron a custom OpenAI-compatible proxy could receive OpenRouter/Anthropic-only payload mutations, while custom provider ids pointed at native OpenRouter missed the cache optimization.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
provider === "openrouter", so it diverged from the transport stack's endpoint-based OpenRouter detection.Regression Test Plan (if applicable)
src/agents/pi-embedded-runner/proxy-stream-wrappers.test.tsUser-visible / Behavior Changes
cache_controlmarkers.Thanks @vincentkoc.Diagram (if applicable)
Security Impact (required)
No)No)No)No)No)Yes, explain risk + mitigation: N/ARepro + Verification
Environment
openrouterprovider on default route vs custombaseUrl, plus custom provider id targetinghttps://openrouter.ai/api/v1Steps
provider: openrouterwith a custom OpenAI-compatiblebaseUrl.baseUrlis native OpenRouter.Expected
Actual
Evidence
Attach at least one:
Verification snippets:
pnpm test src/agents/pi-embedded-runner/proxy-stream-wrappers.test.tspnpm buildpnpm checkcurrently fails in untouched files on this branch (src/agents/pi-embedded-runner/compact.hooks.harness.ts,src/agents/pi-embedded-runner/run/setup.ts) with existing TS2883 portability errors; those files are not part of this diff.Human Verification (required)
What you personally verified (not just CI), and how:
pnpm buildpasses.pnpm checkis blocked by untouched TS2883 errors outside this change.Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes)No)No)Risks and Mitigations