Repository navigation
fix(dashboard): stop invalidating a chat-slots cache no query registers - #11939
Conversation
Two mutation handlers ended with
`queryClient.invalidateQueries({ queryKey: ['chat-slots'] })`, which
refreshes nothing: no query is registered on a chat-slots-prefixed key,
so the call traverses an empty match set and returns with no request and
no error.
Both are deletions rather than replacements, because the refresh each
reached for already arrives from the server:
- TagManagerList's tag delete -- api_chat_tag_delete strips the id
from every slot and then calls push_slots_update() on its one
success path.
- useSessionActions' pin-reconcile fallback -- every accepted
PATCH /api/chat/slots/{slot}/pin ends in push_slots_update(), and
this branch is reached only when the client's own re-read failed.
A new test asserts the exact keys each handler invalidates, and a source
ratchet keeps a seventh site from arriving the way the first six did.
Closes #10204
UX Review (Fable 5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. [UX-REVIEWED] 3b47f9c |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] 3b47f9c |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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: |
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: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. Every load-bearing claim in the description verified against the repo: no What this change shipsInventory (6 items) — 6 justifiedIntent: FIX — remove two
[FIRST-PRINCIPLES-REVIEWED] 3b47f9c |
iamwhatever
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green. Category: removes two dead invalidateQueries(['chat-slots']) calls that no registered query listens to (#10204), keeps the live ['chat-tags']/['tag-columns'] refreshes, and locks the behaviour in with a regression test. The only annotation on the Semgrep run is GitHub's own level=notice runner-image migration message at .github:1, not a Semgrep finding.
…rs (kirodotdev#11939) Two mutation handlers ended with `queryClient.invalidateQueries({ queryKey: ['chat-slots'] })`, which refreshes nothing: no query is registered on a chat-slots-prefixed key, so the call traverses an empty match set and returns with no request and no error. Both are deletions rather than replacements, because the refresh each reached for already arrives from the server: - TagManagerList's tag delete -- api_chat_tag_delete strips the id from every slot and then calls push_slots_update() on its one success path. - useSessionActions' pin-reconcile fallback -- every accepted PATCH /api/chat/slots/{slot}/pin ends in push_slots_update(), and this branch is reached only when the client's own re-read failed. A new test asserts the exact keys each handler invalidates, and a source ratchet keeps a seventh site from arriving the way the first six did. Closes kirodotdev#10204
What is the problem?
Six call sites invalidated the React Query key
['chat-slots']. No query isregistered on that key, so every one of them refreshed nothing.
invalidateQueriesmarks the queries a key matches as stale and refetches theactive ones. The only keys matching a
['chat-slots']prefix are one-shotfetchQueryreads withgcTime: 0and no observers, which are discarded asthey settle and are never active. The list a slot row actually renders from is
the Redux
dashboardslice, fed by the websocketsseSlotsframe and thefetchSlots()thunk. So each call traversed an empty match set and returned: norequest, no error, no refresh.
#10204 listed five sites. Three have since been removed as their surrounding
defects were fixed:
SlotTagPopoverin #8185, andChatSidebar's bulk-model andboard-drop handlers in #10172. Two remained on
mainatc9503c87ab:website/src/components/TagManagerList.tsx:62deleteTagMutation.onSuccesswebsite/src/hooks/useSessionActions.ts:196finishPinMutationreconcile fallbackwebsite/src/components/SlotTagPopover.tsx:41onSuccess8b58f72a86)website/src/pages/ChatSidebar.tsx:3235onSuccess61bee8839d)website/src/pages/ChatSidebar.tsx:3800onSuccess61bee8839d)Three other
['chat-slots']references arefetchQueryreads, notinvalidations, and are left as they are --
useSessionActions.ts:103,ChatSidebar.tsx:3526,chat/SessionTitleControl.tsx:217. They resolve theirown promise, so the unregistered key costs them nothing.
Why this issue matters to the user
Nothing errors, which is what makes the class durable. A reader of either
handler sees a refresh that is not there, so the next person to touch the
surface reasons from a cache line that does not exist, and a real refresh need
arriving at one of these handlers would look already handled. #10151 was the
version of this with a user-visible consequence: a refused rename never
reverted, because the recovery was one of these dead calls. These two have no
such consequence today -- which is exactly why they were left behind, and why
they need a recorded verdict rather than another pass.
How our fix solves it
Both are deletions rather than replacements, because the refresh each one
reached for already arrives from the server:
TagManagerList's tag delete.api_chat_tag_delete(
src/kiro_crew/dashboard/chat_tags.py:826) strips the deleted id from everyslot, then calls
state.push_slots_update()at line 911 -- on its one successpath, after the write lock is released. Every earlier exit returns 404/500, so
onSuccessdoes not run for them. The authoritative frame that reachesapplySlotstherefore already carries the stripped tags. The two liveinvalidations (
['chat-tags'],['tag-columns']) stay; the comment above themno longer claims a slot refresh it never performed.
useSessionActions' pin-reconcile fallback. This branch is entered onlywhen the handler's own
fetchQuerysnapshot read threw, so it is already thefailed re-read; an invalidation could not have been its retry. The
authoritative pinned state arrives anyway: every accepted
PATCH /api/chat/slots/{slot}/pinends instate.push_slots_update()(
chat_folders.py:1882), and a websocket reconnect refetches the whole list.A whole-list
dispatch(fetchSlots())was considered and rejected for thereason fix: refetch slots when a sidebar rename is refused (#10151) #10172 recorded:
applySlotsis a positional whole-list replace, so itcan overwrite a fresher single-slot frame for any other slot that landed
during the read.
What tests we did
New file
website/src/test/chatSlotsDeadKeyInvalidation.test.tsx, 13 tests.Two behavioural tests drive the real surfaces and assert the keys each handler
invalidates, recorded on the actual
QueryClientthe component was handed -- adead key is invisible in rendered output, so the recorded key list is the only
place the difference shows. The tag-delete test also asserts
api.chatSlotsisnever called, so the dead invalidate cannot be traded for a whole-list GET. The
pin test drives the fallback by resolving
setSlotPinand rejectingchatSlots, and asserts the optimistic pin survives.A source ratchet then scans the tree for
invalidateQuerieson achat-slots-prefixed key, in the shapeMemoI18nSubscriptionRatchet.test.tsestablished. The two behavioural tests cannot see a seventh site in a file
nobody wrote a test for, which is how the first six arrived. Its predicate has
its own fixture suite (11 cases: wrapped calls, longer prefixes, both quote
styles, comments, and the permitted
fetchQueryforms), plus an assertion thatthe
fetchQueryreads still exist -- so a rename cannot leave the scan guardinga key nothing uses and reporting green.
Mutation check -- restoring each removed line, and dropping a live one, with
files restored from copies taken before the run:
TagManagerListuseSessionActions['tag-columns']invalidateTwo failures for a restored dead call (the behavioural test plus the ratchet)
and one for the over-deletion (the exact-key assertion alone) -- the differing
counts are per-behaviour assertions rather than one blanket check.
Also run in the worktree: the repo's own frontend scope selection
(
python3 scripts/run_scoped_tests.py --surface frontend) picked 5 files,73 passed;
npx tsc -p tsconfig.app.jsonclean;npx eslint src/ --max-warnings 0clean;i18n:checkclean;lint:phantom-classesand itsself-test clean;
jscpdfound 0 clones. The eight test files importing eitherchanged module pass together (95 tests).
Why no screenshot: nothing rendered changes. Both removed lines were
invalidateQueriescalls on a key no query is registered on, so neither everproduced a request, a refetch, or a repaint -- that is the defect. The tag-delete
test asserts the handler makes no compensating
api.chatSlotscall either, sothe before and after frames are identical by construction. The third file is a
test.
Pattern harvest
Rule candidate: repo ratchet test (added in this PR as
website/src/test/chatSlotsDeadKeyInvalidation.test.tsx)Pattern:
invalidateQuerieson a React Query key that nouseQueryregistersGeneralizable, and already generalized. The defect is not one wrong line, it is
a shape that recurred six times across five files and four PRs, because it fails
silently: an invalidation on an unregistered key issues no request and raises
nothing, so neither the author, the reviewer, nor any behavioural test sees a
difference. Only the key name is wrong, and the key name is a string.
A semgrep rule could pin the single literal
['chat-slots'], but the class iswider than one key: any invalidation whose key no
useQueryregisters is deadthe same way. The ratchet covers the whole
chat-slotsprefix today and gives afuture key the same treatment for one added pattern, so it is the cheaper form
of the same rule. Its predicate carries a fixture suite for the reason such a
scan usually rots -- a regex tightened against the current tree stops matching
the defect and reports green.
Any other suggestions on the work
The deferral #10172 recorded is still open and is not touched here. Both
ChatSidebarhandlers it edited -- bulk model switch and board card drop -- stilldo not eagerly reflect their own writes; they wait for the next authoritative
frame, and an eager client-side patch needs the per-field reconciliation
contract tracked in #11149. That is a separate change from removing a call that
did nothing.
The ratchet bans one verb on one key rather than the key itself, so the
fetchQueryreads stay legal. If a surface ever genuinely needs a whole-listre-read,
dispatch(fetchSlots())is the mechanism, and the ratchet does notstand in its way.
Closes #10204