fix(acp): dead-letter auth errors immediately with re-auth hint#2751
Merged
Conversation
Auth-class errors (expired OAuth token, HTTP 401) are non-retryable: the token won't self-repair between attempts, so requeueing only wastes 10 retry slots and delays the visible failure by a long backoff window. Add is_auth_error() that matches AcpError::AgentError messages containing 'Re-authenticate' or 'API Error: 401' — two narrow patterns observed in Will's canary run. The conservative matching is intentional: a false positive (misclassifying a transient error) silently drops a user message, which is worse than a false negative (extra retries on an auth error). In handle_prompt_result, intercept the failing batch before queue.requeue() for auth-class errors and dead-letter immediately with a notice telling the user to re-authenticate the CLI (e.g. claude /login). The transport/application split in PromptOutcome::Error is untouched; this only changes batch fate after an application-class auth error. 6 tests: is_auth_error classification (Re-authenticate, 401, non-auth AgentError, transport), auth-error dead-letter (no requeue, 0 pending channels), non-auth application error still requeued (1 pending channel). Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Auth-class errors (expired OAuth token, HTTP 401) are non-retryable: the token won't self-repair between attempts. Today,
PromptOutcome::Errorfor an application-class error falls into the genericqueue.requeue()path, burning up to 10 retry slots over a long backoff window before dead-lettering. Will's canary run observed the 401 message being retried repeatedly.Solution
Add
is_auth_error()that classifiesAcpError::AgentErrormessages matching two narrow patterns observed in the field:"Re-authenticate"— emitted by the Claude CLI for expired OAuth tokens"API Error: 401"— present in Claude/Codex HTTP-401 responsesConservative matching is intentional: a false positive (misclassifying a transient error as non-retryable) silently drops a user message, which is worse than a false negative (extra retries on an auth error).
In
handle_prompt_result, a new branch intercepts the failing batch beforequeue.requeue()for auth-class errors and dead-letters immediately, posting a user-visible notice to re-authenticate the CLI (e.g.claude /loginorcodex login).The transport/application split in
PromptOutcome::Erroris untouched — this only changes batch fate after an application-class auth error.Tests
6 new tests in
error_outcome_emission_tests:is_auth_errormatchesRe-authenticatemessageis_auth_errormatchesAPI Error: 401messageis_auth_errorrejects otherAgentErrormessages (usage credits, etc.)is_auth_errorrejects transport errors (I/O, WriteTimeout)handle_prompt_resulthandle_prompt_resultFull
cargo test -p buzz-acp: 598/598 passing.