Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issues): reconcile board column counts on off-screen status change (#4557)
Ol1ver0413adddfbdf89b1
diff --git a/packages/core/issues/ws-updaters.test.ts b/packages/core/issues/ws-updaters.test.tsindex 043dad29be..34aa4c7dd5 100644--- a/packages/core/issues/ws-updaters.test.ts+++ b/packages/core/issues/ws-updaters.test.ts@@ -324,6 +324,91 @@ describe("onIssueUpdated — position move is surgical, not a list refetch", ()});});+// A board column header shows `byStatus[status].total`. On a status change the+// surgical patch shifts both bucket totals — but only if it can find the card in+// a loaded page. A paginated column loads just its first page, so an off-screen+// issue (very common when an agent flips the status of something the viewer+// never scrolled to) is absent: patchIssueInBuckets no-ops and the count would+// silently drift, with no refetch to recover it. The status-changed no-op has to+// fall back to a single-list refetch.+describe("onIssueUpdated — off-screen status change reconciles column counts", () => {+ let qc: QueryClient;++ beforeEach(() => {+ qc = new QueryClient();+ });++ it("refetches the workspace list when a status-changed issue is not in the loaded page", () => {+ // First page only: the totals say these columns have items, but the issues+ // arrays are the loaded window — the moved issue lives beyond it.+ qc.setQueryData<ListIssuesCache>(issueKeys.list(WS_ID), {+ byStatus: {+ in_review: { issues: [], total: 1 },+ done: { issues: [], total: 60 },+ },+ });++ onIssueUpdated(+ qc,+ WS_ID,+ { id: "off-screen", status: "done" },+ { statusChanged: true },+ );++ expectInvalidated(qc, issueKeys.list(WS_ID));+ });++ it("refetches the filtered myAll list under the same condition", () => {+ qc.setQueryData<ListIssuesCache>(issueKeys.myAll(WS_ID), {+ byStatus: { done: { issues: [], total: 60 } },+ });++ onIssueUpdated(+ qc,+ WS_ID,+ { id: "off-screen", status: "done" },+ { statusChanged: true },+ );++ expectInvalidated(qc, issueKeys.myAll(WS_ID));+ });++ it("does NOT refetch when the status-changed issue is loaded (surgical patch suffices)", () => {+ const loaded: Issue = { ...baseIssue, id: "loaded", status: "in_review" };+ qc.setQueryData<ListIssuesCache>(issueKeys.list(WS_ID), {+ byStatus: {+ in_review: { issues: [loaded], total: 1 },+ done: { issues: [], total: 60 },+ },+ });++ onIssueUpdated(+ qc,+ WS_ID,+ { ...loaded, status: "done" },+ { statusChanged: true },+ );++ const list = qc.getQueryData<ListIssuesCache>(issueKeys.list(WS_ID));+ expect(list?.byStatus.in_review?.total).toBe(0);+ expect(list?.byStatus.done?.total).toBe(61);+ // Reconciled in place — the no-flicker fast path from #4415 must hold.+ expect(qc.getQueryState(issueKeys.list(WS_ID))?.isInvalidated).toBe(false);+ });++ it("does NOT refetch an absent issue when the status did not change", () => {+ // A title/label edit of an off-screen issue cannot affect any count, so it+ // must not trigger a fallback refetch.+ qc.setQueryData<ListIssuesCache>(issueKeys.list(WS_ID), {+ byStatus: { done: { issues: [], total: 60 } },+ });++ onIssueUpdated(qc, WS_ID, { id: "off-screen", title: "renamed" });++ expect(qc.getQueryState(issueKeys.list(WS_ID))?.isInvalidated).toBe(false);+ });+});+describe("onIssueDeleted", () => {let qc: QueryClient;diff --git a/packages/core/issues/ws-updaters.ts b/packages/core/issues/ws-updaters.tsindex 42db0fc599..71dae6cee1 100644--- a/packages/core/issues/ws-updaters.ts+++ b/packages/core/issues/ws-updaters.ts@@ -1,4 +1,4 @@-import type { QueryClient } from "@tanstack/react-query";+import type { QueryClient, QueryKey } from "@tanstack/react-query";import { issueKeys } from "./queries";import { labelKeys } from "../labels/queries";import { projectKeys } from "../projects/queries";@@ -40,10 +40,11 @@ export function onIssueUpdated(qc: QueryClient,wsId: string,issue: Partial<Issue> & { id: string },- // assigneeChanged comes from the server's issue:updated flags. It gates the- // filtered-list (myAll) invalidate so a non-membership change keeps those- // lists in place instead of refetching.- meta: { assigneeChanged?: boolean } = {},+ // assigneeChanged / statusChanged come from the server's issue:updated flags.+ // assigneeChanged gates the filtered-list (myAll) invalidate so a+ // non-membership change keeps those lists in place instead of refetching.+ // statusChanged gates the off-screen count reconcile below.+ meta: { assigneeChanged?: boolean; statusChanged?: boolean } = {},) {// Look up the OLD parent before mutating list state, so we can keep// the parent's children cache in sync (powers the sub-issues list@@ -69,8 +70,25 @@ export function onIssueUpdated(const projectChanged =issue.project_id !== undefined && (issue.project_id ?? null) !== oldProjectId;+ // A status change shifts two bucket totals (the column header counts).+ // patchIssueInBuckets does that surgically, but only when it can find the card+ // in a loaded page; a paginated column holds just its first page, so an issue+ // outside that window — common when an agent flips the status of something the+ // viewer never scrolled to — makes the patch a no-op (it returns the same+ // reference) and the totals silently drift. A status change otherwise never+ // refetches the list (that refetch was the drag flicker removed by the+ // optimistic-update work), so recover the one case the patch cannot: on a+ // status-changed no-op, refetch just that single list to reconcile its counts.+ const patchOrRefetchCounts = (key: QueryKey, data: ListIssuesCache) => {+ const next = patchIssueInBuckets(data, issue.id, issue);+ qc.setQueryData<ListIssuesCache>(key, next);+ if (next === data && meta.statusChanged) {+ qc.invalidateQueries({ queryKey: key });+ }+ };+for (const [key, data] of listQueries) {- if (data) qc.setQueryData<ListIssuesCache>(key, patchIssueInBuckets(data, issue.id, issue));+ if (data) patchOrRefetchCounts(key, data);}// The workspace board (issueKeys.list) is NOT filtered: an issue is always a// member, so patchIssueInBuckets above is a complete surgical reconcile —@@ -85,9 +103,7 @@ export function onIssueUpdated(// refetch, no flicker — exactly like the workspace board above.const myListQueries = qc.getQueriesData<ListIssuesCache>({ queryKey: issueKeys.myAll(wsId) });for (const [key, data] of myListQueries) {- if (data?.byStatus) {- qc.setQueryData<ListIssuesCache>(key, patchIssueInBuckets(data, issue.id, issue));- }+ if (data?.byStatus) patchOrRefetchCounts(key, data);}// Only refetch the filtered lists when the change can actually move an issue// in/out of one. My-Issues / actor-panel membership keys on the assignee (thediff --git a/packages/core/realtime/use-realtime-sync.ts b/packages/core/realtime/use-realtime-sync.tsindex 7ef0a62270..201a24d5fe 100644--- a/packages/core/realtime/use-realtime-sync.ts+++ b/packages/core/realtime/use-realtime-sync.ts@@ -588,6 +588,7 @@ export function useRealtimeSync(if (wsId) {onIssueUpdated(qc, wsId, issue, {assigneeChanged: payload.assignee_changed,+ statusChanged: payload.status_changed,});if (issue.status) {onInboxIssueStatusChanged(qc, wsId, issue.id, issue.status);diff --git a/packages/core/types/events.ts b/packages/core/types/events.tsindex 473b422676..15445d6515 100644--- a/packages/core/types/events.ts+++ b/packages/core/types/events.ts@@ -95,11 +95,13 @@ export interface IssueCreatedPayload {export interface IssueUpdatedPayload {issue: Issue;// The server stamps issue:updated with which fields actually changed- // (server/internal/handler/issue.go publish). Only assignee_changed is read- // today: it lets the realtime layer keep filtered myList caches in place on a- // non-membership change instead of refetching. Other change flags are present- // on the wire too and can be surfaced here when needed.+ // (server/internal/handler/issue.go publish). assignee_changed lets the+ // realtime layer keep filtered myList caches in place on a non-membership+ // change instead of refetching; status_changed lets it reconcile board column+ // counts when a status change lands on an off-screen (unloaded) issue. Other+ // change flags are present on the wire too and can be surfaced here when needed.assignee_changed?: boolean;+ status_changed?: boolean;}export interface IssueDeletedPayload {