Skip to content

The agent that grows with you

fix(desktop): preserve alias task cache invalidation

funky-xamarinc4700d60de98
diff --git a/apps/desktop/src/plugins/kanban/api.default-notify.test.ts b/apps/desktop/src/plugins/kanban/api.default-notify.test.ts
index 041feeb9913..ba5522b4368 100644
--- a/apps/desktop/src/plugins/kanban/api.default-notify.test.ts
+++ b/apps/desktop/src/plugins/kanban/api.default-notify.test.ts
@@ -35,6 +35,36 @@ afterEach(() => {
})
describe('default board event notifications', () => {
+ it('refreshes an open alias-keyed task drawer on a live event', async () => {
+ const { QueryObserver } = await import('@tanstack/react-query')
+ const { taskKey } = await import('./api')
+ let frame!: (data: unknown) => void
+ dispose = bindApi(
+ (async (path: string) => (path === '/boards' ? { current: 'drawer-board' } : { latest_event_id: 100 })) as never,
+ { get: (_key, fallback) => fallback, set: vi.fn(), remove: vi.fn() },
+ (_path, callback) => {
+ frame = callback
+ return vi.fn()
+ }
+ )
+ let revision = 1
+ const observer = new QueryObserver(queryClient, {
+ queryKey: taskKey('local', '', 'task'),
+ queryFn: async () => ({ revision }),
+ staleTime: Infinity
+ })
+ const unsubscribe = observer.subscribe(() => undefined)
+ try {
+ await vi.waitFor(() => expect(observer.getCurrentResult().data).toEqual({ revision: 1 }))
+ await vi.waitFor(() => expect(frame).toBeTypeOf('function'))
+ revision = 2
+ frame({ cursor: 101, events: [{ id: 101, kind: 'updated', task_id: 'task' }] })
+ await vi.waitFor(() => expect(observer.getCurrentResult().data).toEqual({ revision: 2 }))
+ } finally {
+ unsubscribe()
+ }
+ })
+
it.each(['empty', 'rejected'])('preserves the live alias socket when board resolution is %s', async mode => {
const rest = vi.fn(async (path: string) => {
if (path === '/boards') {
diff --git a/apps/desktop/src/plugins/kanban/api.ts b/apps/desktop/src/plugins/kanban/api.ts
index 845d0c62fec..345b7570193 100644
--- a/apps/desktop/src/plugins/kanban/api.ts
+++ b/apps/desktop/src/plugins/kanban/api.ts
@@ -160,7 +160,7 @@ export const routedToScope = (query: { queryKey: readonly unknown[] }): boolean
/** One live `task_events` frame → precise cache invalidation: the board, plus
* each touched task's detail. The polls (8s board / 4s drawer) stay as the
* fallback — the socket just makes the board feel instant. */
-function onEventsFrame(scope: string, slug: string, data: unknown): void {
+function onEventsFrame(scope: string, slug: string, data: unknown, selectedSlug = slug): void {
const frame = data as { cursor?: unknown; events?: CompletionEvent[] }
if (typeof frame?.cursor === 'number') {
@@ -179,6 +179,9 @@ function onEventsFrame(scope: string, slug: string, data: unknown): void {
for (const taskId of new Set(events.map(event => event.task_id).filter(Boolean))) {
void queryClient.invalidateQueries({ queryKey: taskKey(scope, slug, taskId!) })
+ if (selectedSlug !== slug) {
+ void queryClient.invalidateQueries({ queryKey: taskKey(scope, selectedSlug, taskId!) })
+ }
}
// Completion notification (after invalidation so notify failure
@@ -229,9 +232,10 @@ export function bindApi(
const dial = (scope: string, slug: string, since: number | undefined) => {
const generation = socketGeneration
+ const selectedSlug = $boardSlug.get()
return socket(eventsUrl(slug, since), data => {
- if (generation === socketGeneration) onEventsFrame(scope, slug, data)
+ if (generation === socketGeneration) onEventsFrame(scope, slug, data, selectedSlug)
})
}