Poll dashboard duplicate cleanup between status updates

Run duplicate dashboard cleanup on a short interval so stale external Status messages are removed between normal status updates.
This commit is contained in:
Eyejoker
2026-05-04 00:02:27 +09:00
committed by GitHub
parent 2be267c51e
commit bc78d43967
2 changed files with 19 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import type { UsageRow } from './dashboard-usage-rows.js';
import { import {
buildWebUsageRowsForSnapshot, buildWebUsageRowsForSnapshot,
formatStatusHeader, formatStatusHeader,
getDashboardDuplicateCleanupIntervalMs,
renderUsageTable, renderUsageTable,
shouldPurgeDashboardChannelOnStart, shouldPurgeDashboardChannelOnStart,
summarizeWatcherTasks, summarizeWatcherTasks,
@@ -82,6 +83,13 @@ describe('shouldPurgeDashboardChannelOnStart', () => {
}); });
}); });
describe('getDashboardDuplicateCleanupIntervalMs', () => {
it('polls duplicate cleanup faster than the status update interval', () => {
expect(getDashboardDuplicateCleanupIntervalMs(10_000)).toBe(2_000);
expect(getDashboardDuplicateCleanupIntervalMs(1_000)).toBe(1_000);
});
});
describe('renderUsageTable', () => { describe('renderUsageTable', () => {
const claudeRow: UsageRow = { const claudeRow: UsageRow = {
name: 'Claude pro', name: 'Claude pro',

View File

@@ -99,6 +99,7 @@ const USAGE_SNAPSHOT_MAX_AGE_MS = 600_000;
* so this only affects how quickly Codex snapshot data is picked up. * so this only affects how quickly Codex snapshot data is picked up.
*/ */
const RENDERER_USAGE_REFRESH_MS = 30_000; const RENDERER_USAGE_REFRESH_MS = 30_000;
const DASHBOARD_DUPLICATE_CLEANUP_POLL_MS = 2_000;
let statusMessageId: string | null = null; let statusMessageId: string | null = null;
let cachedUsageContent = ''; let cachedUsageContent = '';
@@ -171,6 +172,12 @@ export function shouldPurgeDashboardChannelOnStart(args: {
return args.purgeOnStart === true; return args.purgeOnStart === true;
} }
export function getDashboardDuplicateCleanupIntervalMs(
statusUpdateInterval: number,
): number {
return Math.min(statusUpdateInterval, DASHBOARD_DUPLICATE_CLEANUP_POLL_MS);
}
async function refreshChannelMeta( async function refreshChannelMeta(
opts: UnifiedDashboardOptions, opts: UnifiedDashboardOptions,
): Promise<void> { ): Promise<void> {
@@ -798,6 +805,10 @@ export async function startUnifiedDashboard(
}; };
setInterval(updateStatus, opts.statusUpdateInterval); setInterval(updateStatus, opts.statusUpdateInterval);
setInterval(() => {
if (!isRenderer || !statusMessageId) return;
void cleanupDashboardDuplicateMessages(opts, statusMessageId);
}, getDashboardDuplicateCleanupIntervalMs(opts.statusUpdateInterval));
await updateStatus(); await updateStatus();
if (isRenderer) { if (isRenderer) {