perf: cut background polling and log noise

- Codex usage poll: run the repo-pinned CLI (0.159.3) instead of a global
  0.128 install, hold the account lease while polling (skip if a run holds
  it, so the poller cannot rotate a token under a live reviewer session), and
  poll every 5 min instead of every minute (~1,440 app-server spawns a day).
- Claude usage poll: 5 min instead of 1 min. The 1-minute cadence only served
  the auto-paired-mode gate, which is not wired into the runtime; it drew ~32
  HTTP 429s a day.
- Dashboard duplicate cleanup: was a 2 s poll fetching 100 messages (~43k
  Discord REST calls a day) plus a fetch after every edit. Clean up only when a
  fresh status message is posted or on first render, with a 5 min sweep.
- Logging: one line per event and no ANSI colors outside a TTY (events were
  split into ~11 journal lines). Progress-edit audits, Discord progress edits,
  streamed-activity and per-bucket Codex usage logs move to debug; sends,
  agent output and the usage summary stay at info.
- Two tests wrote under the real data/ipc and left fake room folders that the
  live 1 s IPC watcher kept polling; they now clean up after themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-01 18:32:14 +09:00
parent de2de33c3e
commit f1abe037e9
15 changed files with 233 additions and 36 deletions

View File

@@ -99,7 +99,12 @@ const USAGE_SNAPSHOT_MAX_AGE_MS = 600_000;
* so this only affects how quickly Codex snapshot data is picked up.
*/
const RENDERER_USAGE_REFRESH_MS = 30_000;
const DASHBOARD_DUPLICATE_CLEANUP_POLL_MS = 2_000;
const CODEX_ACTIVE_USAGE_POLL_MS = 300_000;
// Safety sweep for stray duplicate dashboard messages. Duplicates only appear
// when a new status message is posted (restart, failed edit), and that path
// cleans up immediately, so a slow sweep is enough. It used to poll every 2s:
// ~43k Discord REST fetches of 100 messages per day.
const DASHBOARD_DUPLICATE_CLEANUP_POLL_MS = 300_000;
let statusMessageId: string | null = null;
let cachedUsageContent = '';
@@ -196,10 +201,8 @@ export function shouldPurgeDashboardChannelOnStart(args: {
return args.purgeOnStart === true;
}
export function getDashboardDuplicateCleanupIntervalMs(
statusUpdateInterval: number,
): number {
return Math.min(statusUpdateInterval, DASHBOARD_DUPLICATE_CLEANUP_POLL_MS);
export function getDashboardDuplicateCleanupIntervalMs(): number {
return DASHBOARD_DUPLICATE_CLEANUP_POLL_MS;
}
async function refreshChannelMeta(
@@ -1013,17 +1016,23 @@ export async function startUnifiedDashboard(
}
}
let postedNewMessage = false;
if (!statusMessageId && channel.sendAndTrack) {
const id = await channel.sendAndTrack(statusJid, content);
if (id) {
statusMessageId = id;
postedNewMessage = true;
writeDashboardStatusMessageId(opts.statusChannelId, id);
}
}
// Duplicates only come from posting a fresh status message (restart or a
// failed edit), so clean up then and on the first render — not on every
// routine edit, which used to cost a 100-message fetch each minute.
const shouldCleanupDuplicates = postedNewMessage || firstStatusRender;
// A render (edit or repost) happened this tick; subsequent ticks use the
// steady-state retry policy.
firstStatusRender = false;
if (statusMessageId) {
if (statusMessageId && shouldCleanupDuplicates) {
await cleanupDashboardDuplicateMessages(opts, statusMessageId);
}
if (!dashboardUpdateLogged) {
@@ -1066,7 +1075,7 @@ export async function startUnifiedDashboard(
setInterval(() => {
if (!isRenderer || !statusMessageId) return;
void cleanupDashboardDuplicateMessages(opts, statusMessageId);
}, getDashboardDuplicateCleanupIntervalMs(opts.statusUpdateInterval));
}, getDashboardDuplicateCleanupIntervalMs());
await updateStatus();
if (isRenderer) {
@@ -1110,9 +1119,11 @@ export async function startUnifiedDashboard(
return refreshActiveCodexUsage().then(applyCodexRefresh);
})
.then(() => runCodexWarmup());
// Each poll spawns a Codex app-server; every 5 minutes is plenty for the
// dashboard (it used to run every minute, ~1,440 spawns a day).
setInterval(
() => void refreshActiveCodexUsage().then(applyCodexRefresh),
opts.usageUpdateInterval,
Math.max(opts.usageUpdateInterval, CODEX_ACTIVE_USAGE_POLL_MS),
);
setInterval(
() =>