Skip to content

fix(scheduler): detect auth-failure markers in session output#243

Open
brianjones-v4n wants to merge 1 commit into
JKHeadley:mainfrom
brianjones-v4n:fix/scheduler-detect-auth-failure-in-output
Open

fix(scheduler): detect auth-failure markers in session output#243
brianjones-v4n wants to merge 1 commit into
JKHeadley:mainfrom
brianjones-v4n:fix/scheduler-detect-auth-failure-in-output

Conversation

@brianjones-v4n
Copy link
Copy Markdown
Contributor

Summary

Claude Code exits cleanly (status completed, exit code 0) on a 401 / invalid-auth response. Without scanning the captured session output, the scheduler records these silent auth failures as successes — the job appears healthy while authentication is actually broken.

This adds a post-completion scan of the last 4 KB of session output against well-known auth-failure regex landmarks:

  • 401 Unauthorized / 401 ... authentication
  • Invalid (authentication|API key|bearer token|x-api-key)
  • Unauthorized
  • OAuth token has expired / is invalid / expired / missing
  • API key not valid / found / provided
  • Please (re-)?authenticate

On hit:

  • Override failed = true
  • Surface the matched fragment as the error reason in runHistory.recordCompletion's error field
  • Same reason flows into the persisted lastError for the job

Test plan

  • Test asserts the AUTH_FAILURE_PATTERNS const exists at module scope with expected regex landmarks
  • Test asserts the completion handler uses let failed so the override is possible
  • Test asserts the scan reads only the last 4 KB of output
  • Test asserts the auth-failure reason flows into both error and lastError
  • npx tsc --noEmit — no new errors (9 pre-existing errors unchanged)

🤖 Generated with Claude Code

Claude Code exits cleanly on 401 / invalid-auth responses, leaving
session.status = 'completed'. Without scanning the output, the
scheduler records these silent failures as successes — the job
appears healthy while auth has actually broken.

Scan the last 4 KB of captured output against a set of well-known
auth-failure regex landmarks (401 Unauthorized, "Invalid API key",
"Please re-authenticate", expired OAuth tokens, etc.). On hit,
override failed = true and surface the matched fragment as the
error reason in both runHistory.recordCompletion and the persisted
lastError field.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

@brianjones-v4n is attempting to deploy a commit to the sagemind Team on Vercel.

A member of the Team first needs to authorize it.

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