Skip to content

fix(command-bar): let a folder deletion reach the launcher's folder list - #12290

Closed
leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/command-bar-folders-view-invalidation
Closed

leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/command-bar-folders-view-invalidation

Conversation

@leonlaiyc

Copy link
Copy Markdown
Contributor

Problem / Motivation

Delete a chat folder in the sidebar, then open the Command Bar (⌘K) and step
into 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 /chat and asks the sidebar to reveal a folder id that no longer
exists — 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 a
plain 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 documented
in the file, because GET /api/chat/folders walks the on-disk session list to
count 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.tsx on folder create (:5498), delete
(:5503), update (:5543) and reorder (:5614);
settings/ChannelFolderBackfill.tsx:89; and useWebSocket.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.

QuickSearchSurface mounts the overlay only while it is open — a deliberate
choice 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 was
never marked stale, so the reopened view re-served the pre-delete rows.

The fix is the key:

-    queryKey: ['command-bar', 'folders', folderQuery],
+    queryKey: ['chat-folders', 'command-bar', 'view', folderQuery],

That is the shape the artifacts view in this same component already uses —
['artifacts', 'command-bar', 'view', artifactsQuery], nested under the corpus
it 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):
useQuery at ChatSidebar.tsx:4408, SessionActionsMenu.tsx:132,
JobForm.tsx:378, ChatPage.tsx:3089 and this component's :517;
fetchQuery at sessionsProvider.ts:338, recentsProvider.ts:272 and this
component's :583; getQueryData/setQueryData at ChatSidebar.tsx:5510,
:5511, :5534, :5582, :5593, :5607, :5625, :5964 and
useWebSocket.ts:1462/:1464. The only prefix consumers are the eight
invalidateQueries above and one cancelQueries (ChatSidebar.tsx:5509, the
rename's optimistic onMutate) — reaching the invalidations is the point, and
the 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 a
prefix — the other two keys in that namespace (:884, :906) are only ever
addressed exactly — so moving this key out of it orphans nothing.

Deliberately not changed

sessionsProvider and recentsProvider also read ['chat-folders'], but for a
different 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 folder
list, so nesting ['command-bar', 'sessions', …] under one of its three inputs
would 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.tsx

  • drops 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 the
    gateway 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.chatFolders is not called. Without it, simply dropping the view's
    staleTime would pass the regression while paying for the expensive folder
    read on every open — the cost the shared key exists to avoid.

Harness change: mount() takes an optional client so one cache spans two
mounts, and the walk from the root into the view is factored out as
enterFoldersView() so the second mount can reuse it. No existing test's
behaviour changed.

Red-before, with the production hunk reverted and the tests kept, on
234121ed0d19497570b3ec38014782109a321add:

 ❯ CommandBarOverlay.folders.test.tsx (22 tests | 1 failed)
   × drops a folder the sidebar deleted, instead of re-listing it from the view cache
     AssertionError: expected true to be false
     374| expect(hasRow('Trading Desk')).toBe(false)
 Tests  1 failed | 21 passed (22)

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 the
negative control that a live click-through cannot distinguish from a lucky
refetch.

Other gates run locally on the branch head, against
234121ed0d19497570b3ec38014782109a321add:
tsc --noEmit clean; eslint clean on both changed files; Brand Name Gate and
Focus Cue Gate pass diff-scoped against origin/main (the Comment History Gate
is Python-scoped — src/kiro_crew, test, .py — so it passes this diff
vacuously, with zero files in scope); neighbouring suites
ChatSidebar.boardFolderRename, ChatSidebar.boardFolderCreateInTab,
ChatSidebar.channelFolder, ChatPage.sidebarSourceReveal 20/20, and
src/components/commandPalette + SessionActionsMenu clean apart from
settingsRegistry.test.ts, which fails identically on an unmodified checkout of
this 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:

FINDING -- website/src/apps/command-bar/CommandBarOverlay.tsx:984 --
"['command-bar', 'folders', folderQuery]" survives folder invalidations, so
a recently renamed/deleted folder remains actionable for 15s -> Fix: nest this
key under ['chat-folders', 'command-bar', 'view', folderQuery].

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 — which
matches 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 that
unmounts while closed hides this behind what looks like a fresh open.

The tell is a queryFn that only reads another React-Query key. In this
component 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

🤖 Generated with Claude Code

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>
@leonlaiyc
leonlaiyc requested review from a team and krishdhasmana September 20, 2026 12:57
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ⚠️ review incomplete

Reviewed 95e1200baac3852b41e34c0d623e40c5718756a9 via the fork AI-review pipeline; updated in place on each push.

No completed Opus verdict for this commit; see the Fork Opus 4.8 Review job logs.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ⚠️ could not complete

The design review did not produce a verdict for 95e1200baac3852b41e34c0d623e40c5718756a9 (the review step failed). See the Fork Design Review job logs. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ⚠️ could not complete

The first-principles review did not produce a verdict for 95e1200baac3852b41e34c0d623e40c5718756a9 (the review step failed). See the Fork First Principles Review job logs. Advisory — does not block merge.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 95e1200baac3852b41e34c0d623e40c5718756a9 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 95e1200

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 26, 2026
@dwu96 dwu96 added the needs-pr-triage PR scanner: awaiting automated triage label Sep 30, 2026
@chenmingwei23 chenmingwei23 added drive-to-green PR claimed by drive-to-green pipeline and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 30, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor

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.

@iamwhatever

Copy link
Copy Markdown
Contributor

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 ['chat-folders'] namespace, so the invalidateQueries({ queryKey: ['chat-folders'] }) that every folder create/delete/update runs never reached them, and a folder deleted while the bar was closed came back listed and selectable on the next open.

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.

@cruisercohen cruisercohen removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 30, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 30, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

@leonlaiyc quick follow-up: your work here landed on main via #15339 (merged). Your commit was kept with your authorship, so your name is on the change in the git history, and you're listed in the README Contributors section. Thanks again for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants