Recognize sign-in failures for every agent and fall through #19
Reference in New Issue
Block a user
Delete Branch "fix/agent-sign-in-failures"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
On lead/memona-home#36 (Actions job 9837), the bot failed with "AI bot failed. > Profile: none · all profiles failed" and never posted the Codex sign-in comment. The staged Codex
auth.jsonheld a token the server had revoked.codex login statusonly reads the local file, so it passed.codex execthen failed withrefresh_token_invalidated, "Your session has ended. Please log in again.",token_revokedand401 Unauthorized.retryInvalidTokenonly matchedinvalid_refresh_token, so device login never ran. The failure also wasn't classified as usage exhaustion, so Claude and OpenCode were never tried.What each CLI emits on rejected credentials (checked against the real CLIs)
refresh_token_invalidated|expired|reused,token_revoked,401 Unauthorized, "log/sign in again", andinvalid_api_keyfor API keys. Codex also echoes the full prompt and tool output to stderr.CLAUDE_CODE_OAUTH_TOKEN): exits 1 with empty stderr. The stream-jsonresulthasis_error: true,api_error_status: 401and "Failed to authenticate. API Error: 401 OAuth access token is invalid."{"type":"error","error":{"name":"APIError","data":{"statusCode":401,"message":"User not found."}}}. Before this change the bot only reported "opencode exited with 1".Changes
isCodexAuthFailurematches those auth markers only on Codex's ownERRORlines, and the runner strips the echoed prompt first, so quoted logs in PR comments or tool output can't trigger a device login. A matching failure re-runs logout and device login, which posts the sign-in comment, then retries once.isClaudeAuthFailureclassifiesis_errorresults byapi_error_status: 401or by the auth message text.openCodeErrorreads OpenCode's stdout error events. A 401 or 403 becomes a sign-in failure. Other errors are surfaced asopencode APIError (API error N): message, so OpenRouter 402 and 429 now count as usage exhaustion.AgentAuthErroris thrown once credentials are rejected and any re-login has been used up. A device login that fails or times out also counts.runProfilesfalls through on it just as it does for usage exhaustion, and still throws the last error if every profile fails.> Tried: `codex` · `gpt-5.6-terra` (sign-in failed), `claude` · `claude-sonnet-5` (usage exhausted).post.tsaccepts only known types and labels from the outcome file, so no raw agent output or secret can reach the comment.Tests
Added tests covering the verbatim job 9837 stderr lines, the other Codex refresh-token errors, the ERROR-line anchoring, Claude and OpenRouter auth errors, fall-through with failure recording, and comment sanitization.
deno fmt --check .,deno lint .,deno checkanddeno test --allow-allall pass (58 tests).Note
The bot still runs Codex first with the revoked login. With this change merged, the bot should post a device-login comment and then fall back to Claude. Until then, the
@botreview on this PR may fail the same way.🤖 Generated with Claude Code
@bot
AI bot failed.