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

address review (codex): let the hook own the coalesced toast lifetime

[._.]/ Adam Eivy3103c0e3ac77
diff --git a/client/src/hooks/useAIStatusNotifications.js b/client/src/hooks/useAIStatusNotifications.js
index 462cd3d027..5e9bee9c7a 100644
--- a/client/src/hooks/useAIStatusNotifications.js
+++ b/client/src/hooks/useAIStatusNotifications.js
@@ -69,29 +69,40 @@ export function useAIStatusNotifications() {
const reason = event.message || `${providerLabel} background AI call failed`;
const entry = silentErrorsRef.current.get(key);
+ // The hook owns the coalesced toast's whole lifetime: render it with
+ // `duration: Infinity` so Toast schedules NO auto-dismiss timer of its own
+ // (it never cancels those, and each update's stale timer would otherwise
+ // dismiss the toast mid-window), and dismiss it ourselves once the rolling
+ // window lapses — SILENT_ERROR_WINDOW_MS after the LAST failure, since the
+ // timer is reset on every update below.
+ const armWindowExpiry = (k, toastId) =>
+ setTimeout(() => {
+ toast.dismiss(toastId);
+ silentErrorsRef.current.delete(k);
+ }, SILENT_ERROR_WINDOW_MS);
+
if (!entry) {
- // Fresh window. Give the toast a window-unique id: Toast schedules an
- // independent auto-dismiss timer per add() and never cancels it, so a
- // stable per-provider id would let a lapsed window's pending dismissal
- // remove the NEXT window's toast a second or two after it appeared.
+ // Fresh window. Give the toast a window-unique id so that even if a
+ // dismissal ever races a brand-new window (e.g. rapid lapse/re-open),
+ // it can only ever target its own window's toast, never a successor's.
windowSeqRef.current += 1;
const toastId = `ai-silent-error::${key}::${windowSeqRef.current}`;
const fresh = { toastId, count: 1, firstReason: reason, timer: undefined };
- fresh.timer = setTimeout(() => silentErrorsRef.current.delete(key), SILENT_ERROR_WINDOW_MS);
+ fresh.timer = armWindowExpiry(key, toastId);
silentErrorsRef.current.set(key, fresh);
- toast.error(reason, { id: toastId, duration: 6000, icon: '✕' });
+ toast.error(reason, { id: toastId, duration: Infinity, icon: '✕' });
return;
}
entry.count += 1;
if (entry.timer) clearTimeout(entry.timer);
- entry.timer = setTimeout(() => silentErrorsRef.current.delete(key), SILENT_ERROR_WINDOW_MS);
+ entry.timer = armWindowExpiry(key, entry.toastId);
// Retain the first real reason — the count alone doesn't tell the user
// whether it was an expired key, a timeout, or a bad response, and these
// events can all land before the browser paints, so the counted toast is
// often the only one the user ever sees.
toast.error(`${providerLabel} failed on ${entry.count} background AI calls — ${entry.firstReason}`, {
- id: entry.toastId, duration: 6000, icon: '✕'
+ id: entry.toastId, duration: Infinity, icon: '✕'
});
};
@@ -174,6 +185,9 @@ export function useAIStatusNotifications() {
opsRef.current.clear();
for (const e of silentErrorsRef.current.values()) {
if (e.timer) clearTimeout(e.timer);
+ // These toasts render with duration: Infinity, so nothing else will
+ // dismiss them once we drop their window timer — clear them explicitly.
+ toast.dismiss(e.toastId);
}
silentErrorsRef.current.clear();
};
diff --git a/client/src/hooks/useAIStatusNotifications.test.jsx b/client/src/hooks/useAIStatusNotifications.test.jsx
index 32f1ed31cb..1eab0d3fd3 100644
--- a/client/src/hooks/useAIStatusNotifications.test.jsx
+++ b/client/src/hooks/useAIStatusNotifications.test.jsx
@@ -162,6 +162,31 @@ describe('useAIStatusNotifications — silent-op error coalescing', () => {
expect(errs[0].opts?.id).toMatch(/^ai-silent-error::prov-1::/);
});
+ it('keeps the coalesced toast alive across staggered same-window failures until the window lapses after the LAST one', () => {
+ renderHook(() => useAIStatusNotifications());
+
+ act(() => {
+ emit({ id: 's1', phase: 'error', silent: true, providerId: 'prov-1', providerName: 'Example Provider', message: 'first' });
+ });
+ // Second failure 3.5s later — still inside the 4s rolling window.
+ act(() => { vi.advanceTimersByTime(3500); });
+ act(() => {
+ emit({ id: 's2', phase: 'error', silent: true, providerId: 'prov-1', providerName: 'Example Provider', message: 'second' });
+ });
+ const coalescedId = errorCalls()[0].opts?.id;
+
+ // Coalesced toasts render with duration: Infinity, so Toast schedules no
+ // auto-dismiss of its own. Advance to t=6 (where a stale per-add 6s timer
+ // from the t=0 toast would have fired) — the toast must still be alive.
+ act(() => { vi.advanceTimersByTime(2500); });
+ expect(dismissCalls().some(c => c.id === coalescedId)).toBe(false);
+
+ // The window is measured from the LAST failure (t=3.5), so it lapses at
+ // t=7.5; advance past it and the hook dismisses exactly this window's toast.
+ act(() => { vi.advanceTimersByTime(2000); });
+ expect(dismissCalls().filter(c => c.id === coalescedId)).toHaveLength(1);
+ });
+
it('starts a fresh coalescing window after the previous one lapses', () => {
renderHook(() => useAIStatusNotifications());