Skip to content

Preserve Anthropic streaming input and cache token usage - #1105

Open
jihtsan wants to merge 1 commit into
patterns-ai-core:mainfrom
jihtsan:codex/1103-preserve-anthropic-stream-usage
Open

jihtsan wants to merge 1 commit into
patterns-ai-core:mainfrom
jihtsan:codex/1103-preserve-anthropic-stream-usage

Conversation

@jihtsan

@jihtsan jihtsan commented Nov 1, 2026

Copy link
Copy Markdown

Closes #1103.

Seed streaming usage from message_start, then apply each message_delta's non-nil cumulative fields in order. This preserves input/cache counts, explicit zero updates and untouched nested metadata without adding cumulative output counters. Keep the latest provided stop reason while retaining ordinary text/tool/thinking reconstruction and nonstream behavior. Add a changelog entry.

Validation on Ruby4.0.9/macOS arm64 with real Anthropic1.82.0 and offline fixture transport:

  • Original provider/response baseline:27 examples passed. New corrected regressions on base:31 examples,6 failures.
  • Final provider, response, Anthropic adapter/message and full Assistant specs:149 examples,0 failures,1 existing pending Ollama case. Repository fixtures verify text5+10=15, thinking12+30=42 and tools472+89=561, plus cache/zero/nil/later cumulative updates.
  • Repository-wide bundle exec standardrb, bundle exec yardoc and git diff --check:passed (existing YARD warnings).
  • Independent Standards and Spec reviews on the submitted SHA.

No tracked Gemfile.lock exists upstream; validation reused the retained generated lock with BUNDLE_FROZEN=true, outside this commit. Full Postgres/vector/provider integration and other Ruby/OS matrices were not run. No live model/API call was needed; hosted CI is not claimed passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic streaming responses drop prompt/cache usage and later cumulative counts

1 participant