fix(exec): detect auth failures in stderr and abort early (#285) - #322
Merged
Conversation
When subscription tokens expire, Claude Code sometimes hangs instead of failing fast. This wastes execution slots for up to an hour before the watchdog recovers them. Changes: - Add _is_auth_failure_message() pattern matcher in agent server - Scan stderr in real-time during execute_headless_task - Kill process immediately when auth failure pattern detected - Return HTTP 503 (Service Unavailable) for auth failures - Backend detects 503 and sets error_code=AUTH for structured handling - Add fallback heuristics: auth pattern in stderr, zero tokens processed The fix enables fast-fail (seconds instead of hours) when tokens expire. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.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.
Summary
error_code=AUTHProblem
When subscription tokens (CLAUDE_CODE_OAUTH_TOKEN) expire, Claude Code sometimes hangs instead of failing fast. This wastes execution slots for up to an hour before the watchdog recovers them. Issue #285 reports some executions fail in ~3 minutes (correct) while others hang for the full timeout (bug).
Solution
Detect auth failure patterns in stderr during execution (not after) and abort immediately:
_is_auth_failure_message()pattern matcher scans for "token expired", "unauthorized", etc.read_stderr()thread checks each line and sets abort event if pattern founderror_code=TaskExecutionErrorCode.AUTHTest Plan
pytest tests/test_auth_failure_detection.py -vCloses #285
🤖 Generated with Claude Code