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
fix(ui): dismiss healthy quality submission notices after five seconds (#11517)
[._.]/4053021133d5
diff --git a/client/src/hooks/useOnDemandTaskToast.js b/client/src/hooks/useOnDemandTaskToast.jsindex 76fda4e161..10bc6075ce 100644--- a/client/src/hooks/useOnDemandTaskToast.js+++ b/client/src/hooks/useOnDemandTaskToast.js@@ -42,6 +42,21 @@ const PR_REVIEWER_REASON_LABELS = {'security-guard-not-ready': "the local model-abuse classifier (Settings → Models → LLMs → Abuse Guard) isn't ready — finish or repair its setup, then try again",};+// Maintenance also records ordinary queue waits in `reason`. Only these exact+// server messages are routine; unfamiliar reasons must remain actionable.+function maintenanceNeedsAttention(run) {+ if (run.status === 'stopped') return run.reason !== 'stopped by the user';+ if (run.status !== 'running') return false;+ const active = run.active;+ if (active?.status === 'blocked') return true;+ if (!run.reason) return false;+ if (active?.taskId && ['pending', 'in_progress'].includes(active.status)+ && run.reason === `waiting for ${active.status.replace('_', ' ')} task ${active.taskId}`) return false;+ if (active?.requestId && (run.reason === `waiting for request preparation ${active.requestId}`+ || run.reason === `waiting for the CoS daemon to accept request ${active.requestId} (${active.taskType})`)) return false;+ return true;+}+/*** Global subscriber that toasts when a user-initiated on-demand task run* produced no work. The server emits `cos:schedule:on-demand-empty` ONLY for@@ -60,14 +75,34 @@ export function useOnDemandTaskToast() {const { current, total } = maintenanceRunProgress(run);const label = `Maintenance · ${current}/${total} · ${run.status}`;const signature = JSON.stringify([run.status, run.completed, run.active, run.reason]);- if (maintenanceStates.get(run.id) === signature) return;- maintenanceStates.set(run.id, signature);- if (maintenanceStates.size > 100) maintenanceStates.delete(maintenanceStates.keys().next().value);- if (run.status !== 'running') toast.dismiss(`maintenance-${run.id}`);+ const previous = maintenanceStates.get(run.id);+ if (previous?.signature === signature) return;+ const attention = maintenanceNeedsAttention(run);+ const attentionKey = attention ? JSON.stringify([run.status, run.active?.status === 'blocked', run.reason]) : null;+ const state = { status: run.status, signature, attentionKey, submissionShown: previous?.submissionShown || false, toastId: previous?.toastId };+ maintenanceStates.set(run.id, state);+ // Bound settled history without forgetting a still-running submission or+ // a dismissed hold: later progress must not resurrect either notice.+ const settled = [...maintenanceStates].filter(([, entry]) => entry.status !== 'running' && !entry.attentionKey);+ if (settled.length > 100) {+ const [id, entry] = settled.find(([id]) => id !== run.id);+ if (entry.toastId) toast.dismiss(entry.toastId);+ maintenanceStates.delete(id);+ }+ if (attention && previous?.attentionKey === attentionKey) return;+ if (run.status === 'running' && !attention) {+ if (previous?.attentionKey) toast.dismiss(previous.toastId);+ // This is a submission receipt, not the live run view. Replacing it on+ // progress would restart Toast's timer or resurrect a dismissed notice.+ if (state.submissionShown) return;+ state.submissionShown = true;+ }const toastId = run.status === 'running' ? `maintenance-${run.id}` : `maintenance-${run.id}-${run.updatedAt}`;+ if (previous?.toastId && previous.toastId !== toastId) toast.dismiss(previous.toastId);+ state.toastId = toastId;const onDismiss = () => toast.dismiss(toastId);toast(() => createElement(MaintenanceRunStatus, { run, onDismiss }), {- id: toastId, label, duration: run.status === 'running' ? Infinity : 8000,+ id: toastId, label, duration: attention ? Infinity : run.status === 'running' ? 5000 : 8000,});};socket.on('cos:maintenance:updated', handleMaintenance);@@ -192,6 +227,9 @@ export function useOnDemandTaskToast() {socket.off('cos:maintenance:updated', handleMaintenance);socket.off('cos:schedule:on-demand-empty', handleEmpty);socket.off('cos:schedule:on-demand-handled', handleHandled);+ for (const state of maintenanceStates.values()) {+ if (state.toastId) toast.dismiss(state.toastId);+ }// Don't unsubscribe from cos — other components share the room.};}, []);diff --git a/client/src/hooks/useOnDemandTaskToast.maintenance.test.jsx b/client/src/hooks/useOnDemandTaskToast.maintenance.test.jsxnew file mode 100644index 0000000000..cbb4641370--- /dev/null+++ b/client/src/hooks/useOnDemandTaskToast.maintenance.test.jsx@@ -0,0 +1,155 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';+import MaintenanceRunStatus from '../components/cos/tabs/schedule/MaintenanceRunStatus';+import toast, { Toaster } from '../components/ui/Toast';++const handlers = vi.hoisted(() => new Map());+vi.mock('../services/socket', () => ({ default: {+ on: (event, handler) => handlers.set(event, handler),+ off: (event, handler) => { if (handlers.get(event) === handler) handlers.delete(event); },+ emit: () => {},+} }));++const { useOnDemandTaskToast } = await import('./useOnDemandTaskToast');+const run = {+ id: 'maintenance-example', status: 'running', completed: {}, reason: null,+ steps: [{ id: 'quality-step', taskRef: { taskType: 'security' } }],+ active: { stepId: 'quality-step', taskType: 'security', status: 'queued', requestId: 'request-example' },+};+function Subscriber() {+ useOnDemandTaskToast();+ return null;+}+function Harness({ subscribed = true }) {+ return <>{subscribed && <Subscriber />}<Toaster />+ <aside aria-label="Ongoing quality run"><MaintenanceRunStatus run={run} /></aside>+ </>;+}+const update = (changes = {}) => act(() => handlers.get('cos:maintenance:updated')?.({ ...run, ...changes }));+const advance = ms => act(() => vi.advanceTimersByTime(ms));+const notifications = () => within(screen.getByRole('region', { name: 'Notifications' }));++beforeEach(() => { vi.useFakeTimers(); handlers.clear(); });+afterEach(() => { cleanup(); toast.dismiss(); vi.useRealTimers(); });++describe('maintenance submission notification lifetime', () => {+ it('expires at five seconds despite ordinary queue/progress events and keeps the ongoing view accessible', () => {+ render(<Harness />);+ update();+ advance(1000);+ update({ reason: 'waiting for the CoS daemon to accept request request-example (security)' });+ advance(1000);+ update({ reason: 'waiting for request preparation request-example' });+ advance(1000);+ update({ active: { ...run.active, taskId: 'task-example', status: 'pending' }, reason: 'waiting for pending task task-example' });+ advance(1000);+ update({ active: { ...run.active, taskId: 'task-example', status: 'in_progress' }, reason: 'waiting for in progress task task-example' });+ advance(999);+ expect(notifications().getByRole('button', { name: 'Dismiss notification' })).toBeVisible();+ advance(1);+ expect(notifications().queryByRole('status')).toBeNull();+ expect(within(screen.getByRole('complementary', { name: 'Ongoing quality run' })).getByRole('status')).toHaveTextContent('running');+ update({ active: { ...run.active, status: 'running', agentId: 'agent-example' } });+ expect(notifications().queryByRole('status')).toBeNull();++ update({ id: 'maintenance-next' });+ advance(4999);+ expect(notifications().getByRole('button', { name: 'Dismiss notification' })).toBeVisible();+ advance(1);+ expect(notifications().queryByRole('status')).toBeNull();+ });++ it('respects manual dismissal without suppressing a new actionable hold', () => {+ render(<Harness />);+ update();+ fireEvent.click(notifications().getByRole('button', { name: 'Dismiss notification' }));+ update({ active: { ...run.active, status: 'running', agentId: 'agent-example' } });+ expect(notifications().queryByRole('status')).toBeNull();+ update({ reason: 'Provider setup requires attention' });+ advance(20000);+ fireEvent.click(notifications().getByRole('button', { name: /Show notification:/ }));+ expect(notifications().getByText('Provider setup requires attention')).toBeInTheDocument();+ fireEvent.click(notifications().getByRole('button', { name: 'Dismiss notification' }));+ update({ reason: 'Provider setup requires attention', active: { ...run.active, agentId: 'agent-example' } });+ expect(notifications().queryByRole('status')).toBeNull();+ update({ reason: 'Choose an available provider' });+ expect(notifications().getByText('Choose an available provider')).toBeInTheDocument();+ update();+ expect(notifications().queryByRole('status')).toBeNull();+ });++ it('keeps blocked tasks and stopped failures available instead of treating them as submission success', () => {+ render(<Harness />);+ update({ active: { ...run.active, taskId: 'task-example', status: 'blocked' }, reason: 'waiting for blocked task task-example' });+ advance(20000);+ fireEvent.click(notifications().getByRole('button', { name: /Show notification:/ }));+ expect(notifications().getByText('waiting for blocked task task-example')).toBeInTheDocument();+ update({ status: 'stopped', reason: 'Request was interrupted; resume explicitly.', updatedAt: 'finished' });+ advance(20000);+ fireEvent.click(notifications().getByRole('button', { name: /Show notification:/ }));+ expect(notifications().getByText('Request was interrupted; resume explicitly.')).toBeInTheDocument();+ });++ it('preserves the toast focus pause without restarting the remaining lifetime on progress', () => {+ render(<Harness />);+ update();+ advance(2000);+ const dismiss = notifications().getByRole('button', { name: 'Dismiss notification' });+ fireEvent.focus(dismiss);+ advance(10000);+ update({ active: { ...run.active, status: 'running' } });+ expect(dismiss).toBeVisible();+ fireEvent.blur(dismiss, { relatedTarget: document.body });+ advance(2999);+ expect(dismiss).toBeVisible();+ advance(1);+ expect(notifications().queryByRole('status')).toBeNull();+ });++ it('does not forget an active receipt or dismissed failure when settled history exceeds the cache limit', () => {+ render(<Harness />);+ update();+ advance(5000);+ const failure = { id: 'maintenance-held', status: 'stopped', reason: 'Request was interrupted; resume explicitly.', updatedAt: 'finished' };+ update(failure);+ fireEvent.click(notifications().getByRole('button', { name: 'Dismiss notification' }));+ for (let index = 0; index < 101; index++) {+ update({ id: `maintenance-settled-${index}`, status: 'completed', active: null, updatedAt: 'finished' });+ }+ advance(8000);+ update({ active: { ...run.active, status: 'running', agentId: 'agent-example' } });+ update({ ...failure, active: { ...run.active, agentId: 'agent-example' } });+ expect(notifications().queryByRole('status')).toBeNull();+ expect(notifications().queryByRole('button', { name: /Show notification:/ })).toBeNull();+ });++ it('removes only its own notices and timers when the subscriber unmounts', () => {+ const { rerender } = render(<Harness />);+ act(() => toast('Unrelated notice', { duration: 10000 }));+ const unrelatedTimers = vi.getTimerCount();+ update();+ expect(vi.getTimerCount()).toBeGreaterThan(unrelatedTimers);+ rerender(<Harness subscribed={false} />);+ expect(notifications().queryByRole('button', { name: 'Dismiss notification' })).toBeNull();+ expect(notifications().getByText('Unrelated notice')).toBeVisible();+ expect(vi.getTimerCount()).toBe(unrelatedTimers);+ expect(handlers.size).toBe(0);+ advance(10000);+ expect(notifications().queryByRole('status')).toBeNull();+ });++ it('still owns the completion notice when the oldest active run finishes after the history cache fills', () => {+ const { rerender } = render(<Harness />);+ update();+ advance(5000);+ for (let index = 0; index < 100; index++) {+ update({ id: `maintenance-settled-${index}`, status: 'completed', active: null, updatedAt: 'finished' });+ }+ advance(8000);+ update({ status: 'completed', active: null, completed: { 'quality-step': 'done' }, updatedAt: 'finished' });+ expect(notifications().getByRole('button', { name: 'Dismiss notification' })).toBeVisible();+ rerender(<Harness subscribed={false} />);+ expect(notifications().queryByRole('status')).toBeNull();+ expect(vi.getTimerCount()).toBe(0);+ });+});diff --git a/client/src/hooks/useOnDemandTaskToast.test.jsx b/client/src/hooks/useOnDemandTaskToast.test.jsxindex b426f09350..bc802d6720 100644--- a/client/src/hooks/useOnDemandTaskToast.test.jsx+++ b/client/src/hooks/useOnDemandTaskToast.test.jsx@@ -295,7 +295,7 @@ describe('useOnDemandTaskToast — programmatic handler results', () => {});});-it('updates one maintenance notification with an agent link and expires terminal progress', () => {+it('shows one submission notification with an agent link and expires terminal progress', () => {toastSpy.mockClear();const { unmount } = renderHook(() => useOnDemandTaskToast());const update = handlers.get('cos:maintenance:updated');@@ -303,7 +303,7 @@ it('updates one maintenance notification with an agent link and expires terminalupdate(run);update(run);expect(toastSpy).toHaveBeenCalledTimes(1);- expect(toastSpy.mock.calls[0][1]).toMatchObject({ id: 'maintenance-maint-example', duration: Infinity });+ expect(toastSpy.mock.calls[0][1]).toMatchObject({ id: 'maintenance-maint-example', duration: 5000 });expect(toastSpy.mock.calls[0][0]().props.run.active.agentId).toBe('agent-example');// onDismiss dismisses the toastexpect(typeof toastSpy.mock.calls[0][0]().props.onDismiss).toBe('function');