Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(issues): keep comment trigger preview fresh against live queue state (#4007)

Naiyuan Qinga0b63462d054
diff --git a/packages/core/issues/queries.ts b/packages/core/issues/queries.ts
index e2d902bba3..1e759935d1 100644
--- a/packages/core/issues/queries.ts
+++ b/packages/core/issues/queries.ts
@@ -73,9 +73,13 @@ export const issueKeys = {
/** Full-issue timeline (single TanStack Query, no cursor). */
timeline: (issueId: string) =>
[...issueKeys.timelineAll(), issueId] as const,
+ /** Prefix across all issues — WS task lifecycle events invalidate here so
+ * an open composer's trigger preview refreshes when an agent's queue
+ * state changes (the dedup guard makes the answer queue-dependent). */
+ commentTriggerPreviewAll: () => ["issues", "comment-trigger-preview"] as const,
/** PREFIX for invalidation — the composer hook appends parent + content signature. */
commentTriggerPreview: (issueId: string) =>
- ["issues", "comment-trigger-preview", issueId] as const,
+ [...issueKeys.commentTriggerPreviewAll(), issueId] as const,
reactionsAll: () => ["issues", "reactions"] as const,
reactions: (issueId: string) =>
[...issueKeys.reactionsAll(), issueId] as const,
diff --git a/packages/core/realtime/use-realtime-sync.ts b/packages/core/realtime/use-realtime-sync.ts
index e63a42d9d2..c931939df6 100644
--- a/packages/core/realtime/use-realtime-sync.ts
+++ b/packages/core/realtime/use-realtime-sync.ts
@@ -504,6 +504,12 @@ export function useRealtimeSync(
// Squad members-status reads the same task lifecycle to flip
// working ↔ idle for each agent member.
invalidateSquadMemberStatusQueries(qc, wsId);
+ // Comment trigger previews answer "who would a send wake right
+ // now" — the pending-task dedup guard makes that answer
+ // queue-dependent, so any task lifecycle change must refresh an
+ // open composer's chips (e.g. an agent finishing its run becomes
+ // triggerable again mid-typing).
+ qc.invalidateQueries({ queryKey: issueKeys.commentTriggerPreviewAll() });
},
};
diff --git a/packages/views/issues/hooks/use-comment-trigger-preview.test.ts b/packages/views/issues/hooks/use-comment-trigger-preview.test.ts
index 2bc9b53a89..238e2556b6 100644
--- a/packages/views/issues/hooks/use-comment-trigger-preview.test.ts
+++ b/packages/views/issues/hooks/use-comment-trigger-preview.test.ts
@@ -69,10 +69,14 @@ describe("useCommentTriggerPreview", () => {
);
});
- it("uses the TanStack Query cache when the debounced signature repeats", async () => {
+ it("revalidates when the debounced signature repeats — the answer is queue-state dependent", async () => {
const agentA = "00000000-0000-0000-0000-000000000001";
const content = `[@A](mention://agent/${agentA})`;
- const { rerender } = renderHook(
+ const agents = [
+ { id: agentA, name: "A", source: "mention_agent", reason: "" },
+ ];
+ previewCommentTriggers.mockResolvedValue({ agents });
+ const { result, rerender } = renderHook(
({ content }) => useCommentTriggerPreview({ issueId: "issue-1", content }),
{
wrapper: createWrapper(),
@@ -85,9 +89,13 @@ describe("useCommentTriggerPreview", () => {
rerender({ content: "" });
rerender({ content });
+ // Cached agents render immediately for the repeated signature (no
+ // flicker)…
await advancePreviewDebounce();
-
- expect(previewCommentTriggers).toHaveBeenCalledTimes(1);
+ expect(result.current.agents).toEqual(agents);
+ // …but a background revalidation still fires: an agent finishing its
+ // queued task changes the answer for the very same mention set.
+ expect(previewCommentTriggers).toHaveBeenCalledTimes(2);
});
it("fetches again when routing mention tokens change", async () => {
diff --git a/packages/views/issues/hooks/use-comment-trigger-preview.ts b/packages/views/issues/hooks/use-comment-trigger-preview.ts
index 60aaf2a0da..048cb52237 100644
--- a/packages/views/issues/hooks/use-comment-trigger-preview.ts
+++ b/packages/views/issues/hooks/use-comment-trigger-preview.ts
@@ -1,7 +1,7 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
-import { useQuery } from "@tanstack/react-query";
+import { keepPreviousData, useQuery } from "@tanstack/react-query";
import { api } from "@multica/core/api";
import { issueKeys } from "@multica/core/issues/queries";
import type { CommentTriggerPreviewAgent } from "@multica/core/types";
@@ -77,7 +77,15 @@ export function useCommentTriggerPreview({
queryFn: () => api.previewCommentTriggers(issueId, contentRef.current, parentId),
enabled: signature !== "empty" && debouncedSignature !== "empty",
retry: false,
- staleTime: Infinity,
+ // The answer depends on live queue state (pending-task dedup), not just
+ // the mention set, so a cached result must revalidate when its signature
+ // reappears — Infinity here once pinned a stale "nobody triggers"
+ // snapshot taken while the agent was still queued.
+ staleTime: 0,
+ // Keep the previous agent list while a new signature is fetching:
+ // without it the in-flight gap renders as "no agents", flickering the
+ // chips and wiping the composer's suppressed-id set.
+ placeholderData: keepPreviousData,
});
// Loading and errors intentionally surface as "no agents": the preview is