Repository navigation
fix(mcp): say in chat when a kas server waits for a sign-in - #36135
Conversation
9d462e4 to
c6dbee4
Compare
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Two small subtractions are open: a duplicated sign-in predicate, and a McpTab sentence outside the chat-scoped Goal. Notes
What this change shipsInventory (7 items) — 5 justifiedIntent: on KAS, a user whose OAuth MCP server's saved sign-in stopped working learns this in chat and can sign in again there. FIX.
[FIRST-PRINCIPLES-REVIEWED] 4b3593d Description read[DESCRIPTION-READ] 35baffbd0844abe029113e871fadb6ad99aab7c82d1e35ead57168cd28a9e8a4 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The fix works from the engine's real output, adds no take-away, and the notice is informational, shown once per chat and bounded. Notes
[DESIGN-REVIEWED] 4b3593d Description read[DESCRIPTION-READ] 3171eb43293798153f6adef07428f7a8d682da64c73ceefe1b8daad6a5a96ac1 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 |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing blocks. The screenshots show both new surfaces, and the blind reader understood the chat notice and said they would act on it. Notes
[UX-REVIEWED] 4b3593d Description read[DESCRIPTION-READ] ab0f66517f7f7c66448820a6b28c62d07c2a91236b3f98b26a4a07b24902b8e9 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
c6dbee4 to
895fcba
Compare
|
span=e1cdc88504ba
|
|
span=436eddf3b05d
|
|
span=4a5a646367e3
|
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 20% chance that this change introduces a defect, above the 12% limit for approving on its own. I'd approve this. The change does what it says: KAS refresh refusals that keep the tokens (a 4xx 'could not be refreshed' error that isn't 408, 425 or 429, or a bare OAuth error code other than server_error or temporarily_unavailable) are now counted as needing a sign-in. Both readers apply the same check: the session handle's tracker and the report's 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 |
895fcba to
ead7f0c
Compare
|
span=436eddf3b05d
|
ba79e59 to
6d22b48
Compare
|
span=e1cdc88504ba
|
|
span=2751f6c2ef16
|
6d22b48 to
2002f87
Compare
2002f87 to
d841bed
Compare
|
span=3a8aea8b4ca1
|
d841bed to
97bb2e8
Compare
On KAS a remote MCP server whose saved OAuth sign-in stopped working left every new chat without its tools and with nothing that said why. The engine deletes saved tokens, and reports failedAuthorization, only for invalid_grant, invalid_client and unauthorized_client. Any other refusal of a refresh keeps the tokens and reports the server failed, so nothing tracked it for a sign-in and naming it in a message did nothing. A failed entry whose error says the token endpoint refused the saved sign-in is now tracked like failedAuthorization and listed as waiting for a sign-in. A 5xx, server_error or an unreachable endpoint is left alone: a sign-in reset would delete tokens that may still work. A chat also adds one notice row, once, naming the servers that wait for a sign-in and have no open sign-in card, with how to sign in. The chat page draws it with a link to the MCP Servers page. It starts no sign-in. On the MCP Servers page a server with a saved sign-in that the page cannot sign in to (added outside the page) says how to sign in, where the row used to show nothing. A server added from the page already offers Sign in again; a test pins it.
97bb2e8 to
4b3593d
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Reviewed head 4b3593d. We traced every changed backend path. On a scratch export of this head, the two new backend test files pass (63/63), and reverting each production hunk turns a test red: the tracker condition, the report bucket, the notice, its backend gate, the once-per-chat flag and the dead-child gate. The tests use no sleeps, clocks, ports or network. Nothing blocking was found. Well done: the classifier counts only the refusal shapes captured from a real engine run. Transient answers (408, 425, 429, 5xx, server_error, temporarily_unavailable) are left out on purpose, and both sides are pinned in a table test.
Security: more KAS OAuth failures now make a server a sign-in candidate. The reset that deletes saved tokens still starts only after the user's own message names the server (want_mcp_sign_in_named then begin_mcp_sign_in), so tracking a server never resets it on its own. Transient failures keep their reattempt path. The chat notice is gated on positive membership in ACP_BACKENDS_OPEN_EXTERNAL_URL. Server names pass through redaction, with both the count and the length bounded, and render as React children with no raw HTML.
The design is signed off under the standing maintainer sign-off for changes by team members.
Optional:
connections/mint_kas.py:448: the mint watcher ends an answered sign-in only on afailedbucket. A bare OAuth code now lands inawaiting_auth, so a refused consent row could staywaitinguntil its 600 s TTL. One mint_kas test for whichever behaviour you choose would settle it.McpTab.tsx:1283: the new "send a chat message that names X" line is not gated ononKas, but naming a server starts a sign-in only on KAS. AddingonKas &&would make it true on every backend.- The
status == "failed"guard at both classifier sites (session_handle_mcp.py:918,mcp_report_bound.py:107) survives deletion. A case with aconnectedentry that carriesinvalid_tokenwould pin it.
On KAS a remote MCP server whose saved OAuth sign-in stopped working left every new chat without its tools and with nothing that said why. The engine deletes saved tokens, and reports failedAuthorization, only for invalid_grant, invalid_client and unauthorized_client. Any other refusal of a refresh keeps the tokens and reports the server failed, so nothing tracked it for a sign-in and naming it in a message did nothing. A failed entry whose error says the token endpoint refused the saved sign-in is now tracked like failedAuthorization and listed as waiting for a sign-in. A 5xx, server_error or an unreachable endpoint is left alone: a sign-in reset would delete tokens that may still work. A chat also adds one notice row, once, naming the servers that wait for a sign-in and have no open sign-in card, with how to sign in. The chat page draws it with a link to the MCP Servers page. It starts no sign-in. On the MCP Servers page a server with a saved sign-in that the page cannot sign in to (added outside the page) says how to sign in, where the row used to show nothing. A server added from the page already offers Sign in again; a test pins it. Hand-resolved backport; original author: Ray Xu. (cherry picked from commit 6b75355)
Problem / Motivation
Goal: On the KAS backend, a chat says once when one of the user's MCP servers is waiting for a sign-in, and a remote server whose saved OAuth sign-in stopped working can be signed in to again from the chat.
Two users reported the same thing on Slack on 2026-11-12, on 0.12.2.x with the KAS backend: a remote MCP server that signs in with OAuth worked after the first sign-in, and about 18 to 20 hours later every new chat started without its tools. No sign-in card appeared, and the only way back was to remove the server and add it again, or to remove the whole saved sign-in store while the gateway was stopped.
Two things are missing on main:
failedAuthorization, only forinvalid_grant,invalid_clientandunauthorized_client. For any other refusal it keeps the tokens and reports the serverfailed, and only afailedAuthorizationentry is tracked for a sign-in.Why it matters
A user on the default backend loses a remote MCP server about once a day and cannot tell why or what to do. This is a Slack-reported KAS bug for 0.13.
Not a goal
What changed (motivation → approach → change)
What the engine reports. I ran a KAS 3.2.1 engine against a local OAuth MCP server and made its token endpoint answer a refresh in five ways:
invalid_grantfailed,failedAuthorization: truefailed,Sign-in for <name> could not be refreshed (token endpoint answered 401). …invalid_tokenfailed,invalid_tokenunknown_errorfailed,unknown_errorserver_errorfailed,… (token endpoint answered 500 server_error). …Fix 1: track a refused saved sign-in.
acp/mcp_reattempt.is_refused_sign_inreads rows 2 to 4: the "could not be refreshed" text with a 4xx and nothing after the status, or a message that is one bare OAuth error code. The session's sign-in tracker (session_handle_mcp._note_mcp_sign_in_status) and the session MCP report (through its one status reader,mcp_report_bound.read_status_snapshot) treat such an entry likefailedAuthorization: the server is listed as waiting for a sign-in, and a message naming it starts the existing KAS sign-in. Row 5,temporarily_unavailableand an unreachable token endpoint are left as failures, because a later attempt may succeed with the same tokens and a sign-in reset deletes them.Fix 2: say it once in the chat. When the session MCP report is published with a server waiting for a sign-in that has no open sign-in card in the chat, the dashboard adds one notice row (
_notice_mcp_sign_in_neededinsrc/kiro_crew/dashboard/chat_turn/mcp_session.py). It names up to five servers and the message that signs in from the chat; when it names several, it says each one needs its own sign-in. It is shown once per chat (a flag on the chat slot, in memory, so a gateway restart shows it once more). The chat page draws the row as a notice card (McpSignInNeededNotice), and a long server name wraps inside the card; other surfaces show the row's text. A kiro-cli chat already has the engine's own sign-in card for the server, so it gets no row. The notice names only the chat way in, because a page sign-in does not always reach a KAS chat.The MCP Servers row. The MCP Servers page probes without a token, so a server whose saved sign-in stopped working reads there like a working one: Signed in, no tools listed. For a server the owner added from the page, that row already offers Sign in again, which #35396 made replace the dead tokens; a test now pins it against the probe's real output shape. For a server added any other way the gateway refuses to start a sign-in, and the row showed nothing. It now says in words how to sign in: send a chat message that names the server, or add it with Add Custom to sign in from the page (
website/src/pages/overview/McpTab.tsx, one new string inwebsite/src/i18n/locales/en.manual.jsonand the 11 translated catalogs).The KAS sign-in section of
docs/system-specs/modules/acp-client.mdand the MCP Servers row section ofdocs/system-specs/modules/connections.mddescribe these.Overlap with #35802. That PR edits the same branch of
_note_mcp_sign_in_status, and the report's status branch that main has since moved intoread_status_snapshot, for a different entry: a failed server with no saved sign-in, decided by a tokenless probe. It leaves a server with a saved sign-in alone; this PR is that other half. The two conditions do not contradict each other. Whichever merges second rebases those hunks.Backwards compatibility
Compatible: a
failedKAS entry whose error is one of the two refused-sign-in shapes moves from "failed" to "waiting for a sign-in" in the session report, and a chat gains at most one notice row. Every other entry reads as before.Removes nothing: the diff adds a condition to two branches, one notice row and one chat-page renderer.
Tests
test/test_kas_mcp_refused_sign_in.py: the texts the engine reported read as refused or not; a refused entry is tracked, starts nothing by itself, and starts one sign-in when the message names the server; a 5xx, an unreachable endpoint and a bad command are not tracked; a server that connects again leaves the tracker; the session report lists a refused entry underawaiting_authand a curable one underfailed.test/test_mcp_sign_in_needed_notice.py: one row, once per chat, with the servers in itsmeta; a long list is capped and counted; a server with an open sign-in card is left to that card; a finished card does not count; nothing waiting shows nothing; a row that cannot be built does not raise; publishing a report with a refused entry shows the row.website/src/pages/chat/McpSignInNeededNotice.test.tsx: the card shows the row text with no page link, a 128-character server name carries no class that stops it wrapping, and the chat page picks it for this row ahead of the plain notice.website/src/test/McpTab.refusedSignIn.test.tsx: with the probe's output for a server that holds a saved sign-in, a server added from the page offers Sign in again; a server added any other way shows the new sentence and no button; a server whose tools the page lists shows neither.test/test_state_parts_facade.py,website/src/test/chatRolesParity.contract.test.ts,website/src/test/CrewChatWindow.test.tsx: the three inventories list the new slot flag and the new row.Proof: not provable -- other: re-run on
ead7f0cc276b: prove.py reverts every production hunk at once, which removes the new function the tests import, so its run errors at collection (INCONCLUSIVE); --per-hunk ends with an environment error (pytest wrote no report for one mutated run).By hand, seven mutations of the new production lines, one at a time, each turned a new test red: the tracker condition, the report condition, the passing-error exemption, the 4xx anchor, the once-per-chat flag, the open-card filter, and the open-link check on a card. The dead-child read gate on a card is pinned by
test_a_card_whose_child_is_gone_does_not_count[c2]and[""], which were red on895fcbaacb94before the gate was added.Determinism: the new tests use no clock, sleep, port or network.
Manual verification
kiro-cli acp --agent-engine v3, engine 3.2.1, against an OAuth MCP server on loopback with made-up tokens. No real OAuth client or account.error_description. The spec names this limit.Screenshots / video
Component render, not the live page. The shots below are the real
McpSignInNeededNotice(through the transcript renderer) and the realMcpTab, drawn from fabricated rows by a local capture entry inwebsite/capture/(not part of this PR) on head6d22b48881d1. No gateway ran.The notice for one server, two servers, and five servers plus two more:
The same rows in German:
A 320px-wide chat with a 128-character server name, which wraps inside the card:
The MCP Servers row for a server added by hand, which holds a sign-in and lists no tools on this page:
Related Issues
Part of #34492
Refs #34476
Sibling sweep
Swept:
git grep -n 'failedAuthorization' -- src/andgit grep -n 'awaiting authorization' -- src/Sibling: src/kiro_crew/acp/mcp_session_report.py:389 -- not affected -- the readiness barrier reads it only for Crew's own managed servers, which do not sign in with OAuth
Sibling: src/kiro_crew/acp/client_mcp_array.py:1442 -- not affected -- a start-timeout summary; a refused sign-in is still named there as failed with its error text
Sibling: src/kiro_crew/acp/runtime_session_registry.py:591 -- not affected -- the same start-timeout summary on the shared runtime
Sibling: src/kiro_crew/connections/mint_kas.py -- not affected -- an explicit Connect already replaces saved tokens for a failed server (#35396)
Pattern harvest
Not generalizable: one engine reports a refused token renewal as a plain failure; the fix reads that engine's two texts.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)