Skip to content

fix(mcp): withdraw an Authorize link once its sign-in attempt times out - #34627

Merged
bolichen97 merged 1 commit into
mainfrom
fix/22897-retire-timed-out-authorize-card
Nov 11, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/22897-retire-timed-out-authorize-card

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: When a KAS MCP sign-in attempt ends without the server connecting, its Authorize card stops offering the dead link and says the sign-in timed out.

On the KAS backend the engine keeps a sign-in attempt's OAuth callback listener open only for the server's connect timeout (60 s by default). Nothing told the chat when that attempt ended, so its Authorize card stayed clickable. A click after that walks the user through the provider's consent page and lands the browser on localhost:<port>/oauth/callback?code=… with ERR_CONNECTION_REFUSED, and the sign-in never completes.

Why it matters

A user who reaches the card more than a minute after it appeared cannot sign in from it, and nothing on screen says why. They finish the provider's consent page and end on a browser error, so the server looks broken instead of merely timed out.

Not a goal

What changed (motivation → approach → change)

When a KAS sign-in attempt ends without the server connecting, its Authorize card drops the dead link and shows a failure notice that says the sign-in timed out, in tabs that are already open too. The cause: AcpRuntime._run_mcp_sign_in freed the sign-in slot when the engine answered the reset but told nobody, so the chat kept the link live. The fix is a hook from the runtime to the chat, called when an attempt ends unconnected, plus one check when a card is drawn, because an attempt can end before its card exists.

Builds on #22907 by @kyleseaman. It keeps that PR's runtime-to-chat hook and leaves out its card removal and attempt tagging.

Layer Change
Runtime (acp/) A reset answered success: false, refused with an error, or never answered, on a live process calls the session's ended-attempt hook with the server name, after the slot is freed; any other answer calls nothing. set_mcp_sign_in_ended_hook installs it and unregister_session drops it. A process that died stays with the dashboard's dead-child gate.
Providers (providers/base.py, providers/acp.py, acp/session_provider.py) LLMProvider.set_mcp_sign_in_ended_hook is a no-op and mcp_sign_in_ended answers False by default. AcpProvider forwards both to the shared-runtime AcpSessionProvider, which installs the hook for its session and answers mcp_sign_in_ended true when, on a live host that opens external URLs, the runtime no longer holds that session and server's sign-in.
Dashboard (dashboard/chat_turn/mcp_session.py) The mid-turn arm installs the hook before it draws a link, and asks mcp_sign_in_ended once the row is appended, for an attempt that ended while its link waited in the queue or while endpoint discovery ran. Either way the row loses its link, takes expired with expired_reason: "attempt_ended" and the change reaches open tabs, idle chats included. A later success still turns the row green. Supersede and this expiry share one retire loop.
Frontend (website/src/pages/chat/McpOAuthBanner.tsx, website/src/i18n/locales/) An attempt_ended row renders through ErrorNotice, with the same "Ask the agent" decision as a failed sign-in, and a new timed_out string translated in every catalog: "sign-in timed out before it was completed. Name this server in a message to get a fresh Authorize link." A process-ended row keeps its grey notice. The capture harness (website/capture/mcp-oauth-banner.tsx) gains a timed-out row.

The specs acp-client.md and learn-cron-dashboard.md describe the hook, the draw-time check and the expiry.

Backwards compatibility

Compatible: expired_reason is a new optional meta key and both provider methods have a default; a row without the key renders as it does today.

Removes nothing: the only link withdrawn is one whose callback listener the engine has already closed, and every banner state main draws still draws.

Tests

  • test/test_kas_mcp_sign_in.py::test_a_sign_in_that_ends_unconnected_tells_the_chat_that_showed_its_link drives a sign-in through the real AcpProvider → AcpSessionProvider → AcpRuntime chain for five answers: success: false and no answer tell the hook; success: true, an answer that states neither, and a dead process do not; mcp_sign_in_ended is False while the sign-in is held and True after; and unregister_session drops the hook.
  • test/test_mcp_oauth_banner_midturn.py::test_an_ended_sign_in_attempt_withdraws_its_link_and_the_next_offer_is_live pins that the hook the mid-turn arm installs withdraws the link (stored row and the open-tab frame) and that the next offer draws a live card.
  • test/test_mcp_oauth_banner_midturn.py::test_an_attempt_that_ends_before_its_row_exists_still_withdraws_it pins both early windows (queued, discovery): the row arrives withdrawn, with no link.
  • test/test_mcp_oauth_banner_midturn.py::test_a_late_success_still_turns_an_ended_attempts_card_green pins that a success still lands on the timed-out row and a failure does not.
  • website/src/test/McpOAuthBanner.test.tsx "says an attempt that ended unconnected timed out, with no link" and "shows a timed-out attempt as a failure, with the hand-off the host allows" (alert role, hand-off on and off, plain notice for a process-ended row).

Proof: PROVEN test/test_acp_bindings.py::test_the_member_set_is_the_frozen_inventory (head 721b36a)

Determinism: the four new backend tests (five cases) passed 20/20 at -n0 and 10/10 at -n 4 --dist loadgroup --max-worker-restart=2 beside test_mcp_oauth_banner_dedupe.py and test_mcp_oauth_banner.py, and the 102 tests of their two files passed in a shuffled order (seed 16320). The frontend timed-out test passed 20/20, and McpOAuthBanner.test.tsx passed in a shuffled order (seed 16320).

Manual verification

Rendered the real McpOAuthBanner from this head in its capture harness (website/capture/mcp-oauth-banner.html on a local vite server), dark and light, with DOM checks: the live card has a link; the timed-out card has none, is an alert and says it timed out; the process-ended card is not an alert. Not run end to end against a live KAS engine and an OAuth MCP server; the runtime and dashboard tests above drive that path.

Screenshots / video

Before (what main still shows once the attempt has ended): the Authorize button looks live.

Before: the Authorize card still offers its link

After: the same card once its attempt ended, dark and light.

After, dark: the card is a failure notice that says the sign-in timed out, with no link

After, light: the card is a failure notice that says the sign-in timed out, with no link

Every banner state from this head, light

All banner states, light: live, signed in, failed, replaced, session ended, timed out

Related Issues

Closes #22897

Sibling sweep

Swept: git grep -nE "_run_mcp_reattempt|begin_mcp_sign_in|_mcp_sign_in = None" -- src/kiro_crew/acp/
Sibling: src/kiro_crew/acp/runtime_host_requests.py:544 -- not affected -- _run_mcp_reattempt resets without startOAuth, so it never shows a link
Sibling: src/kiro_crew/dashboard/chat_utils_display.py:1016 -- not affected -- _expire_dead_child_oauth_meta already withdraws a link whose process died

Pattern harvest

Not generalizable: the one runtime seam where an attempt's end was known but never reported to the chat; no other flow mints a link bound to a short-lived listener.

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 10, 2026 15:47
@bolichen97
bolichen97 enabled auto-merge (squash) November 10, 2026 15:47
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks. The runtime reports the end of the attempt at the point where it already frees the sign-in slot. The card also checks once when it is drawn, which covers attempts that end before the card exists.

Notes

  • mcp_sign_in_ended treats "the runtime holds no slot" as "the attempt ended". That holds only while Crew's begin_mcp_sign_in is the only source of a mid-turn KAS consent link, which is what acp-client.md states today. If a future engine sends its own mcp_oauth_request while a turn is running, every such card would show as timed out the moment it is drawn. Pinning that assumption in a test would make a change there fail loudly.

[DESIGN-REVIEWED] 721b36a

Description read

[DESCRIPTION-READ] 05d07be83a386abcb7d76a21d17b3ffe611f90732a2d3c7b886b57a9d4e2c2e0

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 10, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 721b36a0d523fab4c4a622c5613d6e4aa05b929b — 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

Each new surface has exactly one consumer (the mid-turn arm), and the fix sits where the cause is: the runtime freed the sign-in slot but never told the chat.

What this change ships

Inventory (7 items) — 7 justified

Intent: a user who opens a KAS MCP Authorize card after its sign-in attempt ended should see that the sign-in timed out, not a link that ends on a refused localhost page. FIX (#22897).

  1. When a KAS sign-in attempt ends without connecting, its Authorize card loses the link, including in tabs already open and in idle chats — justified
  2. A card drawn after its attempt already ended (link waited in the queue, or endpoint discovery ran long) arrives with no link — justified
  3. A timed-out card shows as an error alert with the "Ask the agent" hand-off, not the grey notice — justified
  4. New "sign-in timed out… name this server in a message" text, in every catalog — justified
  5. A server that connects late still turns its timed-out card green — justified
  6. The supersede path and the new expiry share one retire loop, with no behaviour change — justified
  7. The capture harness gains a timed-out row — justified

[FIRST-PRINCIPLES-REVIEWED] 721b36a

Description read

[DESCRIPTION-READ] eecfcdd98201af26d4be302aecd3ab952f1c1a2d28061751cdd8a599c7083d59

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 10, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

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

UX-Verdict: PASS

Nothing blocks: the only new surface is the timed-out notice, and the blind reader read it correctly ("my sign-in attempt expired… type the name in the chat to get a new sign-in button").

Notes

  • timed_out copy: "Name this server in a message" left the reader unsure ("do I type 'github-mcp' exactly? And I didn't know it was a 'server'"). Change it to "Send a message that mentions github-mcp to get a fresh Authorize button."
  • The three retired-card notices give three different next steps: "Name this server in a message", "Send a message to get a fresh Authorize link" and "Use the latest Authorize button". This PR's string also adds a third noun, "link", next to "button". Pick one noun (button) and one way to phrase the next step for both ways an attempt can end.

[UX-REVIEWED] 721b36a

Description read

[DESCRIPTION-READ] 27f56d6bfbad953792d46bce444c45f9b3a6c2adc7fdcb1ee01a7951dcd23b4e

That sha256 names everything this verdict read: the PR description, plus the 7 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 10, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 721b36a0d523fab4c4a622c5613d6e4aa05b929b — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 721b36a

Verdict parsed from the review's SHA-scoped output markers for commit 721b36a0d523fab4c4a622c5613d6e4aa05b929b.

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

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 721b36a0d523fab4c4a622c5613d6e4aa05b929b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 721b36a

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

@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 10, 2026
buluoray
buluoray previously approved these changes Nov 10, 2026

@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 4c78817. The runtime-to-chat expiry hook is correct and well tested (3 mutations each turn a named test red), but the PR's own new fr/ru/hi timed_out strings break the repo's i18n style tests (Frontend Tests 1 and 3 red), so it cannot merge as is; a 3-string fix. Named findings for Bolin: (1) fix the new fr/ru/hi pages.chat.mcpOAuthBanner.timed_out strings so Frontend Tests 1 and 3 pass; (2) GPT F2, McpOAuthBanner.tsx:180: the ended-attempt failure is grey text, not ErrorNotice; (3) GPT F1, mcp_session.py:802: if the attempt ends while the banner is still preparing (only when the connect timeout is set below the 8 s discovery cap and discovery is slow), a clickable Authorize card is left pointing at a closed callback port. No credential or privilege impact and the next message re-prompts, but GPT marked it security-class, so it needs your fix or your owner decision. Decisive lines: website/src/i18n/locales/fr.json (pages.chat.mcpOAuthBanner.timed_out), website/src/i18n/locales/ru.json (same key), website/src/i18n/locales/hi.json (same key); src/kiro_crew/dashboard/chat_turn/mcp_session.py:802 (F1, non-blocking); website/src/pages/chat/McpOAuthBanner.tsx:180 (F2, rule-scope call)

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 10, 2026
On the KAS backend the engine keeps a sign-in attempt's OAuth callback
listener open only for the server's connect timeout. When the attempt
ended, the runtime freed its sign-in slot but told nobody, so the chat
kept a live-looking Authorize card whose link now ends on a refused
localhost port.

The runtime now reports an attempt that ends without the server
connecting to a per-session hook, which the dashboard installs through
the provider before it draws a link. The hook withdraws that server's
open links and marks the rows expired with reason attempt_ended. An
attempt that ended before its row was drawn is caught when the row is
appended, by asking the provider whether the runtime still holds that
sign-in. The card renders as a failure notice that says the sign-in
timed out and how to get a fresh link. A later success still turns the
card green.

Builds on #22907.

Closes #22897
@bolichen97
bolichen97 force-pushed the fix/22897-retire-timed-out-authorize-card branch from 4c78817 to 721b36a Compare November 11, 2026 08:05
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in learn-cron-dashboard.md (a merge conflict), acp-client.md, runtime_class.py, session_provider.py, mcp_session.py and the 13 locale catalogs since this head was last judged (6bad93d -> 478d13a); CI re-running.

[operator: bolichen97]

@bolichen97

bolichen97 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: no
mechanism: the arm asks the provider whether the runtime still holds the sign-in once it has appended the row

  • An attempt ending during banner preparation leaves its dead link live span=e1cdc88504ba

fixed in 721b36a: an attempt that ends before its row exists no longer leaves a live link.
After _emit_mcp_oauth_request, _on_mcp_oauth_request asks client.mcp_sign_in_ended(server_name); on a live host that opens external URLs it is true once the runtime no longer holds that session and server's sign-in slot, and the row is retired the same way the hook retires it.
This covers the discovery window named here and the wider one: a link queued behind a permission or elicitation prompt the dispatch loop is awaiting.
Pinned by test_mcp_oauth_banner_midturn.py::test_an_attempt_that_ends_before_its_row_exists_still_withdraws_it (both windows) and the real-chain assertions in test_kas_mcp_sign_in.py.

[operator: bolichen97]

@bolichen97

bolichen97 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: no

  • Failed sign-in attempts bypass the required error surface span=5dd1f2a86a23

fixed in 721b36a: a timed-out sign-in row renders through ErrorNotice with the host's askAgent decision, the same as the failed branch.
The process-ended expired notice is status text and keeps its plain notice; superseded is unchanged.
Pinned by website/src/test/McpOAuthBanner.test.tsx "shows a timed-out attempt as a failure, with the hand-off the host allows" (alert role, hand-off on and off, plain notice for a process-ended row).

[operator: bolichen97]

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 11, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates an 18% chance that this change introduces a defect, above the 12% limit for approving on its own.

Approve. The PR adds a hook from the runtime to the chat, called when a KAS MCP sign-in attempt ends unconnected (answered success: false, refused with an error, or never answered). It also adds a check when a card is drawn, which covers an attempt that ended while its link waited in the queue or during endpoint discovery. Both withdraw the Authorize link and mark the row expired with expired_reason: "attempt_ended"; the frontend then shows a timed-out failure notice. I verified that on KAS every oauth_request frame reaches the chat via _answer_open_external_url only while the sign-in slot is held, so the draw-time check cannot withdraw a live link; non-KAS hosts default to False. On lifecycle: the hook is reinstalled on each arm and removed by unregister_session, a fresh sign-in clears the duplicate-link filter, and a late success still turns the card green. The open-tab merge is harmless because the banner checks completed before expired, and the dead-process gate and rejected-URL banners are unaffected. All test fakes on this path either subclass LLMProvider or were updated, every locale catalog has the new string, and tests cover each new behaviour. The issue the

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 721b36a0d5 · 379 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 11, 2026

@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 721b36a. The delta fixes every finding from the earlier APPROVE: an attempt that ends before its card is drawn now arrives withdrawn, the timed-out card is an ErrorNotice, and the fr/ru/hi (plus bn) strings follow the style rules; tests and two new mutations hold, and every red check on this head is GitHub rate-limit noise. Decisive lines: src/kiro_crew/dashboard/chat_turn/mcp_session.py:896-897 (draw-time check, fixes F1); src/kiro_crew/acp/session_provider.py (mcp_sign_in_ended, reattempts_mcp_servers and not mcp_sign_in_holds(...)); website/src/pages/chat/McpOAuthBanner.tsx (timedOut -> ErrorNotice with askAgent, fixes F2); website/src/i18n/locales/{fr,ru,hi,bn}.json pages.chat.mcpOAuthBanner.timed_out

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 11, 2026
@bolichen97
bolichen97 merged commit d25915a into main Nov 11, 2026
102 of 108 checks passed
@bolichen97
bolichen97 deleted the fix/22897-retire-timed-out-authorize-card branch November 11, 2026 09:46
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 11, 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.

MCP Authorize card stays clickable after its sign-in attempt times out

3 participants