Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: keep a stale sprint-ticket response from overwriting a newer one (#3437)

[._.]/ Adam Eivyf07e650d2583
diff --git a/client/src/components/apps/tabs/OverviewTab.jsx b/client/src/components/apps/tabs/OverviewTab.jsx
index a7435321f6..430e8e0de9 100644
--- a/client/src/components/apps/tabs/OverviewTab.jsx
+++ b/client/src/components/apps/tabs/OverviewTab.jsx
@@ -1,4 +1,4 @@
-import { useState, useEffect, useMemo, useCallback } from 'react';
+import { useState, useEffect, useMemo, useCallback, useRef } from 'react';
import { Link } from 'react-router';
import { FolderOpen, Gamepad2, Terminal, Code, RefreshCw, Wrench, Archive, ArchiveRestore, Ticket, Download, Tag, AlertTriangle, Rocket, Camera, Image, Sparkles } from 'lucide-react';
import toast from '../../ui/Toast';
@@ -24,6 +24,7 @@ export default function OverviewTab({ app, onRefresh }) {
const [jiraTickets, setJiraTickets] = useState(null);
const [loadingTickets, setLoadingTickets] = useState(false);
const [ticketError, setTicketError] = useState(null);
+ const ticketRequestRef = useRef(0);
const [installingScripts, setInstallingScripts] = useState(false);
const [detectingIcon, setDetectingIcon] = useState(false);
// Reverse lookup (#2991): sprite records that publish assets into this app.
@@ -41,12 +42,18 @@ export default function OverviewTab({ app, onRefresh }) {
// tickets" and offered no way to retry.
const loadSprintTickets = useCallback(() => {
if (!app?.jira?.enabled || !app.jira.instanceId || !app.jira.projectKey) return;
+ // Generation guard: a Retry (or a JIRA-config change) while an earlier
+ // request is still open must not let the older response land last.
+ const generation = ticketRequestRef.current + 1;
+ ticketRequestRef.current = generation;
+ const isCurrent = () => ticketRequestRef.current === generation;
+
setLoadingTickets(true);
setTicketError(null);
api.getMySprintTickets(app.jira.instanceId, app.jira.projectKey, { silent: true })
- .then(tickets => setJiraTickets(Array.isArray(tickets) ? tickets : []))
- .catch(err => setTicketError(err?.message || 'Request failed'))
- .finally(() => setLoadingTickets(false));
+ .then(tickets => { if (isCurrent()) setJiraTickets(Array.isArray(tickets) ? tickets : []); })
+ .catch(err => { if (isCurrent()) setTicketError(err?.message || 'Request failed'); })
+ .finally(() => { if (isCurrent()) setLoadingTickets(false); });
}, [app?.jira?.enabled, app?.jira?.instanceId, app?.jira?.projectKey]);
useEffect(() => { loadSprintTickets(); }, [loadSprintTickets]);
diff --git a/client/src/pages/Apps.jsx b/client/src/pages/Apps.jsx
index 66900c28b9..abbe7cfe87 100644
--- a/client/src/pages/Apps.jsx
+++ b/client/src/pages/Apps.jsx
@@ -43,6 +43,8 @@ export default function Apps() {
// focus back to the control that opened it instead of dropping it on <body>.
const menuTriggerRefs = useRef({});
const menuTriggerRef = (id) => (menuTriggerRefs.current[id] ||= { current: null });
+ // Per-app sprint-ticket request tracking: `{ generation, active }`.
+ const ticketRequestsRef = useRef({});
const fetchApps = useCallback(async () => {
const data = await api.getApps().catch(() => []);
@@ -126,15 +128,24 @@ export default function Apps() {
// the cached empty array, never retried for the life of the page (#3437).
// Failure records a message and leaves `jiraTickets[id]` undefined, so both
// Retry and a re-expand re-issue the request; a genuine `[]` is still cached.
+ // Per-app request generation, so a slow earlier fetch can't land after a newer
+ // one and overwrite a good board with its stale error (the pending-request
+ // convention in client/src/CLAUDE.md).
const loadSprintTickets = useCallback(async (app) => {
+ const generation = (ticketRequestsRef.current[app.id]?.generation || 0) + 1;
+ ticketRequestsRef.current[app.id] = { generation, active: true };
+ const isCurrent = () => ticketRequestsRef.current[app.id]?.generation === generation;
+
setLoadingTickets(prev => ({ ...prev, [app.id]: true }));
setTicketErrors(prev => ({ ...prev, [app.id]: null }));
const tickets = await api
.getMySprintTickets(app.jira.instanceId, app.jira.projectKey, { silent: true })
.catch(err => {
- setTicketErrors(prev => ({ ...prev, [app.id]: err?.message || 'Request failed' }));
+ if (isCurrent()) setTicketErrors(prev => ({ ...prev, [app.id]: err?.message || 'Request failed' }));
return null;
});
+ if (!isCurrent()) return; // superseded — the newer request owns the state
+ ticketRequestsRef.current[app.id].active = false;
if (Array.isArray(tickets)) setJiraTickets(prev => ({ ...prev, [app.id]: tickets }));
setLoadingTickets(prev => ({ ...prev, [app.id]: false }));
}, []);
@@ -147,7 +158,7 @@ export default function Apps() {
if (!newExpandedId) return;
const app = apps.find(a => a.id === newExpandedId);
if (!app?.jira?.enabled || !app.jira.instanceId || !app.jira.projectKey) return;
- if (!jiraTickets[id]) loadSprintTickets(app);
+ if (!jiraTickets[id] && !ticketRequestsRef.current[id]?.active) loadSprintTickets(app);
};
// Archive/unarchive gate their success toast on a response, the way
diff --git a/client/src/pages/Apps.test.jsx b/client/src/pages/Apps.test.jsx
index 3033c52934..962ec90a60 100644
--- a/client/src/pages/Apps.test.jsx
+++ b/client/src/pages/Apps.test.jsx
@@ -475,3 +475,35 @@ describe('Apps sprint-ticket fetch failures (#3437)', () => {
expect(api.getMySprintTickets).toHaveBeenCalledWith('jira-1', 'EX', { silent: true });
});
});
+
+describe('Apps sprint-ticket request races (#3437)', () => {
+ const JIRA_APP = {
+ ...APPS[0],
+ jira: { enabled: true, instanceId: 'jira-1', projectKey: 'EX', issueType: 'Task' }
+ };
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ api.getApps.mockResolvedValue([JIRA_APP]);
+ });
+
+ it('does not start a second fetch while one is still in flight, and the in-flight result still lands', async () => {
+ let resolveFirst;
+ api.getMySprintTickets.mockImplementation(() => new Promise(resolve => { resolveFirst = resolve; }));
+
+ const user = userEvent.setup();
+ await renderApps();
+ const toggle = () => user.click(screen.getByRole('button', { name: /(Expand|Collapse) Example App details/ }));
+
+ await toggle(); // first fetch — hangs
+ await toggle(); // collapse
+ await toggle(); // re-expand while the first request is still open
+
+ // One request, not two — so no older response can land after a newer one
+ // and overwrite it.
+ expect(api.getMySprintTickets).toHaveBeenCalledTimes(1);
+
+ await act(async () => { resolveFirst([]); });
+ expect(await screen.findByText('No tickets assigned to you in the current sprint')).toBeTruthy();
+ });
+});