Skip to content

fix(conductor): skip auth suspension for count_tokens 404s#2895

Open
ArcaneOrion wants to merge 1 commit into
router-for-me:devfrom
ArcaneOrion:fix/count-tokens-404-suspend
Open

fix(conductor): skip auth suspension for count_tokens 404s#2895
ArcaneOrion wants to merge 1 commit into
router-for-me:devfrom
ArcaneOrion:fix/count-tokens-404-suspend

Conversation

@ArcaneOrion
Copy link
Copy Markdown

Summary

  • Non-Anthropic upstreams return 404 for /v1/messages/count_tokens because they don't
    support this Anthropic-specific endpoint
  • The conductor treated these 404s as "model not found" and suspended auths for 12 hours,
    causing cascading 503 errors for ALL requests on that model
  • Skip MarkResult for 404 errors in executeCountMixedOnce so count_tokens failures
    don't trigger auth suspension

Test plan

  • TestManagerExecuteCount_404DoesNotSuspendAuth — verifies count_tokens 404 does not
    suspend auth and subsequent Execute still succeeds
  • Full sdk/cliproxy/auth/... test suite passes with no regressions

Non-Anthropic upstreams (e.g. third-party proxies) don't support the
/v1/messages/count_tokens endpoint and return 404. The conductor treated
this as "model not found" and suspended the auth for 12 hours, blocking
ALL subsequent requests for the same model with 503 errors.

Skip MarkResult for 404 errors in executeCountMixedOnce so count_tokens
failures don't trigger auth suspension. Other status codes (401, 429, 500,
etc.) continue to be recorded normally.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

This pull request targeted main.

The base branch has been automatically changed to dev.

@github-actions github-actions Bot changed the base branch from main to dev April 18, 2026 11:04
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that 404 errors from count_tokens endpoints on non-Anthropic upstreams do not trigger a 12-hour authentication suspension. The logic now skips MarkResult for these specific errors and includes a new test case to verify the behavior. One piece of feedback notes that bypassing MarkResult also skips result hooks, which could lead to a loss of observability for these events; it is suggested to call the hooks directly or refactor the result marking logic.

Comment on lines +1400 to +1407
if result.Error.HTTPStatus != http.StatusNotFound {
m.MarkResult(execCtx, result)
} else {
logEntryWithRequestID(execCtx).Debugf(
"skipping MarkResult for count_tokens 404 on auth=%s model=%s: %s",
auth.ID, upstreamModel, errExec.Error(),
)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While skipping MarkResult for 404 errors correctly prevents the 12-hour auth suspension for unsupported count_tokens endpoints, it also bypasses the m.hook.OnResult call. This means these failures will not be visible to any registered hooks (e.g., for metrics, logging, or auditing). If observability for these events is required, consider calling m.hook.OnResult directly or refactoring MarkResult to support a flag that skips suspension while still processing the result for hooks.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 92c2f75f63

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1400 to +1401
if result.Error.HTTPStatus != http.StatusNotFound {
m.MarkResult(execCtx, result)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict 404 bypass to unsupported count endpoint cases

The new if result.Error.HTTPStatus != http.StatusNotFound guard skips MarkResult for all count-token 404s, not just the non-Anthropic "404 page not found" unsupported-endpoint case described in the commit message. In executeCountMixedOnce, this also suppresses model cooldown updates for legitimate model-not-found 404s (for example, stale registry entries against providers that use 404 for missing models), so the same bad auth/model pair keeps being selected and failing on subsequent ExecuteCount calls instead of being temporarily suspended.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This prevents /v1/messages/count_tokens 404s (common for non-Anthropic upstreams that don’t implement the Anthropic-specific endpoint) from being treated as “model not found” and triggering a 12-hour auth/model suspension that can cascade into 503s for normal traffic on the same model.

What changed

  • In executeCountMixedOnce, skip MarkResult when CountTokens returns HTTP 404, and emit a debug log instead.
  • Add a regression test TestManagerExecuteCount_404DoesNotSuspendAuth to verify a count_tokens 404 does not suspend/cooldown the auth and that a subsequent Execute still succeeds.

Notes (non-blocking)

  • Skipping MarkResult means hook.OnResult won’t see these 404s; if you rely on hooks for metrics/monitoring, consider recording count_tokens 404s via a separate path that doesn’t affect auth state.
  • The debug log includes errExec.Error(); please ensure CountTokens error strings cannot contain sensitive data.

Test plan

  • go test ./sdk/cliproxy/auth/...
  • go test ./...

This is an automated Codex review result and still requires manual verification by a human reviewer.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants