fix: pin fixed anthropic/fantasy forks for streaming token accounting#24077
fix: pin fixed anthropic/fantasy forks for streaming token accounting#24077ibetitsmike merged 8 commits intomainfrom
Conversation
77b0fa0 to
e24093f
Compare
Pin coder/anthropic-sdk-go with explicit JSON presence checks in Accumulate() so input and cache tokens from message_start are preserved when message_delta omits them. Also wire async title generation to record its token usage (it was previously discarded via underscore) using the same recording path already used by manual title regeneration, and resolve the title model's DB config so usage appears under the correct model on the usage page.
e24093f to
96049a0
Compare
…tern Remove the Alert component wrapper and use the same inline icon-plus-text pattern as the unpriced messages warning. Position the note directly below that warning.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 478a83f6b3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Manual title regeneration still records usage via recordManualTitleUsage, so the disclaimer should clarify that only automatic title generation is excluded.
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20e510a797
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // 2) Explicit usage-field merging in Accumulate using JSON presence checks | ||
| // (preserves input and cache tokens from message_start when message_delta | ||
| // omits them). | ||
| replace github.com/charmbracelet/anthropic-sdk-go => github.com/coder/anthropic-sdk-go v0.0.0-20260408163834-8345653c189a |
There was a problem hiding this comment.
Use a publicly resolvable anthropic-sdk-go replacement
Pinning github.com/charmbracelet/anthropic-sdk-go to github.com/coder/anthropic-sdk-go makes dependency resolution fail in a default Go environment (GOPROXY=https://proxy.golang.org,direct), which blocks go test/go mod download for affected packages; in this review environment, fetching that pseudo-version returns HTTP 403 from the proxy. This is a build-breaking regression for contributors or CI jobs that do not have GOPRIVATE and credentials configured for github.com/coder, so the replacement should point to a proxy-resolvable module/version (or otherwise avoid introducing a private-only dependency in the default build path).
Useful? React with 👍 / 👎.
Summary
Fixes Anthropic streaming token accounting so input, output, and cache token counts match what the Anthropic console reports.
Changes
Streaming token fix (dependency layer)
Pins
coder/anthropic-sdk-goto a fork commit that fixes the SDK'sAccumulatemethod. The original SDK was clobberinginput_tokens,cache_creation_input_tokens, andcache_read_input_tokenswhen processingmessage_deltaSSE events because Anthropic only sendsoutput_tokensin those deltas. The fix uses JSON presence checks (Raw() != respjson.Omitted) to merge only fields actually present in the delta, preserving the values frommessage_start.Regression tests (Coder layer)
coderd/x/chatd/chattest/anthropic.go: Added cache token fields toAnthropicUsageand a newAnthropicTextChunksWithCacheUsagehelper for realistic SSE fixtures.coderd/x/chatd/chattest/anthropic_test.go: Integration test proving cache tokens survive accumulation.coderd/x/chatd/chatloop/chatloop_test.go: Pipeline test assertingprocessStepStreamcaptures the correct final usage from Anthropic streams.Title generation accounting (removed)
Reverted automatic title generation token recording. These tokens use lightweight models (Haiku, GPT-4o Mini) with negligible cost, and recording them as hidden messages skewed per-chat usage metrics. Manual title regeneration still records usage as before.
Usage disclaimer
ChatCostSummaryView.tsx) stating that title generation is not counted towards usage limits.docs/ai-coder/agents/platform-controls/usage-insights.mddocumenting the exclusion.