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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (antigravity): treat an id missing from a successful project batch as pruned, not in flight (#4149)
[._.]/ Adam Eivy0c82db6ce910
diff --git a/client/src/pages/CreativeCommissionDetail.jsx b/client/src/pages/CreativeCommissionDetail.jsxindex cb4ae26c29..1c018d8642 100644--- a/client/src/pages/CreativeCommissionDetail.jsx+++ b/client/src/pages/CreativeCommissionDetail.jsx@@ -78,6 +78,12 @@ export default function CreativeCommissionDetail() {// check reads, so it re-evaluates on every poll tick rather than freezing at// whatever `Date.now()` was during the last render.const [projectsFetchedAt, setProjectsFetchedAt] = useState(0);+ // The id set the batch last resolved SUCCESSFULLY. Distinct from the+ // attempted-key ref below: a failed fetch is an attempt but not a load, and+ // the in-flight check has to keep the two apart — an id missing from a+ // successful batch is a pruned project (settled), while the same id missing+ // because the request failed is simply not known yet (retry).+ const [projectsLoadedKey, setProjectsLoadedKey] = useState(null);const { isConfirming, requestDelete, cancelDelete, confirmDelete } = useConfirmDelete();// Load (and refresh) the deep-linked commission. `location.key` is a dep so a@@ -140,6 +146,7 @@ export default function CreativeCommissionDetail() {setProjectsById(new Map());setProjectsLoading(false);projectsAttemptedKeyRef.current = '';+ setProjectsLoadedKey('');return null;}// Only the FIRST attempt at a given id set shows "loading…" — a poll tick@@ -152,7 +159,10 @@ export default function CreativeCommissionDetail() {// Index by id, not position: an id that no longer resolves (pruned project)// is absent from the response, and its card degrades to the status-only// placeholder. A FAILED fetch keeps the last good map instead of blanking it.- if (Array.isArray(projects)) setProjectsById(new Map(projects.map((p) => [p.id, p])));+ if (Array.isArray(projects)) {+ setProjectsById(new Map(projects.map((p) => [p.id, p])));+ setProjectsLoadedKey(projectIdsKey);+ }projectsAttemptedKeyRef.current = projectIdsKey;setProjectsLoading(false);// Stamped on every ATTEMPT, not just a successful one, so the in-flight age@@ -163,20 +173,24 @@ export default function CreativeCommissionDetail() {// Is any run still producing? A run row is written once with status 'started'// and never revisited, so "still generating" has to come from the project it- // points at — unresolved (a just-created project can postdate the last batch)- // or sitting in a non-terminal CD status.+ // points at, in a non-terminal CD status.const hasGeneratingRun = useMemo(() => {// The freshness of the data we're judging, not wall-clock render time.const now = projectsFetchedAt || Date.now();+ // Has the CURRENT id set come back from a successful batch? Until it has, an+ // unresolved id means "not known yet" (initial load, or a failed attempt+ // worth retrying) — after it has, the same id means the project was pruned,+ // and no amount of polling brings it back.+ const batchIsAuthoritative = projectsLoadedKey === projectIdsKey;return (commission?.runs || []).some((r) => {if (r?.status !== 'started' || !r.projectId) return false;const ranAt = Date.parse(r.ranAt);if (!Number.isFinite(ranAt) || now - ranAt > IN_FLIGHT_RUN_MAX_AGE_MS) return false;const project = projectsById.get(r.projectId);- if (!project) return true;+ if (!project) return !batchIsAuthoritative;return GENERATING_PROJECT_STATUSES.has(project.status);});- }, [commission, projectsById, projectsFetchedAt]);+ }, [commission, projectsById, projectsFetchedAt, projectsLoadedKey, projectIdsKey]);// Poll only while something is actually generating; the hook also pauses while// the tab is hidden and re-fires on return. `immediate: false` because the@@ -189,8 +203,12 @@ export default function CreativeCommissionDetail() {// Fetch whenever the referenced id set changes (including the initial load and// a Run Now appending a render) — the poll is gated on in-flight work, so it- // can't be responsible for the first read.- useEffect(() => { refetchProjects(); }, [projectIdsKey, refetchProjects]);+ // can't be responsible for the first read. The newest run id is a dep too: a+ // fire always mints a NEW project today, so the id set moves on its own, but a+ // run that ever REUSED a project id would otherwise be judged against the+ // cached 'complete' snapshot and never start polling.+ const latestRunId = commission?.runs?.length ? commission.runs[commission.runs.length - 1].id : null;+ useEffect(() => { refetchProjects(); }, [projectIdsKey, latestRunId, refetchProjects]);const patchForm = useCallback((path, value) => setForm((prev) => patchFormState(prev, path, value)), []);diff --git a/client/src/pages/CreativeCommissionDetail.test.jsx b/client/src/pages/CreativeCommissionDetail.test.jsxindex f08b4b5197..db8f3fa242 100644--- a/client/src/pages/CreativeCommissionDetail.test.jsx+++ b/client/src/pages/CreativeCommissionDetail.test.jsx@@ -183,8 +183,44 @@ describe('CreativeCommissionDetail live render refresh (#4149)', () => {expect(api.getCreativeDirectorProjectsByIds.mock.calls.length).toBe(initialCalls);});- it('no longer tells the user to reload when a run starts', async () => {- api.runCommissionNow.mockResolvedValue({ status: 'started', commission: COMMISSION });+ it('treats a project the batch resolved as pruned as settled, not in flight', async () => {+ vi.useFakeTimers();+ // The batch answered for this exact id set and omitted cd-1 — the project is+ // gone. Polling can never resurrect it, so the page must not keep asking.+ api.getCommission.mockResolvedValue(withRun(new Date().toISOString()));+ api.getCreativeDirectorProjectsByIds.mockResolvedValue([]);++ await mountLoaded();+ expect(screen.getByText('render unavailable')).toBeTruthy();+ const prunedCalls = api.getCreativeDirectorProjectsByIds.mock.calls.length;++ await settle(30000);+ expect(api.getCreativeDirectorProjectsByIds.mock.calls.length).toBe(prunedCalls);+ });++ it('keeps retrying while the project batch request is failing', async () => {+ vi.useFakeTimers();+ // A FAILED fetch is not an authoritative "pruned" answer — an unresolved id+ // still means "not known yet", so the poll has to stay armed.+ api.getCommission.mockResolvedValue(withRun(new Date().toISOString()));+ api.getCreativeDirectorProjectsByIds.mockRejectedValue(new Error('offline'));++ await mountLoaded();+ const failedCalls = api.getCreativeDirectorProjectsByIds.mock.calls.length;++ await settle(5000);+ expect(api.getCreativeDirectorProjectsByIds.mock.calls.length).toBeGreaterThan(failedCalls);+ });++ it('refetches the render batch for a new run and drops the reload advice', async () => {+ const started = {+ id: 'run-new', projectId: 'cd-new', status: 'started', trigger: 'manual',+ ranAt: new Date().toISOString(),+ };+ api.getCommission.mockResolvedValue({ ...COMMISSION, runs: [] });+ api.runCommissionNow.mockResolvedValue({+ status: 'started', commission: { ...COMMISSION, runs: [started] },+ });render(<MemoryRouter><CreativeCommissionDetail /></MemoryRouter>);await screen.findByRole('heading', { name: COMMISSION.name });@@ -192,6 +228,8 @@ describe('CreativeCommissionDetail live render refresh (#4149)', () => {fireEvent.click(screen.getByRole('button', { name: /Run commission .* now/i }));});+ await waitFor(() => expect(api.getCreativeDirectorProjectsByIds)+ .toHaveBeenCalledWith(['cd-new'], { silent: true }));expect(toast.success).toHaveBeenCalledWith(expect.stringContaining('appears below'));expect(toast.success).toHaveBeenCalledWith(expect.not.stringContaining('reload'));});