Skip to content

fix(login): show device code immediately so /login no longer hangs - #3

Merged
wangcansunking merged 3 commits into
masterfrom
worktree-fix-login-deadlock
Jun 25, 2026
Merged

wangcansunking merged 3 commits into
masterfrom
worktree-fix-login-deadlock

Conversation

@wangcansunking

Copy link
Copy Markdown
Owner

Summary

Typing /login in the TUI produced no output and hung. Root cause: the slash-command dispatcher only renders a command's resolved return value, but the /login handler blocked in pollForToken (an infinite poll loop) before returning — so the device code/URL was buffered behind the poll and never shown. The user couldn't authorize a code they couldn't see → deadlock.

Fix

  • src/cli/auth.ts — split device login into two phases: beginDeviceLogin() returns the DeviceCode immediately + a complete() thunk that does the blocking poll + token write. runDeviceLogin now reuses these (still used by the startup path and the copilot-reverse login CLI subcommand).
  • src/tui/app.tsx — new login? prop + a non-blocking /login branch (modeled on the existing /model special case): it pushes the verification URL + code to the UI immediately, then renders a completion/error card when the background poll resolves.
  • src/cli/index.ts — wires the App login prop via beginDeviceLogin; refreshes CopilotTokenStore after re-login so the model picker keeps working once the old Copilot token rotates (caught in review).

Tests

  • tests/cli/auth.test.ts — new two-phase test: code is returned before any poll runs.
  • tests/tui/app-interaction.test.tsx — new regression test: device code renders while the token poll is still pending (holds a gate open, asserts the code is on-screen, then releases).
  • Both were written failing first (TDD), then made green.

Verification

  • npm test → 238 passed (47 files), up from 236
  • npm run test:e2e → 31 passed (4 files)
  • tsc build clean
  • Independent code review pass; one real finding (stale token store) fixed, one declined (would have broken existing slash.test.ts coverage).

Includes a patch changeset.

🤖 Generated with Claude Code

wangcansunking and others added 3 commits June 25, 2026 12:40
/login produced no output and deadlocked: the slash dispatcher only
renders a command's resolved value, but the handler blocked in
pollForToken before returning, so the device code stayed hidden and the
user could never authorize it.

Split device login into beginDeviceLogin (returns the code at once) +
complete() (polls), and give the TUI a non-blocking /login branch that
renders the verification URL + code first, then a completion card. Also
refresh the CopilotTokenStore after re-login so the model picker keeps
working once the old Copilot token rotates.

Co-Authored-By: Claude <noreply@anthropic.com>
A rejected device-code poll (e.g. incorrect_device_code) previously
escaped as an unhandled rejection and killed the process. Surface it as
an error card with a clean message (strip the Error: prefix), and guard
against a double Enter starting two concurrent device-code flows — the
second code supersedes the first, so polling the first 401s.

Co-Authored-By: Claude <noreply@anthropic.com>
After /logout (or an expired login), sending a chat message fired a
request that just hung until the 120s turn timeout, then printed an
opaque "no response". Add an optional pre-flight auth gate to makeOnChat
that runs before each turn; production wires it to the long-lived
tokenStore so a valid login is a cached, round-trip-free check, while a
missing/expired token blocks the turn immediately with a "run /login"
hint.

Co-Authored-By: Claude <noreply@anthropic.com>
@wangcansunking
wangcansunking merged commit 3d435a7 into master Jun 25, 2026
3 checks passed
@wangcansunking
wangcansunking deleted the worktree-fix-login-deadlock branch June 25, 2026 07:26
wangcansunking added a commit that referenced this pull request Jun 29, 2026
…plate, config, banner (#15)

* feat(tui): scope+model status, chat-setup confirmation, parity, report template, config, banner

- #6 /status + HUD show each client's scope AND pinned model, not a bare check
- #5 chat setup_claude/codex require scope+model (ask first, never assume)
- #7 add recent_errors + metrics chat tools to match slash commands
- #4 /report body follows the #5 template (Summary/Environment/Repro)
- #3 GitHub heartbeat interval/delay now configurable via AppConfig
- #1 versioned "what's new" banner, shown ~3 launches then suppressed
- #2 README reflects guards, runaway reporting, scope+model, config knobs

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(report): add #5-style issue template; banner = major changes only

- .github/ISSUE_TEMPLATE/bug.yml (Summary/Environment/Repro/Diagnostics/fixes) so manual
  issues match the rich #5 shape; /report still auto-fills the same sections.
- what's-new banner trimmed to major changes only (the freeze fix); minor polish dropped.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <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.

1 participant