Repository navigation
fix(dashboard): reconnect quietly on a relay token renewal or drain - #34119
Conversation
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. The close-code check sits in one owner module, only the relay's codes change behaviour, and the health probe still restores the stopped-retry path once the token is renewed. Notes
[DESIGN-REVIEWED] 20d8d80 Description read[DESCRIPTION-READ] 58c44c95628c890b8910dce5b73c877360db7a03cd0f938230139aa12c7d446e 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The quiet reconnect, the stop-retrying rule and the two reasons each come from the relay protocol fixture ( What this change shipsInventory (8 items) — 8 justifiedIntent: someone viewing a Crew through the Kiro relay stops seeing a false "offline" at every token turnover, and is told why when the connection really is gone. FIX.
[FIRST-PRINCIPLES-REVIEWED] 20d8d80 Description read[DESCRIPTION-READ] 02d7e18217503fc8c714089fdc2144502fc304ea86e0cb74d635b0319ce6c172 That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS No blocker meets a Trigger/Outcome bar: the new strings say what happened, and every new state is in a screenshot. The one action the copy asks for happens outside the page. Notes
[UX-REVIEWED] 20d8d80 Description read[DESCRIPTION-READ] 87edcb0d1c706ab271b2999728751d7d5fe16c5abfbe087fe861c3da485e18c1 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: |
d463ff1 to
bbb813f
Compare
|
|
bbb813f to
7414c44
Compare
7414c44 to
20d8d80
Compare
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved. On this head the review traced every close path in connection.ts: the quiet 4401/1012 reconnect, the 5 s grace timer, the stop rule after a failed renewal reconnect, and the reset when a socket opens. It also confirmed the health probe still brings a stopped session back, and that a direct gateway connection takes the same path as main because the gateway only closes with 1008. The new hook, classifier and offline-reason tests ran on this head and passed. Reverting connection.ts to main, deleting the stop rule, or keying the stop rule on the shown reason each fails the tests named in the PR body.
Well done: the stop rule depends on the socket that is closing, not on the reason shown on screen, so a probe reconnect that drops goes back to normal backoff. A dedicated test pins this, and the relay close codes live in one small owner module with its own test.
Optional:
- #33825 also edits connection.ts and removes resetBackoff, the open hook where this PR clears the quiet timer and the remembered cause. Whichever PR merges second should move that clearing into the open hook that remains, and both bodies should name the merge order.
- Deleting
causeRef.current = undefinedin resetBackoff fails no test. A test for refused, then open, then a plain 1006 drop, asserting no relay reason, would pin it. - The PR body still links an internal tracker. Please remove that line. A body edit only re-runs readiness.
Problem / Motivation
Goal: A Crew dashboard opened through the Kiro relay stops flashing "offline" each time the relay turns its socket over, and says why when the connection really is gone.
Closes #34111
The relay closes the dashboard's
/api/wssocket with 4401 when the access token it opened with expires, about every five minutes, after the app holding the token has already renewed it. It closes with 1012 when it drains. The next socket opens about a second later. The dashboard treats both like any other drop, so the top-bar capsule turns red and the phone strip says "Gateway offline — reconnecting" every few minutes. When the token really could not be renewed, it says the same thing, which points at a reconnect that will never succeed.Relay build plan item 7B: CREW-24633.
Why it matters
Anyone viewing a Crew through Kiro Mobile or the desktop app's relay Crew window sees a false outage every token turnover. The relay design treats a close at token expiry as not an error: the client reconnects and shows nothing.
Not a goal
CreateCrewAccessToken, "relay unavailable"), which the relay design leaves to the clients.What changed (motivation → approach → change)
The dashboard socket now reads its close code (
relayClose.ts). 4401 is a token renewal, 1012 a relay drain, 4400 to 4499 a relay refusal, and everything else a plain drop. Crew's own gateway sends none of these codes on/api/ws, so a direct connection behaves as before.For a renewal or a drain of a socket that had opened,
connection.tsreconnects at once and leaves the dashboard connected. If the new socket opens, nothing was shown. If it fails, or has not opened after 5 s, the dashboard goes offline; after a 4401 the reason issession_ended, and the dashboard stops retrying. The relay refuses an expired token with a plain 401 at the upgrade, which the browser reports as a 1006 close with no open, the same as a network drop, so only the 4401 before it identifies the case. Retrying with that token cannot succeed. The health probe's reconnect, which runs when/api/statusanswers 200 again, still brings the session back, and if that socket drops before it opens the normal backoff resumes. A refusal goes offline at once with reasonrefused. The reason (offlineCauseindashboardSlice.ts) stays until a socket opens.appShell.tsxturns it into the capsule's accessible name, whichshellHeader.tsx's phone strip now shows too: "Relay session ended — reopen this Crew" or "Relay refused the connection — retrying". With no reason, both keep "Gateway offline — reconnecting". The two strings are added toen.manual.jsonand the eleven translated catalogs, anden-XA.jsonis regenerated.Backwards compatibility
Compatible: a socket closed with any code outside 4401, 1012 and 4400 to 4499 is handled exactly as on main, and Crew's gateway sends none of those on
/api/ws.markGatewayDisconnectedandsseDisconnectedtake an optional reason; existing callers pass none.Tests
website/src/test/useWebSocket.relayQuietReconnect.test.tsdrives the real hook with a mock socket. It checks that 4401 and 1012 reconnect at once and never show offline, including across repeated renewals. It checks a failed reconnect after 4401 (refused at the upgrade, or still opening after the grace) showssession_ended, and that the reason survives later failed reconnects, including a health-probe replacement after the grace. It also checks that a failed reconnect after a 4401, whether it fails at once or after the grace, opens no further socket for two minutes, that the health probe still brings it back and an open clears the reason, that a probe reconnect which drops goes back to the backoff, and that a direct dashboard whose handshakes keep failing stays plain offline and keeps retrying. It also checks that a failed reconnect after a drain shows a plain offline, that 4429 showsrefusedat once, and that a plain drop still goes offline at once.website/src/hooks/websocket/relayClose.test.tscovers the code table.website/src/test/offlineReason.test.tscovers the wording.website/src/test/gatewayConnectedPairing.test.tsandwebsite/src/test/useWebSocket.ownership.test.tsnow admit the reason argument and the new owner module.Proof: not provable -- frontend test (prove.py runs Python only)
Run by hand instead: with
connection.tsreverted to main, the hook test file fails 12 of 14. With only the new stop rule reverted, the two stop-retrying tests fail. With the stop keyed on the displayed reason instead of the failed reconnect, the probe-reconnect test fails. With the stop rule widened to every reconnect after a first connect, the direct-dashboard test and the plain-drop test fail.tsc -p tsconfig.app.jsonis clean. The 269 test files that reference the changed modules all pass, as do the i18n parity and duplicate-key tests. The full local gate did not run:scripts/local-gate.pyselects 1,244 backend and 138 frontend files for this diff, and avitest relatedrun over the changed sources timed out at 25 minutes on this host, so the change is held to the 269 files above,tscand CI.Manual verification
Run against the production build with Playwright, socket closes faked through
page.routeWebSocket(phone viewport, where the strip shows). The appearances column counts every time the offline strip appeared during the run. The first one in every row is page load, before the first socket opens.A manual relay test on the previous head (bbb813f), with a host Crew on the beta relay and a Firefox viewer holding a session cookie that was never renewed, found the gap this head fixes. After the token expired, the page tried
/api/ws12 times over about two minutes with growing backoff. Every try got HTTP 401 at the upgrade, so no socket opened and no close code arrived, and the page kept retrying a token that could no longer work. On this head, the first reconnect that fails after the 4401 shows "Relay session ended" and no further tries are made. That is pinned by the unit tests above and has not been re-run against the relay.Not checked: a real Kiro Mobile WebView or the desktop relay Crew window. Those renew the token, so the quiet path is the one they take.
Screenshots / video
Shot on 20d8d80 (after) and main (before) from the production build, socket closes faked with Playwright, cropped to the top bar. Each pair is before, then after.
Desktop, 1300 px. On desktop the reason is the capsule's accessible name and tooltip, not visible text, so the pairs look alike; the measured name is under each.
4401, then the token is not renewed. Before: "Gateway offline — reconnecting". After: "Relay session ended — reopen this Crew".
4401, then the next socket opens. Both end connected; counting every offline appearance during the run, main showed offline twice (page load, then the flash) and this PR once (page load only).
Phone, 390 px, where the strip shows the reason as text.
In this harness
/api/statusanswers 200, so the health probe keeps bringing the socket back; on the real relay it gets a 401 too, which is why Tim's run on this head saw one failed try and no more.Related Issues
Closes #34111
Sibling sweep
Swept: git grep -n "onclose = " -- website/src ':!.test.'
Sibling: website/src/apps/mochi/panel/panelBridge.ts -- not affected -- its socket never moves the dashboard connected flag or its offline wording
Sibling: website/src/apps/crew-companion/sessionWatch.ts -- not affected -- its socket never moves the dashboard connected flag or its offline wording
Pattern harvest
Not generalizable: the relay's close codes are read in one place, the dashboard socket, and no other socket shows the dashboard's offline state.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)