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

@@ -157,6 +157,66 @@ describe('codex-usage-collector fallback account usage', () => {
]);
});
it('runs the repo-pinned Codex CLI rather than a global codex binary', async () => {
createDefaultCodexAuth(tempHome);
const childProcess = await import('child_process');
let captured: { cmd: string; args: readonly string[] | undefined } | null =
null;
vi.mocked(childProcess.spawn).mockImplementation(((
cmd: string,
args: readonly string[] | undefined,
) => {
captured = { cmd, args };
return createFakeChildProcess({
codex: {
limitName: 'Codex',
primary: { usedPercent: 1, resetsAt: new Date().toISOString() },
secondary: { usedPercent: 1, resetsAt: new Date().toISOString() },
},
}) as never;
}) as unknown as typeof childProcess.spawn);
const rotation = await import('./codex-token-rotation.js');
const usage = await import('./codex-usage-collector.js');
rotation.initCodexTokenRotation();
await usage.refreshActiveCodexUsage();
expect(captured).not.toBeNull();
expect(captured!.cmd).toBe(process.execPath);
expect(captured!.args).toEqual([
path.join(
process.cwd(),
'node_modules',
'@openai',
'codex',
'bin',
'codex.js',
),
'app-server',
]);
});
it('skips the poll instead of spawning Codex while a run holds the account lease', async () => {
createDefaultCodexAuth(tempHome);
const childProcess = await import('child_process');
vi.mocked(childProcess.spawn).mockImplementation((() => {
throw new Error('must not spawn while the account is leased');
}) as unknown as typeof childProcess.spawn);
const rotation = await import('./codex-token-rotation.js');
const usage = await import('./codex-usage-collector.js');
rotation.initCodexTokenRotation();
const held = rotation.claimCodexAuthLease();
expect(held).not.toBeNull();
try {
const result = await usage.refreshActiveCodexUsage();
expect(result.fetchedAt).toBeNull();
expect(childProcess.spawn).not.toHaveBeenCalled();
} finally {
held?.release();
}
});
it('handles a lone weekly window (secondary: null) without throwing and routes it to 7d', async () => {
createDefaultCodexAuth(tempHome);
const childProcess = await import('child_process');
@@ -201,6 +261,9 @@ describe('codex-usage-collector fallback account usage', () => {
it('finds codex via ~/.hermes/node/bin when running under bun', async () => {
createDefaultCodexAuth(tempHome);
// PATH discovery only applies when the repo-pinned Codex package is absent.
const originalCwd = process.cwd();
process.chdir(tempHome);
const childProcess = await import('child_process');
const bunExecPath = path.join(tempHome, '.bun', 'bin', 'bun');
const hermesBin = path.join(tempHome, '.hermes', 'node', 'bin');
@@ -269,6 +332,7 @@ describe('codex-usage-collector fallback account usage', () => {
}),
]);
} finally {
process.chdir(originalCwd);
Object.defineProperty(process, 'execPath', {
configurable: true,
writable: true,