Skip to content

fix: report an Anthropic token-count failure as an LLM error instead of an SDK traceback - #168

Open
vitali87 wants to merge 1 commit into
fix/non-utf8-file-contentfrom
fix/count-tokens-errors
Open

fix: report an Anthropic token-count failure as an LLM error instead of an SDK traceback#168
vitali87 wants to merge 1 commit into
fix/non-utf8-file-contentfrom
fix/count-tokens-errors

Conversation

@vitali87

Copy link
Copy Markdown
Owner

Summary

_count_tokens_anthropic called client.messages.count_tokens with no error handling. It is the first API call of a split run, so a bad key, an unreachable proxy or a rate limit surfaced as a raw anthropic.AuthenticationError / APIConnectionError traceback rather than the LLMError path _call_anthropic already uses.

anthropic.APIError is now wrapped into LLMError(ErrorMsg.LLM_TOKEN_COUNT_FAILED) at both count call sites (single-shot sizing and chunked overhead). No local fallback estimate: the count uses the same key/host as the planning call, so anything that breaks it breaks the next request too, and the SDK's own retries already absorb transient blips. With #63's PRSplitError guard this becomes a clean red message.

Stacked on #146 (stack #81 = #49#50#69#70#93#105#113#146→this).

Test plan

  • test_api_failure_is_an_llm_error: APIConnectionError from count_tokensLLMError naming the detail; fails on the base
  • Review verified both call sites end to end and that _count_tokens_openai (tiktoken, local) needs nothing
  • 484 tests pass, ruff clean
  • Local review: 5/5

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d27f1025-2b26-4922-9265-f65af53a9f2a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vitali87
vitali87 force-pushed the fix/count-tokens-errors branch from a9a1b9e to 6f604c5 Compare August 30, 2026 19:15
@vitali87
vitali87 force-pushed the fix/count-tokens-errors branch from 6f604c5 to e3e62c4 Compare August 30, 2026 19:16
@vitali87
vitali87 force-pushed the fix/count-tokens-errors branch from e3e62c4 to af449a4 Compare August 30, 2026 19:17
@vitali87
vitali87 force-pushed the fix/count-tokens-errors branch from af449a4 to fa37abf Compare August 31, 2026 01:10
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.

1 participant