fix(agents-login): robust credential completion + lifecycle logging#732
Merged
Conversation
…logging The worker still hung after redirect submission in production: its completion detection did not match the real claude setup-token output (OSC8 hyperlink / surrounding text), so it never captured or POSTed and the session stayed awaiting_url. With no logging it was a black box. - Parse the Claude OAuth token from bare output, surrounding text, and OSC8 hyperlink targets; fall back to $HOME/.claude/.credentials.json. - Bounded post-redirect timeout transitions the session to failed (with a redacted output tail) instead of hanging forever. - Single happy-path POST to agents-api; capture/POST failures -> failed. - Redacted structured logging across the session lifecycle (no token values) so prod failures are diagnosable.
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.
Symptom
After pasting the Claude redirect URL the session never reached
succeededand nothing was stored (re-submits returned 400 "authorization code already submitted"). Prod evidence: agents-api received onlyGET /sessions/{id}polls and never the worker'sPOST /api/v1/internal/credentials, and the worker logged nothing past startup.Root cause
The worker's completion detection didn't match the real
claude setup-tokenoutput (the token arrives in an OSC8 hyperlink / surrounded by text, not a plain success line), so capture/finalize/POST never ran and the session hung inawaiting_url. No logging made it a black box.Fix
$HOME/.claude/.credentials.json.failed(with a redacted output tail) instead of hanging forever.failedwith reason.Tests
Failing-first: OSC8 token completion, credentials-file fallback (no stdout token), timeout→failed, bare-token parse, plus logging-redaction tests. Suite: 86 tests + typecheck + lint pass.