Skip to content

fix(website): cancel a pending kiro sign-in once signed in elsewhere - #35176

Merged
bolichen97 merged 1 commit into
mainfrom
fix/34446-cancel-stale-kas-login
Nov 12, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/34446-cancel-stale-kas-login

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: When you start a Kiro sign-in in the dashboard and then sign in some other way, the dashboard ends the sign-in it left waiting instead of polling it unseen.

Start a Kiro sign-in in the dashboard (device code or browser), then finish signing in another way: another tab, or the CLI. The dashboard shows the signed-in view, but the abandoned sign-in keeps calling /api/kas-login/poll every few seconds for as long as the page stays open. The report counted 4 calls in the 16 s after the signed-in view appeared.

Why it matters

Anyone who starts a sign-in in one place and finishes it in another gets a poll loop they cannot see or stop. The gateway keeps that login open until it times out, and for the browser flow that includes its callback port. On the Kiro sign-in card in Settings, Switch account then brings back the old code screen instead of the sign-in choices.

Not a goal

  • Changing the signed-in view itself.
  • An account switch in progress (Switch account): its pending sign-in is kept, as today.
  • Reading the sign-in status more often (it is still read every 30 s).

What changed (motivation → approach → change)

Once the account is signed in some other way, the dashboard now ends the Kiro sign-in it left waiting. Its poll stops, and Switch account on the Settings sign-in card opens the sign-in choices instead of the abandoned code. If ending it fails, the signed-in view says so and offers Try again.

Why it kept polling: the gate shows the signed-in view whenever the status says signed in, and it makes that check first. A pending sign-in is therefore hidden but stays alive, and its poll runs for as long as it exists. Only its own poll answering authorized ever ended it, and that never happens when the sign-in finished in another tab or in the CLI.

When the status says signed in and a sign-in is still pending What the dashboard does
The cancel succeeds The signed-in view, unchanged
The cancel fails (the request never reaches the gateway) The signed-in view plus a notice: the sign-in started here could not be cancelled and stays open until it times out. Try again repeats the cancel; the poll does not come back
An account switch is running Nothing: the switch keeps its pending sign-in

The fix is in website/src/components/KasLoginGate.tsx. With no account switch running and no cancel already settling, the gate drops the pending sign-in and cancels it through settleCancel, the same path the Cancel button uses. That path re-reads the status and clears the cached model list when a sign-in landed, so a sign-in this login completed at that same moment still counts as one. The notice is an ErrorNotice with the agent hand-off, beside the existing "previous sign-in could not be removed" notice. Its one new string is in every shipped language under website/src/i18n/locales/. The Settings card embeds the same flow and behaves the same way. The kas-auth spec says so.

Backwards compatibility

Compatible: nothing a user can do today stops working. A pending sign-in is cancelled only after the status already says signed in, when nothing on screen can reach it any more.

Removes nothing: the only thing dropped is a hidden pending sign-in that the user could no longer see or act on.

Tests

  • KasLoginGate.test.tsx, cancels a pending sign-in and stops its poll once the account signs in elsewhere: starts the device flow, waits for its first poll, then changes the status read to signed in. It checks that the app renders, that the pending login is cancelled exactly once by its id, and that no poll runs in the next 15 s. Red on the parent commit (no cancel, and the poll keeps running), green with the fix.
  • KasLoginGate.test.tsx, says so in the signed-in view when that cancel fails, and retries it from there: the same start, with the first cancel rejected. It checks that the signed-in view shows the notice, that no poll runs in the next 15 s, and that Try again cancels the same login id again and removes the notice once it settles. Red without the notice, green with it.
  • The existing account-switch tests (Start over during an account switch ...) keep a pending sign-in open while the status still says signed in. They stay green, which pins the "no switch running" condition.
  • Determinism: each new test passed 20 runs in a row, and the whole file passed in a shuffled order.

Proof: not provable -- frontend test (prove.py runs Python only)

Manual verification

Ran the real Settings sign-in card (KiroSignInCard) and the full-screen gate (KasLoginGate) in Chromium through Vite, scripted with Playwright, with only the /api/kas-login calls stubbed. Started a Google device sign-in, then made the status read say signed in.

  • Cancel succeeds: no poll call after the status flipped, one cancel for the pending login id, and Switch account showed the sign-in choices. On the parent commit there were 3 poll calls, no cancel, and Switch account showed the old code KWXR-VBTM.
  • First cancel fails: the notice appeared on the card (dark and light) and over the gate, with no poll call after the flip. Try again sent a second cancel for the same login id, and the notice went away.

Screenshots / video

Switch account after signing in elsewhere, before (the abandoned code screen comes back):

before: Switch account shows the abandoned code

After (the sign-in choices):

after: Switch account shows the sign-in choices

The cancel failed: the Settings sign-in card, dark and light:

cancel failed: notice on the sign-in card, dark

cancel failed: notice on the sign-in card, light

The same notice over the full-screen gate, above the dashboard:

cancel failed: notice over the gate

The signed-in view once the cancel settles, the same as before this change

signed-in view

Related Issues

Closes #34446

Sibling sweep

Swept: git grep -nlE "login_id|loginId|user_code|qr_code|qrcode|deviceCode|device_code" -- website/src
Sibling: website/src/pages/settings/WeixinPanel.tsx -- not affected -- its QR stays on screen, and its own poll answer (confirmed, connected or expired) ends the session
Sibling: website/src/pages/settings/WhatsAppPanel.tsx -- not affected -- its QR stays on screen, and its own poll answer (connected, error or expired) ends the session
Sibling: website/src/components/MobileConnectModal.tsx -- not affected -- it reads its status once on open and has no pending sign-in to poll
Sibling: website/src/components/KasLoginGate.tsx -- not affected -- its reset and replaceAttempt cancels already show a failed cancel on the waiting screen

Pattern harvest

Rule candidate: review-prompt
Pattern: a render branch that hides a component's in-flight work (a poll, a listener) must also stop that work

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 11, 2026 08:09
@bolichen97
bolichen97 enabled auto-merge (squash) November 11, 2026 08:18
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 32d69c413d722c1e5bcc1bfda445c698dc97538a — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix reuses settleCancel, the same cancel path the Cancel button uses. The failure notice follows the file's existing rule that a cancel that does not settle is "shown, never swallowed" (KasLoginGate.tsx:485).

What this change ships

Inventory (5 items) — 5 justified

Intent: FIX. If you start a Kiro sign-in in the dashboard and finish signing in somewhere else (another tab or the CLI), the dashboard should stop the sign-in it left waiting instead of polling it unseen (#34446).

  1. When the status says signed in and no account switch is running, the pending sign-in is dropped and cancelled, so its hidden poll stops — justified
  2. Switch account on the Settings sign-in card opens the sign-in choices, not the abandoned code screen — justified
  3. A new notice in the signed-in view when that cancel fails — justified
  4. Try again on that notice repeats the cancel for the same login id — justified
  5. One new i18n string in every shipped language, plus a kas-auth spec paragraph — justified

[FIRST-PRINCIPLES-REVIEWED] 32d69c4

Description read

[DESCRIPTION-READ] 7a1342d728f1ec4d2c437c17a54c455f74d39ebb80295fb9a58d65723a3b9266

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 32d69c413d722c1e5bcc1bfda445c698dc97538a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the pending sign-in is now cancelled through the same settleCancel path the Cancel button already uses, and only when the signed-in view has already hidden it. Screenshots of this revision are attached.

Notes

  • settleCancel also returns 'unknown' when the cancel succeeds but the status read after it fails. In that case the notice says the cancel failed, which is wrong, and Try again re-cancels a login the gateway may already have closed. Check that a second cancel on a closed login settles cleanly rather than leaving the notice stuck.

[DESIGN-REVIEWED] 32d69c4

Description read

[DESCRIPTION-READ] efbe86b9a0659067af15f4aa0f3e818787d6fa95705872aed5bd3d480070dd02

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 32d69c413d722c1e5bcc1bfda445c698dc97538a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing blocks. The new notice says what happened, says it ends by itself, and offers a retry. The only weak spot is the retry button's label, which sits on a rare failure path.

Notes

  • The notice's "Try again" button (components.kiroPrerequisiteGate.try_again, reused from another component) doesn't say what it retries. The blind reader had "no idea" what it does, would not click it, and feared it "might sign me out or start a whole new sign-in". Give it its own label that names the action, such as "Cancel it again".
  • pending_cancel_unsettled leads with "You're signed in, but…", which leaves the reader unsure "if it's a problem". Lead with the consequence instead: "A sign-in started here is still open and will time out on its own. You're signed in."

[UX-REVIEWED] 32d69c4

Description read

[DESCRIPTION-READ] 04ed723397fcafe6e9dc7980a2fa51991c6bd0b7fd606a3d527067ebe5a8f1a5

That sha256 names everything this verdict read: the PR description, plus the 9 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 32d69c413d722c1e5bcc1bfda445c698dc97538a — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 32d69c4

Verdict parsed from the review's SHA-scoped output markers for commit 32d69c413d722c1e5bcc1bfda445c698dc97538a.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 32d69c413d722c1e5bcc1bfda445c698dc97538a false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 32d69c413d722c1e5bcc1bfda445c698dc97538a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 32d69c4

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 32d69c413d722c1e5bcc1bfda445c698dc97538a false-positive: <reason, 20 to 500 characters>

@KiroCrewCaptain

KiroCrewCaptain commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

The PR adds an effect to KasLoginFlow. When the status read says signed in, no account switch is running, no cancel is already in flight, and a session is still pending, it drops the session (which turns off its poll) and cancels it through the existing settleCancel path. A failed cancel shows an ErrorNotice with Try again in the signed-in view. Verified: the backend cancel is idempotent (an unknown or finished id returns 200), so a login that already finished causes no false notice. A sign-in that lands at the same moment still clears the cached model list through settleCancel's landed check. Account switches are excluded, and the switch back-out button only appears when nothing is pending. Start over, Use code instead and Cancel are excluded while their cancel is in flight. The two new tests would fail without the fix. The new string is in en.manual.json and all 12 translated locales, the same way the existing cancel_unsettled key is. The GPT lane's blocking finding is about an earlier head and is fixed in this one.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 0d0e54b3fe · 133 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 12, 2026
@bolichen97
bolichen97 force-pushed the fix/34446-cancel-stale-kas-login branch from 67999f7 to 0d0e54b Compare November 12, 2026 00:30
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Automatic cancellation silently discards failures span=0b66d81b3750
    self-added: no

fixed in 0d0e54b: a failed automatic cancel keeps the login id and shows an ErrorNotice (agent hand-off on) over the signed-in view, with Try again re-running the same settle for that id.
The dropped session is never restored, so the hidden poll does not resume; the user-cancel paths (reset, replaceAttempt) already rendered this outcome and are unchanged.
Pinned by says so in the signed-in view when that cancel fails, and retries it from there (red without the notice).
[operator: bolichen97]

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 12, 2026
Starting a Kiro sign-in and then signing in another way (another tab,
the CLI) showed the signed-in view while the hidden login kept polling
/api/kas-login/poll every few seconds. The gate renders the signed-in
branch before the session branch, and the session was dropped only
when its own poll answered authorized.

When the status reads signed in, no account switch is running and no
cancel is settling, the gate now drops the pending session and cancels
it through the same settle path a user's cancel takes. If that cancel
fails, the signed-in view shows a notice with Try again instead of
dropping the failure.

Closes #34446

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve on 0d0e54b. The new head handles the case the last review left open. When the automatic cancel of a dropped sign-in fails, the signed-in view now shows an error notice with Try again, and the dropped session stays dropped, so its poll does not resume. The new string is in every shipped locale. The new test turns red if the notice, the retry or the reset before a retry is removed. The red backend shards are the two tests that were failing on main before this PR's run, so the PR only needs a rebase. One small gap remains: no test covers the guard that skips the automatic cancel while a user's own cancel is settling. Removing that guard would only send a second cancel, which the gateway ignores. Decisive lines: website/src/components/KasLoginGate.tsx:1103-1114, website/src/components/KasLoginGate.tsx:1181-1196, website/src/components/KasLoginGate.test.tsx:391-431

@bolichen97
bolichen97 force-pushed the fix/34446-cancel-stale-kas-login branch from 0d0e54b to 32d69c4 Compare November 12, 2026 07:51
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/dashboard/handlers/updates.py and test/test_update_boot_apply.py since this head's CI ran (f9788c5 -> e1b079c); CI re-running.

The four Backend Tests reds and the Coverage Gate on 0d0e54b were main's (#35660: test_updates_handlers_facade and test_wait_discipline_ratchet fail on main too). #35625 fixed both on main, so this branch now sits on it. The PR's own diff is unchanged.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 12, 2026
@bolichen97
bolichen97 merged commit d21074a into main Nov 12, 2026
99 of 100 checks passed
@bolichen97
bolichen97 deleted the fix/34446-cancel-stale-kas-login branch November 12, 2026 14:11
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 12, 2026
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.

Kiro sign-in keeps polling in the background after the account signs in elsewhere

3 participants