Skip to content

fix(exec): detect auth failures in stderr and abort early (#285) - #322

Merged
vybe merged 1 commit into
mainfrom
feature/285-expired-token-fast-fail
Apr 13, 2026
Merged

fix(exec): detect auth failures in stderr and abort early (#285)#322
vybe merged 1 commit into
mainfrom
feature/285-expired-token-fast-fail

Conversation

@vybe

@vybe vybe commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add real-time auth failure detection in agent server stderr scanning
  • Kill Claude Code process immediately when expired token patterns detected
  • Return HTTP 503 so backend can classify as error_code=AUTH
  • Add fallback heuristics: auth pattern in stderr, zero tokens processed

Problem

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:

  1. _is_auth_failure_message() pattern matcher scans for "token expired", "unauthorized", etc.
  2. read_stderr() thread checks each line and sets abort event if pattern found
  3. Process is killed immediately, HTTP 503 returned
  4. Backend detects 503, sets error_code=TaskExecutionErrorCode.AUTH

Test Plan

  • Unit tests for pattern matcher: pytest tests/test_auth_failure_detection.py -v
  • Manual: Configure agent with expired token, verify fails in seconds not hours
  • Verify watchdog still recovers executions that slip through

Closes #285

🤖 Generated with Claude Code

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>
@vybe
vybe merged commit 85121f6 into main Apr 13, 2026
vybe added a commit that referenced this pull request Apr 14, 2026
Shipped:
- #95 (PR #320) - unified TaskExecutionService
- #285 (PR #322) - auth failure fast-fail
- #226 (PR #323) - per-agent slot TTL
- #286 (PR #324) - preserve error context

Remaining: #61, #132, #56

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

bug: expired subscription token causes hour-long zombie executions instead of fast failure

1 participant