Skip to content

fix(agents-login): robust credential completion + lifecycle logging#732

Merged
ExtraToast merged 1 commit into
mainfrom
fix/credential-finalize-observability
Jun 25, 2026
Merged

fix(agents-login): robust credential completion + lifecycle logging#732
ExtraToast merged 1 commit into
mainfrom
fix/credential-finalize-observability

Conversation

@ExtraToast

Copy link
Copy Markdown
Owner

Symptom

After pasting the Claude redirect URL the session never reached succeeded and nothing was stored (re-submits returned 400 "authorization code already submitted"). Prod evidence: agents-api received only GET /sessions/{id} polls and never the worker's POST /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-token output (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 in awaiting_url. No logging made it a black box.

Fix

  • Parse the Claude OAuth token from bare output, surrounding text, and OSC8 hyperlink targets; fall back to reading $HOME/.claude/.credentials.json.
  • Bounded post-redirect timeout → failed (with a redacted output tail) instead of hanging forever.
  • Single happy-path POST to agents-api; capture/POST failure → failed with reason.
  • Redacted structured lifecycle logging (never the token value) so any future failure is visible in pod logs.

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.

…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.
@ExtraToast ExtraToast added the bug Something isn't working label Jun 25, 2026
@ExtraToast ExtraToast self-assigned this Jun 25, 2026
@ExtraToast ExtraToast merged commit ae2f03f into main Jun 25, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant