Skip to content

feat(cloud): let users regenerate an expired remote sign-in code - #10885

Closed
molladair wants to merge 1 commit into
mainfrom
feat/signin-timeout-retry
Closed

molladair wants to merge 1 commit into
mainfrom
feat/signin-timeout-retry

Conversation

@molladair

@molladair molladair commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

When you launch a managed EC2 crew, one step is "Sign in to Kiro" — the instance shows a device code you approve in your browser. That code expires in about 10 minutes. If you miss the window, you are stuck three ways:

  1. The dashboard shows the old, dead code with no way to get a new one.
  2. The copy never warned you the code expires, so you do not know why it stopped working.
  3. If you switch to the half-set-up instance from the header, its embedded dashboard shows the generic "Install Kiro CLI" screen — Kiro CLI is already installed, so "Check again" never clears, and the full-screen gate hides the tab strip, so you cannot even click back to Local.

Why it matters

The only escape today is to cancel the whole launch and pay for a fresh instance. A user who steps away for eleven minutes loses the instance they just made. This hits exactly the users most likely to be interrupted mid-setup.

What changed (motivation → approach → change)

The code expires and nothing lets you make a new one, so add a way to make a new one, and stop the dead-end screens from trapping you.

  • Backend: a new POST /api/cloud/launch/{id}/signin/refresh route restarts kiro-cli login --use-device-flow on the already-running instance over SSM and returns a fresh URL + code. It only runs once the instance exists (409 before that, or on a cancelled job), surfaces an SSM failure as a 502, and handles the race where you approve the old code just as the refresh fires (reports "already signed in" instead of a code you no longer need). start_device_login already kills any stale login process before starting a new one, so calling it again is safe.
  • Launch card (Remote Instances settings): the hint now says the code expires in ~10 minutes; a Generate new code button calls the refresh route; and once the instance is registered, a line points you to "Your instances" so you know it is ready to connect after you finish signing in.
  • Embedded gate: when the SPA runs as an embedded remote pane and Kiro CLI is installed but not yet signed in, it shows a purpose-built "Finish signing in to Kiro" screen instead of the wrong "Install" flow — with a button that navigates the parent dashboard to Remote Instances settings (via postMessage, since an iframe cannot navigate its parent). The gate also keeps polling in this state so it clears itself the moment you approve, no "Check again" needed.
  • Escape hatch: the viewport now handles the mc-navigate message from that button, switching back to Local first so the settings page is not hidden behind the pane overlay.
flowchart TD
    subgraph before["Before — code expires"]
        B1[Code expires]:::ctx --> B2[Dashboard shows dead code]:::removed
        B1 --> B3[Embedded pane: 'Install Kiro CLI']:::removed
        B3 --> B4[Check again → nothing]:::removed
        B2 --> B5[Only exit: cancel + relaunch]:::removed
    end
    subgraph after["After"]
        A1[Code expires]:::ctx --> A2[Generate new code]:::added
        A1 --> A3[Embedded pane: 'Finish signing in']:::added
        A3 --> A4[Open Remote Instances settings]:::added
        A2 --> A5[Fresh code, keep the instance]:::added
    end
    classDef added fill:#DCFCE7,stroke:#16A34A;
    classDef changed fill:#FEF3C7,stroke:#D97706;
    classDef removed fill:#FEE2E2,stroke:#DC2626,stroke-dasharray:4 3;
    classDef ctx fill:#E0F2FE,stroke:#0284C7;
Loading

🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged

The picture: instead of a dead code and two dead-end screens, an expired code now has a "make a new one" button and the embedded pane sends you where the code lives.

Note — interaction with PR #9840 (fix(cloud): preserve Identity Center login through managed launch, still open): that PR reworks start_device_login to thread an organization's identity provider through managed launch. This PR calls start_device_login with only profile/region. Whichever merges second should thread #9840's identity flags through the refresh call so an Identity Center user who regenerates a code is not sent back to the generic Builder ID portal. The two changes are complementary (which identity vs. retry-when-expired) and do not conflict textually.

Files

Path Change
src/kiro_crew/dashboard/handlers_cloud.py new signin-refresh route handler
src/kiro_crew/dashboard/routes/connections.py registers the refresh route
website/src/api/client.ts client method for the refresh route
website/src/pages/settings/RemoteCrewPanel.tsx timeout copy, Generate-new-code button, registered hint
website/src/components/KiroPrerequisiteGate.tsx embedded "Finish signing in" screen + keep-polling
website/src/components/InstancesViewport.tsx mc-navigate escape hatch to settings
website/src/i18n/locales/en.json new strings + two copy improvements
test/test_cloud_handlers.py 7 tests for the refresh route

Tests

test/test_cloud_handlers.py::TestSigninRefresh — 7 cases locking in the new route: 404 on an unknown job, 409 before an instance exists and on a cancelled job, a fresh code returned and persisted (with the stale confirmed flag re-armed), the already-signed-in race reported as success, a social-login path with no device code surfaced as 502, and an SSM failure surfaced as 502.

Manual verification

Backend route is covered by unit tests. The frontend changes (launch-card button, embedded gate screen, tab-strip escape hatch) are wired against existing patterns and typecheck clean (tsc -p tsconfig.app.json), but I have not captured live screenshots — see below.

Screenshots / video

Screenshots pending — the three UI states (launch card with the new button, the embedded "Finish signing in" screen, the tab-strip escape hatch) need the dashboard driven into an unconfirmed-signin launch state, which I will capture and attach before this is marked review-ready. Flagging honestly rather than omitting.

Pattern harvest

Not generalizable: this is a specific missing-retry gap in one launch flow, not an instance of a broader defect class.

Checklist

  • At most two commits (one here), Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) — N/A, no doc surface
  • No secrets, credentials, or internal references in the diff

Related Issues

no linked issue: reported directly by a maintainer, not filed as a tracked issue.

@molladair
molladair requested review from a team and chenmingwei23 September 14, 2026 22:40
@molladair

Copy link
Copy Markdown
Contributor Author

Intent: Let a user whose managed-launch device-code expired generate a fresh code, and stop the half-set-up instance from trapping them behind the wrong "install CLI" screen with no way back.
Not a goal: Changing which identity provider the login targets (that is PR #9840) — this PR only adds retry-when-expired and the escape hatches.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 14, 2026
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🔴 BLOCK (blocking)

Design-level review of 15739950246883b56a555a469dbda400e2bb8f21 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: BLOCK

Cannot evaluate: missing screenshot or recording of the three new UI states — the description itself says screenshots are pending.

Blockers

Required rendered evidence missing for a reshaped user-visible surface
The PR adds a new full-screen embedded gate screen (EmbeddedSigninPending in website/src/components/KiroPrerequisiteGate.tsx) and reshapes the launch card (RemoteCrewPanel.tsx: Generate-new-code button, already-logged-in state, registered hint) → the workflow's evidence file lists 0 downloaded attachments, 0 committed images, and 0 transport failures, matching the description's own "Screenshots pending … which I will capture and attach before this is marked review-ready" → the shape of the gate screen, the button placement on the crowded sign-in card, and the tab-strip escape-hatch flow cannot be judged unseen. The backend route and its 7 tests are sound; this blocker is evidence-only, not approach.
Fix: drive the dashboard into the unconfirmed-signin state and attach the three screenshots the description already promises.
Clears when: the PR description carries downloaded image/recording attachments of this revision showing the launch card with the new button, the embedded "Finish signing in" screen, and the escape-hatch navigation.

Suggestions

  • The window.open('/settings/instances', '_blank') fallback resolves against the pane's remote origin, opening the wrong dashboard's settings — since postMessage(…, '*') effectively cannot throw, drop the fallback rather than ship a dead end.

[DESIGN-REVIEWED] 1573995

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — 🔴 BLOCK

UX-level review of 15739950246883b56a555a469dbda400e2bb8f21 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: BLOCK

cannot evaluate: missing every screenshot — blind read not performed; the PR admits "Screenshots pending" while adding a button, a full-screen state, and four new copy states.

Evidence gaps

  • Blind read NOT PERFORMED: no image attached to the description and none committed — attach stills to close all gaps below.
  • "Generate new code" button (idle, "Generating…", and inline new_code_error states) on the launch card: no screenshot.
  • Expired-code state with the new sign_in_unconfirmed copy ("may have expired… generate a new one"): no screenshot.
  • "Already signed in! Connect the instance…" success state after refresh: no screenshot.
  • instance_registered_hint line on a done-but-unconfirmed job: no screenshot.
  • Embedded "Finish signing in to Kiro" screen ("Open Remote Instances settings" + "Check again"): no screenshot.

Watch

  • The postMessage fallback window.open('/settings/instances', '_blank') resolves against the pane's own (remote) origin, whose dashboard is still gated unauthenticated — the button labeled "Open Remote Instances settings" lands on the same sign-in gate in a new tab. Rare branch × dead end × every hit; point the fallback at the local dashboard's absolute URL or drop it.

Suggestions

  • already_logged_in_after_refresh says "Connect the instance" with nowhere to do it, and the !alreadyLoggedIn condition suppresses the "Your instances" pointer exactly then — show the registered hint (or a link) in that state too.

[UX-REVIEWED] 1573995

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 15739950246883b56a555a469dbda400e2bb8f21 — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Verify merge order with #9840: whichever lands second must thread Identity Center flags through the refresh call, or regenerated codes reach the wrong portal.

Not justified as shipped

  • Item 4 — rides along: the "registered — find it under Your instances" hint is declared, but it addresses none of the three reported dead-ends; harm-free rider.
  • Item 8 — undeclared: the checklist says "Documentation updated — N/A, no doc surface" while the diff edits docs/feature-map/README.md; the edit itself is the mandated same-commit doc sync.
  • Item 10 — undeclared: the window.open('/settings/instances','_blank') catch fallback rests on "if postMessage fails (e.g. same-origin or sandboxed)", a failure no declared path produces; trivial, harm-free rider.

What this change ships

Inventory (10 items) — 7 justified

Intent: unstick a user whose device sign-in code expired mid-launch, instead of forcing cancel-and-relaunch — fundamentally a FIX (reproduction written in the description; existing /signin route verified fetch-only, 409 with no pending prompt).

  1. "Generate new code" button on the launch card, backed by new POST /api/cloud/launch/{id}/signin/refresh — justified
  2. Launch-card hint now warns the code expires in ~10 minutes — justified
  3. Unconfirmed-sign-in copy now says the code may have expired and offers regeneration — justified
  4. Done-but-unconfirmed jobs show a "registered — see Your instances" line — rides along (declared, outside the three reported dead-ends)
  5. Embedded pane with CLI installed but unsigned shows "Finish signing in" instead of the wrong Install flow — justified
  6. That embedded state keeps polling so approval clears the gate without "Check again" — justified
  7. "Open Remote Instances settings" button drives the parent via purpose-fixed mc-navigate (no payload, one destination, origin-validated like mc-set-crew-pin; 1 sender, 1 handler) — justified
  8. Feature-map row gains the new route — undeclared (mandated same-commit doc sync)
  9. Approving the old code mid-refresh reports "already signed in" instead of a dead new code — justified
  10. New-tab fallback if postMessage throws — undeclared (unverified failure premise)

[FIRST-PRINCIPLES-REVIEWED] 1573995

@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — 🔴 changes requested (blocking)

Reviewed 1c7b5edec08e51cfb4b7e5fb807e2b0383cad9be — this comment is updated in place on each push.

Confirmed. Candidate 1 is a real violation of the blocking: true errors-use-error-notice rule. Candidates 2 and 3 do not survive falsification (candidate 2's corruption path is guarded by start_device_login's is_logged_in early-return-without-save and its remaining outcome is timing-dependent and non-corrupting; candidate 3's navigate uses the History API which cannot cross origins, and the sender is origin-validated).

BLOCKING — a failed sign-in-refresh request is rendered in a hand-written <p className="text-danger">, the exact surface the errors-use-error-notice (blocking:true, src/**/*.tsx) rule bans.

[BLOCK-MERGE] 1c7b5ed
BLOCKING — website/src/pages/settings/RemoteCrewPanel.tsx:713

{signinRefreshError && (
  <p className="mt-1.5 text-[12px] text-danger">{i18nT('pages.settings.remoteCrewPanel.new_code_error')}</p>
)}

signinRefreshError is fed by signinRefreshMutation.isError (line 1750) → the POST …/signin/refresh failing (502 signin_refresh_failed / no_device_code) renders the failure into a hand-written <p className="text-danger">, the surface the rule names verbatim ("an error string dropped into a <p>"), throwing away the structured hand-off ErrorNotice recovers.
Fix: render through <ErrorNotice variant="inline" message={signinRefreshError ? i18nT('…new_code_error') : undefined} /> (already imported here) with a {/* No hand-off: this card sits over the live setup form */} comment; the mutation carries no data, so drop the 'error' sentinel and pass the message directly.

[OPUS-REVIEWED] 1c7b5ed

Verdict parsed from the review's SHA-scoped output markers for commit 1c7b5edec08e51cfb4b7e5fb807e2b0383cad9be.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 1c7b5edec08e51cfb4b7e5fb807e2b0383cad9be: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging 15739950246883b56a555a469dbda400e2bb8f21. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/dashboard/handlers_cloud.py:594 -- Active launch worker overwrites the refreshed code
fresh.signin = new_signin
Refresh during awaiting_signin -> worker times out and saves its stale prompt -> dashboard restores the expired code.
Anchor: residual/crash-data-loss-corruption
Fix: Serialize refresh with the launch worker, or reject refresh until the job is terminal.
[BLOCK-MERGE] 1573995
[GPT-REVIEWED] 1573995

Adjudication (Opus 4.8) — is blocking on each finding proportionate?

The adjudicable block is empty. One fenced finding, F1, to annotate.

F1 — handlers_cloud.py:594 overwrites via last-writer-wins race.

Conditions confirmed this run:

  • Worker parks in AWAITING_SIGNIN at launch_job.py:633 (signed = handle.wait(cancel)), holding its in-memory job.signin = the initial prompt from launch_job.py:628.
  • Refresh re-reads fresh at handlers_cloud.py:586; guard at :587 only bails on terminal/signin_detected advance, so a still-awaiting worker doesn't trip it, and refresh persists the new code at :594–597.
  • Worker's wait times out unsigned (launch_job.py:640, signed=False → prompt not cleared), then store.save(job) at :650 writes the stale in-memory prompt over the refreshed code.

Recovery path: the job proceeds to DONE (terminal), and a second refresh re-read at handlers_cloud.py:586–587 no longer bails (both job and fresh terminal), regenerating and persisting a fresh code — self-correcting on the next click, and the endpoint documents itself safe on done-but-unconfirmed jobs (:519–521).

Harm rung: LOW. The clobbered value is an ephemeral device code that reverts to an expired one — no credential is exposed (the stale code is useless), no irreversible loss; the user sees a non-working code and clicks refresh again. The fix ("reject refresh until terminal") would defeat the endpoint's core purpose (refresh during awaiting_signin is exactly the need); real serialization is a new cross-module ordering contract for a self-correcting usability revert. A human would plausibly accept this residual risk.

[ADJUDICATION] 1573995 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 1573995
[ADJUDICATION-FENCED] 1573995 fenced=1 flagged=1
FLAG F1 src/kiro_crew/dashboard/handlers_cloud.py:594 -- Race reverts the fresh device code to an expired one only in a narrow interleave; nothing is leaked, the code is regenerable, and a second refresh click fully recovers, so the residual risk is plausibly acceptable.
[GPT-ADJUDICATED-FENCED] 1573995

🏷️ Fenced finding(s) machine-flagged as likely edge case

The security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override. The annotate-only pass judged the condition combination each one requires extreme, and pre-drafted the override rationale below. A repository writer must independently verify a rationale before posting it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop.

  • F1 src/kiro_crew/dashboard/handlers_cloud.py:594 — Race reverts the fresh device code to an expired one only in a narrow interleave; nothing is leaked, the code is regenerable, and a second refresh click fully recovers, so the residual risk is plausibly acceptable.

    /ai-review override gpt 15739950246883b56a555a469dbda400e2bb8f21: Race reverts the fresh device code to an expired one only in a narrow interleave; nothing is leaked, the code is regenerable, and a second refresh click fully recovers, so the residual risk is plausibly acceptable.
    

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 15739950246883b56a555a469dbda400e2bb8f21: <one-sentence reason>

@molladair
molladair force-pushed the feat/signin-timeout-retry branch from 1c7b5ed to 1573995 Compare September 14, 2026 23:21
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 14, 2026
When a managed EC2 crew launch runs past the device-code timeout, the
displayed code expires with no way to get a fresh one, and switching to
the half-set-up instance shows the generic "install Kiro CLI" gate with
no escape. Add a signin-refresh route, a "Generate new code" button, a
purpose-built embedded gate screen, and a tab-strip escape hatch.
@molladair
molladair force-pushed the feat/signin-timeout-retry branch from 1573995 to 1d64e1c Compare September 14, 2026 23:28
@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 Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for 1d64e1cef4c6477c3b2aa1088a3118060b1276c0; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 1d64e1cef4c6477c3b2aa1088a3118060b1276c0: <one-sentence reason>

@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 Sep 14, 2026
@molladair

Copy link
Copy Markdown
Contributor Author

Converting this to a draft and handing the work off to a feature request: #10903.

Rather than owning this feature to completion, filing it as a tracked request. This branch stays as a reference implementation — it has the working backend route, the UI, and passing tests — but two open items need engineering decisions that are better made by someone with the concurrency context:

  1. A refresh-vs-launch-worker race (design choice between rejecting refresh until the job is terminal, or serializing with the worker) — see Let users regenerate an expired device-code sign-in during a managed remote launch #10903.
  2. The Identity Center flag threading vs fix(cloud): preserve Identity Center login through managed launch #9840.

Screenshots for the Design/UX gates were also not captured. #10903 documents all three. Anyone is welcome to pick up this branch from here.

@molladair
molladair marked this pull request as draft September 14, 2026 23:42
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 15, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks for tackling this, @molladair — regenerating an expired remote sign-in code is a real gap worth closing.

I'm closing this one because the current shape is much larger than the feature needs: ~540 lines across 10 files, including a new KiroPrerequisiteGate component and a RemoteCrewPanel rewrite, to regenerate an expired device code. The Design review can't fully evaluate a change that broad, and Opus confirmed a real errors-use-error-notice rule violation (a genuine code fix, not a nitpick), alongside broad CI reds across backend, frontend, macOS, coverage, SAST and screenshots.

A much smaller version would likely go green far more easily: a single "regenerate" action wired onto the existing expired-code state, reusing the current RemoteCrewPanel and the existing error-notice path rather than introducing a new gate component and a panel rewrite. That keeps the surface tiny and sidesteps both the design-evaluability and the error-notice-rule blockers.

You're very welcome to reopen this or open a smaller PR along those lines — happy to see the feature land. Thanks again.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 24, 2026
@bolichen97
bolichen97 deleted the feat/signin-timeout-retry branch November 6, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants