Skip to content

A rate limit, an empty account or a refused model is not a refused key; error.detail says why and whether a retry can succeed - #734

Open
eric-epsilla wants to merge 1 commit into
HarnessRouter:mainfrom
eric-epsilla:provider-failure-reason
Open

eric-epsilla wants to merge 1 commit into
HarnessRouter:mainfrom
eric-epsilla:provider-failure-reason

Conversation

@eric-epsilla

Copy link
Copy Markdown
Contributor

The problem

When the provider turns down an install's own connection, every answer that matches _PROVIDER_REFUSAL_RE is worded as a refused key: 401, 403, 429, "rate limit" and "quota" alike. Three of those are not the key at all:

  • A rate limit partway through a task. Waiting would have fixed it.
  • An account with no quota or credit left. OpenAI sends insufficient_quota as a 429.
  • A model the provider will not serve for this key. The same key works on another model.

Each one sends people to check a key that works. The failed response's error also gives a client with automatic retries nothing machine-readable to tell "retry later" from "stop". It carries turn_failed plus the base and tool, so the only signal is the message's wording.

Reproduced on main (93994cf):

stops: True | Your tokenrouter key was refused: tokenrouter: 429 Too Many Requests
stops: True | Your tokenrouter key was refused: Error code: 429 - {'error': {'code': 'insufficient_quota'}}
stops: True | Your tokenrouter key was refused: 403: your key is not allowed to use model claude-opus-5
error: {'type': 'harness_error', 'code': 'turn_failed', 'message': 'Your tokenrouter key was refused: …', 'detail': {'base': 'hermes'}}

The fix

_provider_refused still decides that the turn stops on this connection, with the same effect as before, including the relay exception from #714. The new _provider_failure_kind changes what the turn says:

The provider's first line The message error.detail adds
401, 403, invalid key, forbidden "Your key was refused: …" (unchanged) reason: provider_key_refused, retryable: false
429, rate_limit " rate-limited this task (too many requests for now; your key was not refused). Wait a minute and try again. …", or the wait the provider named reason: provider_rate_limited, retryable: true, retry_after_seconds when named
insufficient_quota and similar "Your account has no quota or credit left …; add credit with …" reason: provider_quota_exhausted, retryable: false
does not have access to model, not allowed to use model, model_not_found " refused this model for your key (the key itself was accepted). Choose another model, or enable this one …" reason: provider_model_refused, retryable: false
  • The code stays turn_failed. The new fields sit in detail beside base and tool (Errors §1, "structured extra context"), so no client that reads the code sees a change.
  • The detail carries none of the provider's text.
  • An Entra connection is still called a connection.
  • The rule now also reads rate_limit. A bare "too many requests" stays off it, because Entra's own throttling answers a 502 with "AADSTS90055: Too many requests." That is a sign-in failure, and it still moves on as before. test_entra_failing_is_not_a_refusal_of_the_connection caught this.

Verified

$ python -m pytest -q gateway/tests/test_provider_failure_reason.py
29 passed in 0.70s

Against main's app.py:

28 failed, 1 passed

The one that passes is the check that other failures add nothing.

The tests that already covered this path all pass: test_turn_failure_message, test_failure_detail, test_entra_connection, test_relay_401_is_not_a_key_refusal and test_memory_provisioning, 120 tests in total.

The full gateway suite on this branch:

13 failed, 3058 passed, 13 skipped

The 13 failures are all in test_database_mcp.py, and the same 13 fail on main on my machine, which has no database server for those tests. main's CI is green on them.

🤖 Generated with Claude Code

… is said as that, not as a refused key; error.detail says why and whether a retry can succeed

_PROVIDER_REFUSAL_RE matched 429, "rate limit" and "quota" the same as 401 and an invalid key, so each
read "Your <provider> key was refused". The rule still decides that the turn stops on this connection
(_provider_refused, unchanged in effect), and _provider_failure_kind tells the four apart:

- refused (401, 403, invalid key, forbidden): "Your <provider> key was refused: ...", unchanged.
- rate limit (429, rate_limit): the key was not refused; wait, with the provider's own wait when its
  line names one.
- quota (insufficient_quota and the like, which OpenAI sends as a 429): add credit with the provider.
- model (does not have access to model, not allowed to use model, model_not_found): the key was
  accepted; choose another model or enable this one.

error.detail gains reason (provider_key_refused, provider_model_refused, provider_quota_exhausted,
provider_rate_limited), retryable (rate limit only) and retry_after_seconds when named, beside base and
tool. The code stays turn_failed. The rule now also reads rate_limit; a bare "too many requests" stays
off it, since Entra's own throttling says that on a sign-in that moves on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
unified-harness-protocol Ready Ready Preview Nov 22, 2026 1:26pm UTC

Request Review

@eric-epsilla

Copy link
Copy Markdown
Contributor Author

@richard-epsilla could you review this when you have a moment?

Problem. When the provider turns down an install's own key, a rate limit, an empty account and a model the provider won't serve for that key all read "Your key was refused". People go and check a key that works. A client with automatic retries also has nothing machine-readable to tell "retry later" from "stop".

Approach. Whether the turn stops on that connection is unchanged. Only the wording changes, by cause, and error.detail gains reason, retryable and, when the provider names a wait, retry_after_seconds. These sit beside the existing base and tool. The code stays turn_failed, so nothing that reads the code changes.

What I'd like from you:

  1. Check the four reason names: provider_key_refused, provider_model_refused, provider_quota_exhausted and provider_rate_limited. They are easy to rename now and hard to rename after a release.
  2. Decide whether these should go into a later protocol version (Errors §3.3/§4), so other servers report them the same way. I have not touched protocol/.
  3. Decide whether a rate limit should keep stopping the turn on this connection, as it does today. Moving on to the next connection would rerun the task's work on another key, so I kept today's behaviour.
  4. If the answers are as written, merge once CI is green.

This branch was successfully deployed

1 active deployment
Preview — b3f56b9d Deployed Nov 22, 2026 by vercel[bot]
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