feat(dashboard): 60s base refresh with event-driven immediate updates
Raise the status dashboard base refresh from 10s to 60s, and refresh immediately (debounced 1.5s) on events between ticks: - a real chat message arrives in a registered room (index.ts onMessage) - an agent starts/finishes a run, i.e. activity moves between rooms (GroupQueue.setOnActivityChange fired on activeCount changes) requestImmediateStatusUpdate() drives updateStatus out-of-band via a coalescing trigger. The existing re-entrancy guard means the base periodic refresh does not run while an edit-retry is in flight; a refresh requested during that window is remembered and runs once afterward. Adds createCoalescingTrigger with tests. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
|
||||
import type { UsageRow } from './dashboard-usage-rows.js';
|
||||
import {
|
||||
buildWebUsageRowsForSnapshot,
|
||||
createCoalescingTrigger,
|
||||
editStatusMessageWithRetry,
|
||||
formatStatusHeader,
|
||||
getDashboardDuplicateCleanupIntervalMs,
|
||||
@@ -312,3 +313,30 @@ describe('editStatusMessageWithRetry', () => {
|
||||
expect(slept).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createCoalescingTrigger', () => {
|
||||
it('coalesces a burst into one run and re-arms after firing', () => {
|
||||
let runs = 0;
|
||||
let fire: (() => void) | null = null;
|
||||
const timer = {
|
||||
set: (cb: () => void) => {
|
||||
fire = cb;
|
||||
return 0 as unknown as ReturnType<typeof setTimeout>;
|
||||
},
|
||||
};
|
||||
const trigger = createCoalescingTrigger(() => runs++, 1500, timer);
|
||||
|
||||
trigger();
|
||||
trigger();
|
||||
trigger();
|
||||
expect(runs).toBe(0); // nothing runs until the debounce window elapses
|
||||
|
||||
fire!();
|
||||
expect(runs).toBe(1); // three calls collapsed into a single run
|
||||
|
||||
// A new request after the run schedules and fires again.
|
||||
trigger();
|
||||
fire!();
|
||||
expect(runs).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user