Repository navigation
fix(terminal): reconcile restored dock tabs with the backend at hydrate - #11133
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify a reloaded popout window with suspect tabs settles (dock tests cover the gate; the popout-reload path is only reasoned, not in the test list). Suggestions
[DESIGN-REVIEWED] da72c85 |
UX Review (Fable 5) — ✅ PASSUX-level review of UX-Verdict: PASS Verify the gated dock stays blank only imperceptibly on a real gateway — a hung probe leaves an empty frame, no feedback, for up to ~40s. Suggestions
[UX-REVIEWED] da72c85 |
GPT 5.6 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 5.6 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- website/src/App.tsx:1375 -- Hydrate probe failures have no error surface Adjudication (Opus 4.8) — is blocking on each finding proportionate?I have what I need. Let me record my analysis. F1 analysis — The catch block at Checking whether the blocking rule actually anchors: the rule governs how an error that is shown to the user renders, and its blocking triggers are (a) a hand-written error surface, or (b) a touched/added Weighing it:
LOW harm; conditions confirmed at False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS Fix lands only in the dock store — usePanelTabs restores persisted terminal ids the same way, so dead side-panel tabs still respawn shells on reload. Not justified as shipped
What this change shipsInventory (7 items) — 5 justifiedIntent: stop dead persisted dock terminal tabs from coming back — and respawning shells — on reload; a FIX (#10977, #10822).
[FIRST-PRINCIPLES-REVIEWED] da72c85 |
Opus 4.8 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: |
abc7bff to
0cb1d63
Compare
|
CI note on The stale |
|
CI note on |
`loadPersisted` restored the dock terminal tab list without asking the backend which PTY sessions still exist. A tab leaked by a "Run in terminal" dispatch whose page closed before its rollback deadline (#10822), or one whose shell the orphan reaper has since killed, therefore came back on every reload — holding a slot in the per-panel tab cap and, the moment its view reconnected, minting a fresh shell nobody asked for (the WS route spawns a PTY for an id it does not know). The store now marks the restored set as pending at module init and rules on it against `GET /api/terminal/sessions`, which App already fetches at boot. The ruling takes two looks, the protocol #10859 gave the dispatch-deadline probe: the route skips the placeholder a session holds until its shell spawns, so a session another window is opening reads like one that never existed, and this store is shared across windows. The first answer only names suspects (absent or `alive: false`); an uncached second answer after the opening grace drops the ones still missing and keeps the ones now live. The trimmed list is persisted and focus moves to a survivor. An answer that does not rule — request failure, unrecognized shape, or the feature-disabled reply, which returns an empty list without consulting the registry — keeps every tab, since removing a live shell's scrollback cannot be undone while a kept dead tab is user-closable and reaped server-side. Tabs minted after boot are never candidates. Both looks run under a deadline: the panel stays gated until they settle, so a socket that never answers must be made to answer, and past the bound it reads as a failed probe that keeps every tab. `TerminalTabsView` draws nothing while the ruling is pending. Effect order made that necessary rather than cosmetic: a CliPanel mounted for a restored tab opens its socket before the App-level probe fires, so the probe would find the very shell it was asked about and keep the tab. Closes #10977
0cb1d63 to
da72c85
Compare
|
CI note on |
|
|
|
|
|
|
CI note on |
iamwhatever
left a comment
There was a problem hiding this comment.
Approved after a full read of the diff on the current head: the change matches the linked issue and body, every load-bearing claim was spot-checked against main, tests pin the behaviour, all review lanes are clean and nothing is left undisposed on this head.
…te (kirodotdev#11133) `loadPersisted` restored the dock terminal tab list without asking the backend which PTY sessions still exist. A tab leaked by a "Run in terminal" dispatch whose page closed before its rollback deadline (kirodotdev#10822), or one whose shell the orphan reaper has since killed, therefore came back on every reload — holding a slot in the per-panel tab cap and, the moment its view reconnected, minting a fresh shell nobody asked for (the WS route spawns a PTY for an id it does not know). The store now marks the restored set as pending at module init and rules on it against `GET /api/terminal/sessions`, which App already fetches at boot. The ruling takes two looks, the protocol kirodotdev#10859 gave the dispatch-deadline probe: the route skips the placeholder a session holds until its shell spawns, so a session another window is opening reads like one that never existed, and this store is shared across windows. The first answer only names suspects (absent or `alive: false`); an uncached second answer after the opening grace drops the ones still missing and keeps the ones now live. The trimmed list is persisted and focus moves to a survivor. An answer that does not rule — request failure, unrecognized shape, or the feature-disabled reply, which returns an empty list without consulting the registry — keeps every tab, since removing a live shell's scrollback cannot be undone while a kept dead tab is user-closable and reaped server-side. Tabs minted after boot are never candidates. Both looks run under a deadline: the panel stays gated until they settle, so a socket that never answers must be made to answer, and past the bound it reads as a failed probe that keeps every tab. `TerminalTabsView` draws nothing while the ruling is pending. Effect order made that necessary rather than cosmetic: a CliPanel mounted for a restored tab opens its socket before the App-level probe fires, so the probe would find the very shell it was asked about and keep the tab. Closes kirodotdev#10977
What
On reload, the dock terminal store now settles its restored tab list against the backend before any terminal view mounts. Restored tabs whose session
GET /api/terminal/sessionsomits, or reportsalive: false, are dropped once a second, uncached look after the opening grace still misses them; the trimmed list is persisted and focus moves to a surviving tab. Tabs minted after boot are never candidates.Why
loadPersisted(website/src/hooks/useBottomTerminal.ts) restored persisted tab ids without asking the backend which PTYs still exist. A tab leaked by a "Run in terminal" dispatch whose page closed before its rollback deadline (#10822, fixed in-page by #10859), or one whose shell the orphan reaper has since killed, came back on every reload — occupying a slot in the per-panel tab cap (the #10822 reporter saw 5 restored tabs, 3 already dead), and re-spawning a fresh shell the moment its view reconnected, because the WS route mints a PTY for an id it does not know. Item 1 of #10977.How
useBottomTerminal.ts: the restored id set is captured at module init and flagged pending. The ruling takes two looks, the same protocol fix(chat): roll back the dock tab a failed run-in-terminal dispatch minted #10859 gave the dispatch-deadline probe and for the same reason: the sessions route skips theNoneplaceholder a session holds fromws.prepare()until its shell spawns, so a session another window is opening right now reads exactly like one that never existed — and this store is shared across windows.reconcileRestoredTabs(first)names restored tabs the first answer omits or marks dead as suspects without dropping anything;confirmRestoredTabs(second), fed an uncached answer taken afterRUN_IN_TERMINAL_OPENING_GRACE_MS, drops the suspects still missing and keeps the ones now listed live. Either look that cannot rule — request failure, unrecognized shape, or the feature-disabled reply (which returns an empty list without consulting the registry) — keeps every tab and settles: dropping a live shell's scrollback is irreversible, while a kept dead tab is user-closable and its registry entry is the reaper's to clear (it runs every 60 s).useTerminalHydratePending()/isTerminalHydratePending()expose the gate;__resetBottomTerminalclears it.App.tsx: theterminal-enabledquery already fetches/api/terminal/sessionsat boot; an effect hands its result to the first look and, when there are suspects, waits the grace, fetches once more uncached, and hands that to the confirm look (nullon any failure so a probe that never answers still settles). Both looks run underwithDeadline(TERMINAL_PROBE_TIMEOUT_MS, 10 s): the panel stays gated until they settle, so a hung socket must be made to answer — past the bound it reads as a failed probe and keeps every tab (GPT round-2 advisory, fixed rather than dispositioned).BottomTerminalPanel.tsx:TerminalTabsViewrenders nothing while the ruling is pending. This is required, not cosmetic: child effects run before parent effects, so aCliPanelmounted for a restored tab would open its socket — and spawn a shell — before the App-level probe fired, and the probe would then find the very shell it was asked about and keep the tab. Both hosts (dock and popout) share this view.No DELETE is issued for
alive: falseentries: the reaper and the WS reconnect path already clear dead registry entries, so a client-side delete would be a second writer for the same fact.Not in this PR (per the issue): item 2 (visible notice at the tab cap) belongs to #10120, which rewrites this hook and already carries the notice; item 3 (blind send into a confirmed-alive shell) is a readiness-contract question owned by #7638 / RFC #7649.
Tests
Run by path with
npx vitest run <file>; all mutation-verified (fix reverted, test fails, fix restored).src/test/useBottomTerminal.hydrateReconcile.test.ts(16): pending only when storage held tabs; the first look names absent and dead tabs as suspects and drops nothing; the confirm look drops the still-missing suspects withactiveIdrefocus and the trimmed list persisted; a suspect the second look lists live is kept (the other-window-opening case); no suspects settles at once; all-gone hides the panel; a tab minted after boot survives both looks omitting it; five non-ruling first-look payloads keep every tab and settle; a non-ruling confirm keeps every suspect; settled sets cannot be reopened; a repeated first look while confirming is a no-op (query refetch); subscribers are notified per phase. Red on base: the module exported no reconciler.src/test/BottomTerminalPanel.hydrateGate.test.tsx(2): noCliPaneland no tab strip while pending and while confirming, then only the kept tab mounts; every tab mounts when the first look could not rule. Boots the store fresh from seeded storage so the restored set is real. Red with the gate line removed.src/test/App.terminalHydrateReconcile.test.tsx(4): both looks omit a tab → dropped, and at least two probes were made; first look omits, second lists live → kept; a confirm look that never answers (mswdelay('infinite')) → settles after grace + deadline keeping every suspect; failing request → both kept. Red with the confirm drive replaced by an immediate drop, red with the deadline removed (the hang case runs out its 14 s wait), and red with the App effect removed (the panel would otherwise stay gated forever).App.terminalNavActive,App.terminalEnabledFlag,BottomTerminalPanel.cwd,BottomTerminalPanel.popout,ChatPageMoreCoverage,SidePanelLayout.bottomFloatTerminal,TerminalPopoutFrameCov80,terminalChordFocus,useBottomTerminal.viewportClamp,fenceShell(113 tests, 10 files).npx tsc -b --forceandnpx eslinton the changed files: clean.Pattern harvest
Rule candidate: review checklist. Pattern: a client that restores persisted references to server-side resources (tab ids, session ids) without a liveness check at hydrate — the persisted list is treated as truth for a resource the server owns. The two-look absence protocol (absent once is "opening or gone", absent twice across the opening grace is "gone") now exists in two places (dispatch deadline, hydrate); a third caller should extract it.
Other
Why no screenshot: the change adds or restyles no UI element. Every state it can produce already renders today — the dock with N tabs, or closed — so a screenshot would show an existing panel with fewer tabs. The user-visible delta is that tabs whose shells are gone no longer come back after a reload, plus a brief empty frame (two probe round-trips plus a 2 s grace, only when a restored tab is suspect) before the kept tabs mount. A popout window whose restored tabs are all gone returns itself to the main window, as it already does when its last tab closes.
App.terminalHydrateReconcile.test.tsxpins all four. Worst case on a gateway that accepts the socket and never answers: react-query's default retries of the bounded first look, then the grace and the bounded confirm look — well under a minute before the panel settles keep-all, versus never before this round.Closes #10977