Skip to content

fix(dashboard): stop invalidating a chat-slots cache no query registers - #11939

Merged
iamwhatever merged 1 commit into
mainfrom
fix/dead-chat-slots-invalidations-10204
Sep 19, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/dead-chat-slots-invalidations-10204

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What is the problem?

Six call sites invalidated the React Query key ['chat-slots']. No query is
registered on that key, so every one of them refreshed nothing.

invalidateQueries marks the queries a key matches as stale and refetches the
active ones. The only keys matching a ['chat-slots'] prefix are one-shot
fetchQuery reads with gcTime: 0 and no observers, which are discarded as
they settle and are never active. The list a slot row actually renders from is
the Redux dashboard slice, fed by the websocket sseSlots frame and the
fetchSlots() thunk. So each call traversed an empty match set and returned: no
request, no error, no refresh.

#10204 listed five sites. Three have since been removed as their surrounding
defects were fixed: SlotTagPopover in #8185, and ChatSidebar's bulk-model and
board-drop handlers in #10172. Two remained on main at c9503c87ab:

Site Handler Verdict
website/src/components/TagManagerList.tsx:62 deleteTagMutation.onSuccess remove
website/src/hooks/useSessionActions.ts:196 finishPinMutation reconcile fallback remove
website/src/components/SlotTagPopover.tsx:41 tag-assign onSuccess already removed (#8185, 8b58f72a86)
website/src/pages/ChatSidebar.tsx:3235 bulk model switch onSuccess already removed (#10172, 61bee8839d)
website/src/pages/ChatSidebar.tsx:3800 board card drop onSuccess already removed (#10172, 61bee8839d)

Three other ['chat-slots'] references are fetchQuery reads, not
invalidations, and are left as they are -- useSessionActions.ts:103,
ChatSidebar.tsx:3526, chat/SessionTitleControl.tsx:217. They resolve their
own 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 every
    slot, then calls state.push_slots_update() at line 911 -- on its one success
    path, after the write lock is released. Every earlier exit returns 404/500, so
    onSuccess does not run for them. The authoritative frame that reaches
    applySlots therefore already carries the stripped tags. The two live
    invalidations (['chat-tags'], ['tag-columns']) stay; the comment above them
    no longer claims a slot refresh it never performed.

  • useSessionActions' pin-reconcile fallback. This branch is entered only
    when the handler's own fetchQuery snapshot read threw, so it is already the
    failed re-read; an invalidation could not have been its retry. The
    authoritative pinned state arrives anyway: every accepted
    PATCH /api/chat/slots/{slot}/pin ends in state.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 the
    reason fix: refetch slots when a sidebar rename is refused (#10151) #10172 recorded: applySlots is a positional whole-list replace, so it
    can 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 QueryClient the component was handed -- a
dead 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.chatSlots is
never called, so the dead invalidate cannot be traded for a whole-list GET. The
pin test drives the fallback by resolving setSlotPin and rejecting
chatSlots, and asserts the optimistic pin survives.

A source ratchet then scans the tree for invalidateQueries on a
chat-slots-prefixed key, in the shape MemoI18nSubscriptionRatchet.test.ts
established. 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 fetchQuery forms), plus an assertion that
the fetchQuery reads still exist -- so a rename cannot leave the scan guarding
a 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:

Run Result
baseline, unmutated 13 passed
restore the dead invalidate in TagManagerList 2 failed, 11 passed
restore the dead invalidate in useSessionActions 2 failed, 11 passed
drop the live ['tag-columns'] invalidate 1 failed, 12 passed
restored 13 passed

Two 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.json clean; npx eslint src/ --max-warnings 0 clean; i18n:check clean; lint:phantom-classes and its
self-test clean; jscpd found 0 clones. The eight test files importing either
changed module pass together (95 tests).

Why no screenshot: nothing rendered changes. Both removed lines were
invalidateQueries calls on a key no query is registered on, so neither ever
produced a request, a refetch, or a repaint -- that is the defect. The tag-delete
test asserts the handler makes no compensating api.chatSlots call either, so
the 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: invalidateQueries on a React Query key that no useQuery registers

Generalizable, 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 is
wider than one key: any invalidation whose key no useQuery registers is dead
the same way. The ratchet covers the whole chat-slots prefix today and gives a
future 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
ChatSidebar handlers it edited -- bulk model switch and board card drop -- still
do 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
fetchQuery reads stay legal. If a surface ever genuinely needs a whole-list
re-read, dispatch(fetchSlots()) is the mechanism, and the ratchet does not
stand in its way.

Closes #10204

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
@chenmingwei23
chenmingwei23 requested review from a team and iamwhatever September 19, 2026 04:37
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ✅ PASS

UX-level review of 3b47f9cbb163f03c7d94b398c1351f08f98c1393 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Nothing to check.

[UX-REVIEWED] 3b47f9c

@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 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 3b47f9cbb163f03c7d94b398c1351f08f98c1393 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 3b47f9c

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 3b47f9cbb163f03c7d94b398c1351f08f98c1393 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3b47f9c

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 3b47f9cbb163f03c7d94b398c1351f08f98c1393: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 3b47f9cbb163f03c7d94b398c1351f08f98c1393 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 3b47f9c

Verdict parsed from the review's SHA-scoped output markers for commit 3b47f9cbb163f03c7d94b398c1351f08f98c1393.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 3b47f9cbb163f03c7d94b398c1351f08f98c1393: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 3b47f9cbb163f03c7d94b398c1351f08f98c1393 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Nothing to check.

Every load-bearing claim in the description verified against the repo: no useQuery registers a ['chat-slots'] key (only the three fetchQuery reads the description names, counted at useSessionActions.ts:103, ChatSidebar.tsx:3526, SessionTitleControl.tsx:217); api_chat_tag_delete pushes the authoritative slots frame on its one success path (chat_tags.py:911); the accepted pin PATCH pushes one (chat_folders.py:1882); reconnect dispatches fetchSlots (chatSlice.ts:6101). The ratchet follows the existing MemoI18nSubscriptionRatchet.test.ts shape, exports included, and its harm is counted: six recurrences of the same dead call, per #10204. The deletions are mechanism-level; the ratchet closes the invariant gap that let the class recur.

What this change ships

Inventory (6 items) — 6 justified

Intent: FIX — remove two invalidateQueries(['chat-slots']) calls that refresh nothing (#10204) and prevent the class recurring.

  1. Tag delete no longer ends with a dead ['chat-slots'] invalidation — justified
  2. Pin-reconcile fallback no longer ends with the same dead invalidation — justified
  3. Both handlers' comments now say why no slot refresh is issued — justified
  4. Two behavioural tests pin each handler's exact invalidated key set — justified
  5. Tree-wide ratchet test bans invalidateQueries on a chat-slots-prefixed key — justified
  6. Predicate fixture suite plus a guard that the permitted fetchQuery reads still exist — justified

[FIRST-PRINCIPLES-REVIEWED] 3b47f9c

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 19, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 19, 2026 05:02

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@iamwhatever
iamwhatever merged commit c4bb485 into main Sep 19, 2026
91 of 93 checks passed
@iamwhatever
iamwhatever deleted the fix/dead-chat-slots-invalidations-10204 branch September 19, 2026 05:02
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 19, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Five plain ['chat-slots'] invalidateQueries call sites are no-ops

2 participants