feat(ai): prompt-cache correctness fixes for Kimi, OpenRouter, and Bedrock - #766
Merged
Conversation
Plan: .omo/plans/cache-hit-maximization.md
code-yeongyu
force-pushed
the
code-yeongyu/cache-hit-ai-fixes
branch
from
August 9, 2026 08:43
101f55c to
1014c26
Compare
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.
Summary
This PR implements PR-A from the approved cache-hit maximization plan:
cache-hit-maximization.mdBehavior changes
usage.cached_tokensas cache-read usage without changing existing precedence.supportsPromptCacheKeycompatibility detection and send stable, clampedprompt_cache_keyvalues for Moonshot/Kimi requests.x-session-idand bodysession_id.anthropic/,qwen/, andgoogle/model prefixes after stripping one optional leading~; runtime and generator logic are identical.TDD evidence
Each implementation todo has captured failing and passing output under:
.omo/evidence/cache-hit-maximization/task-1-{red,green}.txt.omo/evidence/cache-hit-maximization/task-5-{red,green}.txt.omo/evidence/cache-hit-maximization/task-14-{red,green}.txt.omo/evidence/cache-hit-maximization/task-2-{red,green}.txt.omo/evidence/cache-hit-maximization/task-3-{red,green}.txt.omo/evidence/cache-hit-maximization/task-4-{red,green}.txt.omo/evidence/cache-hit-maximization/task-15-{red,green}.txt.omo/evidence/cache-hit-maximization/task-4-hydrate.txtandtask-4-model-data-check.txt.omo/evidence/cache-hit-maximization/task-15-changes.md.txtThese evidence files are task-local and intentionally ignored by git.
Verification
cd packages/ai && npm test -- test/- 191 files passed, 1816 tests passed, 25 files / 806 tests skipped by existing suite conditions.npm run check- passed.npm run build- passed (required to materialize workspace package artifacts before the full AI suite).npm run check:model-data- passed.node scripts/check-pr-changelog.mjs --base origin/main- passed.git diff --check origin/main...HEAD- passed.Summary by cubic
Improves prompt cache correctness across OpenAI-compatible and Bedrock lanes to boost cache hits and accurate usage/TTL reporting. Aligns Kimi usage accounting, OpenRouter cache-control and affinity, and Bedrock TTL behavior.
New Features
supportsPromptCacheKey; sends a clampedprompt_cache_keyfor Moonshot/Kimi when caching is on.x-session-idand bodysession_id.anthropic/,qwen/, andgoogle/prefixes (handles one leading~).Bug Fixes
usage.cached_tokensas cache-read tokens without changing precedence.claude-sdk-oauthmodel shape.Written for commit 1014c26. Summary will update on new commits.