diff --git a/packages/core/src/services/monitorRegistry.test.ts b/packages/core/src/services/monitorRegistry.test.ts index 86a5189c8..dc09ec70e 100644 --- a/packages/core/src/services/monitorRegistry.test.ts +++ b/packages/core/src/services/monitorRegistry.test.ts @@ -664,5 +664,22 @@ describe('MonitorRegistry', () => { ).not.toThrow(); expect(registry.get('a')).toBeDefined(); }); + + it('fires once on reset() so dialog snapshots clear stale rows', () => { + registry.register(createEntry({ monitorId: 'a' })); + registry.register(createEntry({ monitorId: 'b' })); + const cb = vi.fn(); + registry.setStatusChangeCallback(cb); + registry.reset(); + expect(cb).toHaveBeenCalledTimes(1); + expect(registry.getAll()).toEqual([]); + }); + + it('reset() on an empty registry does not fire statusChange', () => { + const cb = vi.fn(); + registry.setStatusChangeCallback(cb); + registry.reset(); + expect(cb).not.toHaveBeenCalled(); + }); }); }); diff --git a/packages/core/src/services/monitorRegistry.ts b/packages/core/src/services/monitorRegistry.ts index 710f856f7..ff14c2542 100644 --- a/packages/core/src/services/monitorRegistry.ts +++ b/packages/core/src/services/monitorRegistry.ts @@ -250,6 +250,7 @@ export class MonitorRegistry { } reset(): void { + if (this.monitors.size === 0) return; for (const entry of this.monitors.values()) { this.clearIdleTimer(entry); if (entry.status === 'running') { @@ -257,6 +258,12 @@ export class MonitorRegistry { } } this.monitors.clear(); + // Notify subscribers that the registry's contents changed wholesale + // — without this, the dialog snapshot in `useBackgroundTaskView` + // would keep rendering the now-cleared rows until an unrelated + // register/settle event happens. Mirrors BackgroundShellRegistry / + // BackgroundTaskRegistry's reset paths. + this.fireStatusChange(); } // --- Internal helpers ---