Repository navigation
Conversation
The Command Bar's Folders view derives its rows from the sidebar's own
`['chat-folders']` cache, but cached them under `['command-bar', 'folders', q]`
— a key outside that namespace. React-Query invalidates by key PREFIX, so the
`invalidateQueries({ queryKey: ['chat-folders'] })` that ends every folder
create, delete and update in `ChatSidebar` reached the corpus and not the rows
built from it.
`QuickSearchSurface` mounts the overlay only while the bar is open, and a
remount refetches only what is stale. A folder deleted while the bar was closed
therefore came back on the next open: listed, selectable, and carrying an id the
sidebar no longer has, so activating it asked for a reveal that silently did
nothing. The window is the view's own `staleTime`, 15s.
The key is now nested under the corpus, `['chat-folders', 'command-bar', 'view',
q]` — the shape the artifacts view in this same file already uses
(`['artifacts', 'command-bar', 'view', q]`), which is why that view has never had
this gap. Nothing reads `['chat-folders']` as a prefix except `invalidateQueries`
and `cancelQueries`; every get/set in the repo uses the exact key, so no other
reader's match changes.
Named by the Design review on kirodotdev#12013 and shipped unaddressed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Opus 4.8 Review (fork) —
|
Design Review (Fable 5, fork) —
|
First Principles Review (Fable 5, fork) —
|
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
|
Kiro Crew [operator: chenmingwei23#de330d0c]: This PR has been inactive for 7+ days with failing CI. I have assessed the blockers and they appear resolvable - I will push fixes directly to this branch as a co-author. Assessment: Small fix (81 added lines, 2 files). GPT 5.6 returned PASS with no findings; the Opus 4.8 lane returned 'review incomplete' with no verdict, and Design plus First Principles 'could not complete' -- lane infrastructure, not code findings. Rebase onto main (branch is dirty), re-run the incomplete review lanes, and green Backend Tests (Windows) (1). If you would prefer I do not touch this PR, add the pr-no-autofix label. |
|
Thank you, @leonlaiyc, for this fix and the clear write-up of the root cause — the Command Bar's Folders view cached its rows under a key outside the Your commit is carried forward verbatim (you remain the author) in an in-repo replacement PR so it could run the full CI suite: #15339. It has driven fully green there. Closing this one in favor of that; full credit to you for the diagnosis and the fix. |
|
@leonlaiyc quick follow-up: your work here landed on |
Problem / Motivation
Delete a chat folder in the sidebar, then open the Command Bar (
⌘K) and stepinto Search Folders. The deleted folder is still there: listed in sidebar
order, selectable, and reachable by name. Pressing Enter on it closes the bar,
navigates to
/chatand asks the sidebar to reveal a folder id that no longerexists — so nothing is revealed and nothing says why.
Delete is the case measured here. Create, rename and reorder end in the same
invalidation, and so does the WebSocket's folder-generation refresh, so they
reach the view's cache by the same route — but only the delete is pinned by a
test, and this description claims no more than that.
The window is 15 seconds — the Folders view's own
staleTime— and it is aplain window, not a race: any open of the bar inside it shows the stale list.
Why it matters
The Folders view exists so a folder can be reached by name without hunting the
sidebar tree. A row that opens nothing is worse than a missing row: the user
cannot tell whether the launcher is broken, the reveal is broken, or the folder
was never deleted. Deleting a folder and immediately going looking for what is
left is the natural next action, which is exactly when the window is open.
What changed (motivation → approach → change)
The view's corpus is the sidebar's own folder list, read through the shared
['chat-folders']React-Query key — that sharing is deliberate, and documentedin the file, because
GET /api/chat/folderswalks the on-disk session list tocount archived sessions per folder, so a folder read is expensive.
The rows the view renders are derived from that corpus and were cached under
['command-bar', 'folders', folderQuery], a key outside the corpus namespace.React-Query matches invalidations by key prefix, and eight call sites
invalidate that corpus:
ChatSidebar.tsxon folder create (:5498), delete(
:5503), update (:5543) and reorder (:5614);settings/ChannelFolderBackfill.tsx:89; anduseWebSocket.ts:1467/:1493,which is how a folder changed by an agent, another tab or another device
reaches this client at all. Every one of them reached the corpus entry and
stopped there; the derived rows were a cache nothing could reach.
QuickSearchSurfacemounts the overlay only while it is open — a deliberatechoice recorded in that file, so a closed bar holds no live subscriptions — so
closing and reopening the bar is an unmount and a remount against the app's one
QueryClient. A remount refetches only what is stale, and the derived entry wasnever marked stale, so the reopened view re-served the pre-delete rows.
The fix is the key:
That is the shape the artifacts view in this same component already uses —
['artifacts', 'command-bar', 'view', artifactsQuery], nested under the corpusit derives from — which is why the artifacts view has no equivalent gap. The
folders view is now the same shape, so one folder invalidation reaches both the
corpus and the rows built from it, and the remount re-derives.
Every other consumer of the corpus reads it by exact key, so none of their
matches change. Full census on
234121ed0d19497570b3ec38014782109a321add(
grep -rn "\['chat-folders'\]" website/src, non-test):useQueryatChatSidebar.tsx:4408,SessionActionsMenu.tsx:132,JobForm.tsx:378,ChatPage.tsx:3089and this component's:517;fetchQueryatsessionsProvider.ts:338,recentsProvider.ts:272and thiscomponent's
:583;getQueryData/setQueryDataatChatSidebar.tsx:5510,:5511,:5534,:5582,:5593,:5607,:5625,:5964anduseWebSocket.ts:1462/:1464. The only prefix consumers are the eightinvalidateQueriesabove and onecancelQueries(ChatSidebar.tsx:5509, therename's optimistic
onMutate) — reaching the invalidations is the point, andthe cancel is self-correcting: the same mutation's
onSettled(:5543)invalidates, so a view query cancelled mid-flight is refetched rather than left
behind.
Symmetrically, nothing invalidates, removes or reads
['command-bar']as aprefix — the other two keys in that namespace (
:884,:906) are only everaddressed exactly — so moving this key out of it orphans nothing.
Deliberately not changed
sessionsProviderandrecentsProvideralso read['chat-folders'], but for adifferent purpose: a folder name to label a session row with, alongside two
other corpora of their own (
['palette', 'recents', 'history']and['palette', 'recents', 'crons'],recentsProvider.ts:258/:265). Their rows are not a view of the folderlist, so nesting
['command-bar', 'sessions', …]under one of its three inputswould make an unrelated folder write refetch a session search. Whatever is right
there is a different remedy, and this PR does not claim to have measured what
those two do after a folder write — only that the key change here does not touch
them.
Backwards compatibility
Compatible: a React-Query key is process-local cache addressing with no wire,
storage or API surface. Nothing is persisted under it, nothing outside this
component names it, and the request the view issues is unchanged.
Tests
website/src/apps/command-bar/CommandBarOverlay.folders.test.tsxdrops a folder the sidebar deleted, instead of re-listing it from the view cache— the regression. It runs the production sequence: enter the view,unmount the overlay (what closing the bar does), apply the sidebar's own
delete shape (
invalidateQueries({ queryKey: ['chat-folders'] })with thegateway now answering without that folder), remount against the same
QueryClient, and re-enter the view. Asserts the deleted folder is not a row.still serves the view from cache when nothing invalidated the corpus—the control, and the reason the regression pins the invalidation rather than
the guard. Same unmount/remount with no invalidation: the list is unchanged
and
api.chatFoldersis not called. Without it, simply dropping the view'sstaleTimewould pass the regression while paying for the expensive folderread on every open — the cost the shared key exists to avoid.
Harness change:
mount()takes an optionalclientso one cache spans twomounts, and the walk from the root into the view is factored out as
enterFoldersView()so the second mount can reuse it. No existing test'sbehaviour changed.
Red-before, with the production hunk reverted and the tests kept, on
234121ed0d19497570b3ec38014782109a321add:The control passes in that same run, so it pins the cache and not the fix.
Green-after:
src/apps/command-bar/— 10 files, 286/286.Manual verification
N/A — unit coverage sufficient: the defect is a cache-key match, and the test
drives the exact production sequence (unmount, the sidebar's own invalidation,
remount on one
QueryClient) that a hand-run would reproduce, including thenegative control that a live click-through cannot distinguish from a lucky
refetch.
Other gates run locally on the branch head, against
234121ed0d19497570b3ec38014782109a321add:tsc --noEmitclean;eslintclean on both changed files; Brand Name Gate andFocus Cue Gate pass diff-scoped against
origin/main(the Comment History Gateis Python-scoped —
src/kiro_crew,test,.py— so it passes this diffvacuously, with zero files in scope); neighbouring suites
ChatSidebar.boardFolderRename,ChatSidebar.boardFolderCreateInTab,ChatSidebar.channelFolder,ChatPage.sidebarSourceReveal20/20, andsrc/components/commandPalette+SessionActionsMenuclean apart fromsettingsRegistry.test.ts, which fails identically on an unmodified checkout ofthis same commit (a CRLF-vs-LF artifact of a Windows working copy, not this
change).
Why no screenshot: This changes only the React-Query key the Folders view
caches its derived rows under; it adds and alters no layout, styling, component
or copy, and the difference it makes — a list re-derived after a folder write
rather than re-served — is a still frame of N rows versus N-1 that is
indistinguishable from a correct list of a different set of folders, which is
why the evidence here is the deterministic test plus its negative control.
Related Issues
No issue. Named by the Design review on #12013, which merged without it:
The key this PR ships is the one that review specified.
Pattern harvest
Rule candidate: review-prompt
Pattern: a React-Query entry holding rows DERIVED from a shared corpus is keyed
outside that corpus's namespace, so the corpus's
invalidateQueries— whichmatches by prefix — reaches the corpus and not the derived entry. The derived
entry then serves pre-write rows for its whole
staleTime, and a surface thatunmounts while closed hides this behind what looks like a fresh open.
The tell is a
queryFnthat only reads another React-Query key. In thiscomponent the artifacts view is the correct spelling of the same shape
(
['artifacts', 'command-bar', 'view', q]) and was the reference for the fix,so the rule has a positive control in-tree.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code