Repository navigation
fix(dashboard): watch only the visible file tab, re-read on return - #14262
Conversation
GPT 5.6 Review — ✅ human override acceptedHuman judgment by @pepmach overrides the GPT 5.6 finding for [GPT-OVERRIDE] 673afc5 This comment is updated in place on each push. The model was not re-run because an authorized human decision supersedes it. False positive or not applicable? A repository writer can comment: |
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Placeholder detection by string-equality with a localized sentence makes the last-copy guard depend on the current locale, not on tab state. Watch
[DESIGN-REVIEWED] 673afc5 |
UX Review (Fable 5) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS The tab strip's × still skips the new discard guard, so the most habitual close silently loses the last copy the banner warns about. Watch
Suggestions
[UX-REVIEWED] 673afc5 |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The frozen Not justified as shipped
What this change shipsInventory (10 items) — 8 justifiedIntent: FIX — stop six idle file-tab watch streams starving every other dashboard request (#14236), and stop a file deleted under an open tab taking its last copy with it (#14365).
[FIRST-PRINCIPLES-REVIEWED] 673afc5 |
Opus 5 Review — ✅ no blocking findingsReviewed Review detailsNo findings that block. FINDING — website/src/components/MarkdownPanel.tsx:1541 — the placeholder exclusion compares the buffer to a localized string ( FINDING — website/src/utils/fileReadQuery.ts:44 — [OPUS-REVIEWED] 673afc5 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
5310ee3 to
2d86b96
Compare
|
2d86b96 to
17f66b6
Compare
17f66b6 to
98555c5
Compare
98555c5 to
49c24ab
Compare
|
Description gains the |
39b3892 to
8a28f7c
Compare
8a28f7c to
e3735e8
Compare
Every open file tab in the chat side panel held its own /api/file-watch EventSource whether or not it was visible. The gateway serves HTTP/1.1 and Chromium allows six connections per host, so six idle tabs starved every other request the dashboard makes (uploads, chat sends, polls). MarkdownPanel arms the watch only while the tab is the visible one, and a tab re-reads its file when it becomes visible again, through the same readFromDisk/applyDiskRead pair and under the same dirty/superseded guards, so a change made while the tab was hidden is on screen on reactivation. A tab with unsaved edits keeps them and does not re-read. Fixes #14236
|
AI-review override not recorded: keep the reason to 500 characters or fewer. |
|
|
|
|
|
|
|
|
|
/ai-review override gpt 673afc5: The review's own flag, not a data-loss path: it needs a file whose whole content is byte-identical to the locale's "file not found" sentence (MarkdownPanel.tsx:1537). The seeded sentence cannot be saved back -- saving is dirty-gated (:2597, Cmd+S :2552/:2610, the edit band collapsed until dirty :2700) -- so such a file must be authored to say exactly that, and all a guard-less close then discards is that catalog sentence (en.manual.json:4566): reconstructible. Tab flag tracked in #14449. |
Human judgment recorded@pepmach marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
Problem / Motivation
Goal: Open several files as tabs in the chat side panel without the dashboard's other requests stalling behind their file-watch streams -- and without a file that disappears under an open tab taking its last copy with it (#14365).
Open six files as tabs in the chat side panel and the dashboard stops talking to the gateway: the attach button spins, a sent message waits, polls stop arriving. Every open file tab holds its own
GET /api/file-watchstream, whether or not the tab is visible. The gateway serves HTTP/1.1 and Chromium allows six connections per host, so six idle tabs hold all six, and every other request sits in the browser's queue until one of them ends (#14236, with the HAR: six streams open for 52 s, the uploads and about 20 other requestsblockedbehind them).Why it matters
Anyone who keeps a handful of files open while chatting is hit, on every platform the desktop app runs on. The stall is silent: the gateway is healthy and answers as soon as a request reaches it, so nothing on screen says why the message is not going out.
Not a goal
ArtifactPanel's hidden-tab streams: the same pattern, its own fix (dashboard: a hidden file-backed artifact tab keeps its own /api/file-watch stream open #14259), where the catch-up machinery here is extracted into a shared hook.missingframe fromapi_file_watch, a redaction header fromapi_file_read): the panel works from what the read returns today; the header is a follow-up.SidePanel.tsx(refactor(dashboard): host the session side panel inline in main, not a portal #12662's file), which onmainbypasses the panel's close guard for dirty tabs too.What changed (motivation → approach → change)
The watch was armed on
liveWatch && !editing && !dirtythoughSidePanelkeeps hidden tabs mounted; now onactivetoo.A tab with no stream would go stale silently, so it re-reads on becoming visible, on mount and on leaving edit mode. One procedure,
adoptDisk, one rule: every read is a freshGET /api/file-read, never the opening read or a cached body, which can predate the change.A tab is caught up only once a read has APPLIED:
adoptDisksettles adue/reading/donelatch and nothing else writesdone. A read the typing overtook leaves the tabdue. The first edit of a clean buffer withdraws any read in flight; save, undo and discard each start one. A save clearsdirtyonly if no keystroke landed during its write (editGenRef) and, like every read, drops the shared cache entry. The stream's first frame is compared, never applied: equal to the clean buffer, no read unless one is in flight; otherwise a re-read.A gone file (404) is a state, not content: every read that meets it records it, dirty or not, so the retry and the parked stream never depend on the buffer; banner and guards need a real last copy. Buffer and baseline keep the last text under a banner ("File not found on disk — nothing else holds its contents; download it or save it elsewhere to keep it.") with two buffer exits. Refresh and Cancel on a gone file raise the banner. Closing asks first ("Discard the file’s remaining contents?", file and edits named, Download beside them): the unsaved-edits prompt would imply a saved copy. A live-watched tab asks the disk first (the watch polls on silently through a deletion); a read typed past closes nothing; a failed one asks "Close without checking the disk?" -- only over a buffer that could be a copy, the dialog the sole report. A rail click re-targeting a clean tab asks the disk first too; a copy found, or a read that could not answer, opens the next file beside it. A PARTIAL buffer -- its read cut at the gateway's cap (
X-Truncated), redacted (X-Redacted) or decoded with replacement characters (X-Lossy-Decode;api_file_readnow sets both new headers) -- carries that verdict on the TAB from whichever read filled it, the opening read included, never guessed from the body. It is guarded like a whole copy; only the words change: "only part of it", a.partialdownload. Meanwhile the tab holds no stream (a 404 stream closes for good) and retries the read once the last settled, never over one in flight, the wait doubling 1 s to 30 s (each GET is a SEL record), until one finds the file and re-arms the stream; a failed read is reported once.Changed:
website/src/components/MarkdownPanel.tsx;website/src/utils/fileReadQuery.ts(header verdicts onFileReadResult),website/src/hooks/usePanelTabs.ts(PanelTab.partial, transient likebinary),website/src/hooks/usePanelDocumentActions.ts,website/src/pages/ChatPage.tsx,website/src/pages/chat/SidePanel.tsx(verdict plumbing; disjoint from #12662),website/src/utils/fileReadUrl.ts,src/kiro_crew/dashboard/handlers/files.py(X-Redacted,X-Lossy-Decode),website/src/i18n/locales/(thirteen keys, twelve languages),website/scripts/capture-file-tab-missing-on-disk.mjs. Untouched:useFileWatch.ts. Not here:ArtifactPanel(#14259).Backwards compatibility
Compatible: same props, same host callbacks; a tab that is visible behaves as before. The new requests are one
GET /api/file-readwhen the visible tab mounts (right after a chip open too: one more than the opening read), one when a hidden tab comes back, one when a buffer the user edited becomes clean again (save, undo, discard), and one when a clean tab leaves edit mode.Tests
website/src/test/MarkdownPanel.watchVisibleTab.test.tsx(new, 42 cases), red-first onmain@ f6d8b7f: the first assertion failed withexpected [ StubEventSource{ …(5) }, …(5) ] to have a length of 1 but got 6.onDiskContent;.tsfile) re-reads on activation and still holds no stream;expected "vi.fn()" to be called with arguments: [ '/tmp/b.md', …(2) ]);export const x = 2landed over the savedexport const x = 3);expected 'export const x = 1\n' to be 'export const x = 3\n', the cached pre-save body restamped the save);onDiskContentnever called with'');fetchFileReadis spied; one fresh call per mount, per return and per save, equal to theGETcount, with a fresh cache entry seeded before each step (red-first on 49c24ab: the mount made no fetch);GET; a frame with a real change still re-reads (red-first on 2d86b96: two reads per activation);file-readentry (red-first: the entry survived);onClosefires once (red-first on 49c24ab: no dialog);onClosefired, no dialog);onClosefired on the stale clean state);b.md.partial(the buffer's bytes), Escape opens the last-copy prompt in the partial wording and its Download is.partialtoo; a WHOLE buffer that merely quotes[REDACTED: credential], unmarked: the whole-copy banner,b.md, the plain prompt (red-first on 8a28f7c: the body sniff called the quoting file partial; on 5c06505: the panel had seen no read of its own and called a partial buffer whole; the guard: a partial buffer closed with no prompt);partial: truewith the text when the response carriesX-Truncated, and a whole read over a tab still marked partial restamps it although the text is unchanged (red-first on 8a28f7c: two-argumentonDiskContent);/api/file-downloadrequest and no "Download failed" (red-first on 167b903: no blob);expected true to be false);true); a failed check spares the tab too, an intact file re-targets;X-Lossy-Decode(a Latin-1 file decoded with replacement characters) marks the tab partial throughonDiskContentand throughopenFile, so its banner says partial and its download is named.partial;/api/file-downloadrequest; Copy content copies the buffer and shows "Copied" on the button, and a refused copy raises the panel's action notice (red-first on 49c24ab: no Download button; on 7fe7a91: no "Copied", the refusal vanished).The stale-content regression the maintainer pipeline warned about is the second, third, fourth, sixth and seventh case.
MarkdownPanelMoreCoverage.test.tsx's failed-watch-re-read test now lets the mount read land before it fires the failing frame.sidePanelColdTabHydration.test.tsx: a hydration read answeringX-Truncatedstamps the tab partial, and the persisted tab drops the flag likebinary.usePanelDocumentActions.redactionEpoch.test.ts: the opening read'sX-Redacted/X-Truncatedheaders reachtabsCtl.openFileaspartial: true, a plain read asfalse.test/test_dashboard_file_io.py: a read whose body the credential pass rewrote carriesX-Redacted: true, a Latin-1 file carriesX-Lossy-Decode: truewith a replacement character in the body; a plain UTF-8 read carries neither. Green on this head: the module file (42), the related frontend files (sidePanelColdTabHydration,usePanelDocumentActions.redactionEpoch,MarkdownPanel.binaryCard,MarkdownPanelCoverage,usePanelTabs,BinaryFileCard,useFileWatch,i18nLintExemptions: 242 tests), the i18n parity, style and QA gates with the thirteen keys (707),test_dashboard_file_io.py+test_file_watch.py(71,-n0).Manual verification
Browser:
website/scripts/capture-file-tab-missing-on-disk.mjsruns the built SPA against fixtures (the file tab seeded, its read answering 404 after the hydration, its stream delivering one frame), waits for the banner text, its two buttons AND the document heading to be on screen together, captures the frames below in two languages, then sends Escape to the document and captures the confirmation it opens, the "Copied" answer, the banner in a 360px full-screen layout (asserting both buttons visible and the band inside the viewport), and -- in a context with no clipboard -- the refused-copy notice; a pass restores the tab with unsaved edits over a gone file and captures the prompt that names them; a pass seeds the tab from a read answeringX-Truncated, then 404, and asserts the partial banner, that the browser is handedrelease-checklist.md.partial, and the partial prompt; two passes fail the close-time read (500) on a clean and on a dirty tab and capture "Close without checking the disk?". The stream and request counts are unit-tested (the tests countEventSourceinstances andfile-readrequests directly). A preview pod could not be driven: it booted, but its token mint was refused for this caller (member_owner_token_refused).Rebased onto main
8abbf3a64dafter #14398 merged (the prepare-pr size ratchet and theCrewWebviewContainmentclock test are healed there).Screenshots / video
The visible tab's file deleted outside the dashboard after the tab was hydrated: the last copy stays on screen and the banner sits over it, with Copy content and Download beside the sentence. Two languages, because a lone English frame does not prove the banner comes from the catalog. Then the close: Escape opens "Discard the file’s remaining contents?" over a body that names the file and the Download way out, with Cancel and Discard the contents -- the one exit that discards the copy asks first; a tab restored with unsaved edits gets the body that names the edits too. Then the copy button's two answers: "Copied", and the notice a refused clipboard raises. Then a PARTIAL copy (the opening read was cut at the gateway's cap): the banner says so and the prompt uses the partial wording. Then the close-time read itself failing, on a clean and on a dirty tab: "Close without checking the disk?" with Close anyway.
Full dashboard frames
Related Issues
Fixes #14236
Also fixes #14365 (the deleted-file data loss the last-copy surface answers).
Pattern harvest
Rule candidate: review-prompt
Pattern: a per-instance background connection (EventSource, WebSocket, long poll) armed on "mounted" rather than "visible", in a host that keeps hidden instances mounted.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)