[PR #5764] [MERGED] fix: include Anthropic cache tokens in context usage #6922

Closed
opened 2026-10-23 04:14:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5764
Author: @Gunterlie
Created: 9/2/2026
Status: ✅ Merged
Merged: 9/2/2026
Merged by: @Gunterlie

Base: staging ← Head: fix/5763-anthropic-context-usage


📝 Commits (4)

  • ba4b90a fix: include Anthropic cache tokens in context usage
  • 8fd9c34 fix: preserve cache-only Anthropic usage
  • a8d21aa test: cover streamed Anthropic cache usage
  • e89f536 Merge remote-tracking branch 'origin/staging' into fix/5763-anthropic-context-usage

📊 Changes

5 files changed (+129 additions, -18 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/client/src/lib/professor-mari-context-budget.ts (+5 -3)
📝 packages/server/src/services/llm/providers/anthropic.provider.ts (+34 -12)
📝 scripts/regressions/open-issues.regression.ts (+20 -0)
📝 scripts/regressions/provider-compat.regression.ts (+69 -3)

📄 Description

$Fixes #5763\n\n## Summary\n- Persist Anthropic cache-read and cache-write input token usage for streamed and non-streamed responses.\n- Include cached prompt tokens in the active context indicator.\n- Add regression coverage for long cached contexts.\n\n## Why\nAnthropic reports cached prompt input separately from fresh input. The indicator previously showed only the fresh portion, so long chats could show values such as 3.5k even when the model received a much larger active context.\n\n## Known limitation\nExisting assistant messages from older builds do not contain the omitted cache fields. A new generation after this fix stores the complete usage data.\n\n## Test plan\n- [x] Run the focused open-issue regression.\n- [x] Run lint, type checks, localization checks, and formatting checks through pnpm check until the production build.\n- [ ] Manually verify a long cached Anthropic chat in the browser.\n- [ ] Manually verify the indicator in light mode, dark mode, and a mobile viewport.\n- [ ] Confirm all required CI checks and CodeRabbit review.\n\nThe client production build exceeded the local 120-second command timeout after the server build completed. It did not report a compile error.

Summary by CodeRabbit

  • New Features

    • Context usage now includes Anthropic prompt-cache tokens, including cached and cache-write input tokens.
    • Token usage totals combine prompt, cached prompt, cache-write prompt, and completion tokens.
    • Prompt-cache usage is preserved for both streaming and non-streaming responses.
  • Bug Fixes

    • Improved handling of missing token usage data for more accurate context calculations.
  • Tests

    • Added regression coverage for combined context token usage and Anthropic prompt-cache reporting.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5764 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 9/2/2026 **Status:** ✅ Merged **Merged:** 9/2/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `fix/5763-anthropic-context-usage` --- ### 📝 Commits (4) - [`ba4b90a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ba4b90ad9264f84042537efe813f2f25d1c310f0) fix: include Anthropic cache tokens in context usage - [`8fd9c34`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8fd9c34b9f6b869164c6b6abd209b440935b32f9) fix: preserve cache-only Anthropic usage - [`a8d21aa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a8d21aa88c7da407a5b0ff285c64c4eb752dd8b2) test: cover streamed Anthropic cache usage - [`e89f536`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e89f5362bf4506fa23e7e32df6f4c29cc0560f12) Merge remote-tracking branch 'origin/staging' into fix/5763-anthropic-context-usage ### 📊 Changes **5 files changed** (+129 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/client/src/lib/professor-mari-context-budget.ts` (+5 -3) 📝 `packages/server/src/services/llm/providers/anthropic.provider.ts` (+34 -12) 📝 `scripts/regressions/open-issues.regression.ts` (+20 -0) 📝 `scripts/regressions/provider-compat.regression.ts` (+69 -3) </details> ### 📄 Description $Fixes #5763\n\n## Summary\n- Persist Anthropic cache-read and cache-write input token usage for streamed and non-streamed responses.\n- Include cached prompt tokens in the active context indicator.\n- Add regression coverage for long cached contexts.\n\n## Why\nAnthropic reports cached prompt input separately from fresh input. The indicator previously showed only the fresh portion, so long chats could show values such as 3.5k even when the model received a much larger active context.\n\n## Known limitation\nExisting assistant messages from older builds do not contain the omitted cache fields. A new generation after this fix stores the complete usage data.\n\n## Test plan\n- [x] Run the focused open-issue regression.\n- [x] Run lint, type checks, localization checks, and formatting checks through `pnpm check` until the production build.\n- [ ] Manually verify a long cached Anthropic chat in the browser.\n- [ ] Manually verify the indicator in light mode, dark mode, and a mobile viewport.\n- [ ] Confirm all required CI checks and CodeRabbit review.\n\nThe client production build exceeded the local 120-second command timeout after the server build completed. It did not report a compile error. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Context usage now includes Anthropic prompt-cache tokens, including cached and cache-write input tokens. - Token usage totals combine prompt, cached prompt, cache-write prompt, and completion tokens. - Prompt-cache usage is preserved for both streaming and non-streaming responses. - **Bug Fixes** - Improved handling of missing token usage data for more accurate context calculations. - **Tests** - Added regression coverage for combined context token usage and Anthropic prompt-cache reporting. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:14:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6922
No description provided.