Skip to content

Gateway: a provider's refusal of the key stops the task at once and says why at the top - #808

Merged
richard-epsilla merged 4 commits into
mainfrom
fix/har112-relay-refusal
Dec 2, 2026
Merged

richard-epsilla merged 4 commits into
mainfrom
fix/har112-relay-refusal

Conversation

@github-actions

@github-actions github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

What changes

When a model provider refuses the key a task runs on, the task now stops at once and says why at the top of the response, with the next step.

Before this, such a task looked like any other failed task. Its reason was the agent's own report of the error (for example "The model provider refused the request (403: Forbidden.)"). It named the provider by an internal id ("Your tokenrouter key") and said nothing about what to do.

  • Read at the model call. The gateway reads the provider's own error body on a model call that answers 400/401/402/403/404/429. It records a refusal that no retry can change:

    • the key was refused;
    • no credit or quota is left (402, or an empty account's code on 400/403/429);
    • the model was refused for this key.

    A rate limit is not recorded. The provider's words are kept without any part of the key. The agent still gets the answer as it came. The record lives in the process and in the control store (both backings), so any process's turn sees it.

  • The turn stops on it. This happens only when the refusal is for the turn's own model on its own connection and came after the turn started. A turn that ended first, failed in its own words, or "completed" with nothing from the model still fails with the refusal. A turn that answered is left as it was.

  • The message names the provider as Bring Your Own Key does ("TokenRouter") and says the next step. error.detail adds provider, status, model and connection to reason and retryable. The stream's error event carries the same detail.

  • Better reading of the runner's line. 402, "credit balance is too low", and a credit code in the body under a refusal's first line now mean no credit, not a refused key or a rate limit.

  • Protocol docs. Errors §3.4 describes the detail fields (additive, no new code). The retry table says a failed task with retryable: false is not worth retrying. Streaming lists detail on the error event.

Tests

  • gateway/tests/test_relay_refusal.py is new, with 38 tests:
    • reading and classifying the provider's body; the key never kept;
    • the turn stopping at once, and a turn that ended first or "completed" with nothing;
    • a side model's refusal leaving the turn running; the platform's own route never affected;
    • one task's refusal never read by another;
    • the connection-name alignment with the sandbox credential;
    • a refusal through the broker end to end, handed back to the agent unchanged.
  • Updated wording tests: test_provider_failure_reason, test_turn_failure_message, test_entra_connection.
  • The full gateway suite on this branch and on main fails the same 19 tests, which need ffmpeg and aren't affected by this change. 4321 pass on this branch vs 4283 on main.

🤖 Generated with Claude Code

… call passes, stops the task at once and says why at the top

A task whose provider refused its key looked like any other failed task. Its reason was the runner's
reading of what the agent printed ("The model provider refused the request (403: Forbidden.)"), named
the provider by its wiring's id ("Your tokenrouter key"), and said nothing of what to do; an agent that
retried, stopped quietly or answered in its own words left less.

- The broker reads the provider's own error body on a model call's 400/401/402/403/404/429 and records,
  for the task, a refusal no retry can change: the key refused, no credit or quota left (402, or an
  empty account's code on 400/403/429), or the model refused for the key. A rate limit is not recorded.
  The provider's words are kept without any part of the key. The agent still gets the answer as it came.
  The record lives in the process and in the control store (both backings), so any process's turn sees it.
- The turn stops on it at once (the runner told to cancel) when it is the turn's own model on its own
  connection, made after the turn started. An agent that ended first, failed in its own words or
  "completed" with nothing from the model, still fails with it; one that answered is left as it was.
- The message names the provider as Bring Your Own Key does ("TokenRouter") and says the next step;
  error.detail adds provider, status, model and connection to reason and retryable; the stream's
  error event carries the detail too.
- The runner's line is read better: 402, "credit balance is too low", and a credit code in the body
  under a refusal's first line are no credit, not a refused key or a rate limit.
- Protocol: Errors §3.4 describes these detail fields (additive, no new code), the retry table says a
  failed task with retryable false is not worth retrying, Streaming lists detail on the error event.

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

vercel Bot commented Dec 2, 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 Dec 2, 2026 1:18am UTC

Request Review

Comment thread gateway/app.py Dismissed
Comment thread gateway/app.py Dismissed
Comment thread gateway/app.py Dismissed
richard-epsilla
richard-epsilla previously approved these changes Dec 2, 2026

@richard-epsilla richard-epsilla left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed: same change as the hosted gateway release b135bc2cb (read back on production 12-02: a refused own key fails at once as provider_key_refused with the next step; the key never appears in the error, the stream or the log). Suite: same 19 ffmpeg-dependent failures as main; 38 new tests pass.

@richard-epsilla richard-epsilla left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-approved after merging main (one CHANGELOG conflict: both new entries kept). All required checks and CodeQL pass on 9d0363d.

@richard-epsilla
richard-epsilla merged commit d85388a into main Dec 2, 2026
17 checks passed

This branch was successfully deployed

1 active deployment
Preview — 9d0363d0 Deployed Dec 2, 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.

2 participants