Commit 632eecc
authored
feat(site/src): reintroduce chat search cache invalidation (#27892)
Stacked on `feat/chat-cache-semantic-ops`.
## Bug
Chat search results (`chatSearch` queries) were never invalidated, so
the search dialog served stale results after archives, renames,
deletions, new chats, message edits, and watch-driven status changes.
## Fix
Reintroduces `invalidateChatSearches`, a prefix invalidation over the
module-private `chatSearchFamilyKey`, and wires it into:
- `chats.ts`: `archiveChat.onSettled`, `unarchiveChat.onSettled`,
`updateChatTitle.onSettled`, `editChatMessage.onSettled`,
`createChat.onSuccess`
- `useChatStore.ts`: `upsertCacheMessages` (unconditional; assistant
message bodies are indexed too) and `replaceCacheMessages`
- `AgentsPageLayout.tsx`: the `deleted` and root `created` watch
branches, the merge watch branch (gated by a new exported
`shouldInvalidateChatSearches` helper), the `has_unread` clearing
effect, the `onOpen` reconnect convergence, and
`archiveAndDeleteMutation.onSuccess`
The merge-branch gate only invalidates for search-affecting event kinds
(`title_change`, `status_change`, `diff_status_change`,
`action_required`). `summary_change`, `chat_summary_change`, and
`context_dirty` are excluded: stale `last_turn_summary` subtitles are
accepted until reconciliation lands.
## Backend constraint
Message bodies only enter full-text search via the dbpurge backfill
(`search_tsv` starts NULL and is populated every 10 minutes). Frontend
invalidation fixes removals, ordering, and rendered fields immediately,
but a chat that newly matches on message body will not appear until the
next backfill. This is a server-side eventual-consistency limit we
accept.
## Scope decisions (confirmed)
- No invalidation in `createChatMessage.onSuccess`: the send path
already routes through `useChatStore.upsertCacheMessages`; adding both
would double-invalidate every send.
- No invalidation for `pinChat`/`unpinChat`/`reorderPinnedChat`
(ordering-only, self-heals).
- ACL mutations out of scope.
- No coalescing/debouncing; that belongs to a later reconciler PR.
## Tests
- Prefix invalidation: multiple distinct `q` params invalidated,
bystanders (list, by-workspace, entity, messages, cost tree) untouched.
- Mutation wiring: settlement of `archiveChat`, `unarchiveChat`,
`updateChatTitle`, `editChatMessage`, and `createChat` invalidates a
seeded search key; `createChatMessage` asserted NOT to.
- `shouldInvalidateChatSearches` unit-tested over all
`ChatWatchEventKind` values.
PR generated by Coder Agents.1 parent 4b7494b commit 632eecc
4 files changed
Lines changed: 152 additions & 0 deletions
File tree
- site/src
- api/queries
- pages/AgentsPage
- components/ChatConversation
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
945 | 948 | | |
946 | 949 | | |
947 | 950 | | |
| 951 | + | |
948 | 952 | | |
949 | 953 | | |
950 | 954 | | |
| |||
956 | 960 | | |
957 | 961 | | |
958 | 962 | | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
959 | 971 | | |
960 | 972 | | |
961 | 973 | | |
| |||
1550 | 1562 | | |
1551 | 1563 | | |
1552 | 1564 | | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
1553 | 1610 | | |
1554 | 1611 | | |
1555 | 1612 | | |
| |||
3057 | 3114 | | |
3058 | 3115 | | |
3059 | 3116 | | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
| 3138 | + | |
| 3139 | + | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
3060 | 3174 | | |
3061 | 3175 | | |
3062 | 3176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
651 | 671 | | |
652 | 672 | | |
653 | 673 | | |
| |||
993 | 1013 | | |
994 | 1014 | | |
995 | 1015 | | |
| 1016 | + | |
996 | 1017 | | |
997 | 1018 | | |
998 | 1019 | | |
| |||
1042 | 1063 | | |
1043 | 1064 | | |
1044 | 1065 | | |
| 1066 | + | |
1045 | 1067 | | |
1046 | 1068 | | |
1047 | 1069 | | |
| |||
1329 | 1351 | | |
1330 | 1352 | | |
1331 | 1353 | | |
| 1354 | + | |
1332 | 1355 | | |
1333 | 1356 | | |
1334 | 1357 | | |
| |||
1409 | 1432 | | |
1410 | 1433 | | |
1411 | 1434 | | |
| 1435 | + | |
1412 | 1436 | | |
1413 | 1437 | | |
1414 | 1438 | | |
| |||
1501 | 1525 | | |
1502 | 1526 | | |
1503 | 1527 | | |
| 1528 | + | |
1504 | 1529 | | |
1505 | 1530 | | |
1506 | 1531 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
308 | 310 | | |
309 | 311 | | |
310 | 312 | | |
| 313 | + | |
311 | 314 | | |
312 | 315 | | |
313 | 316 | | |
| |||
576 | 579 | | |
577 | 580 | | |
578 | 581 | | |
| 582 | + | |
579 | 583 | | |
580 | 584 | | |
581 | 585 | | |
| |||
615 | 619 | | |
616 | 620 | | |
617 | 621 | | |
| 622 | + | |
618 | 623 | | |
619 | 624 | | |
620 | 625 | | |
| |||
650 | 655 | | |
651 | 656 | | |
652 | 657 | | |
| 658 | + | |
653 | 659 | | |
654 | 660 | | |
655 | 661 | | |
| |||
659 | 665 | | |
660 | 666 | | |
661 | 667 | | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
662 | 671 | | |
663 | 672 | | |
664 | 673 | | |
| |||
681 | 690 | | |
682 | 691 | | |
683 | 692 | | |
| 693 | + | |
684 | 694 | | |
685 | 695 | | |
686 | 696 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
| 238 | + | |
237 | 239 | | |
238 | 240 | | |
239 | 241 | | |
| |||
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| 260 | + | |
258 | 261 | | |
259 | 262 | | |
260 | 263 | | |
| |||
0 commit comments