fix: reduce runner command poll latency

This commit is contained in:
Codex
2026-06-02 02:00:30 +08:00
parent 9b401086d0
commit 30458a7efe
4 changed files with 18 additions and 1 deletions
+6 -1
View File
@@ -62,7 +62,7 @@ export async function runOnce(options: RunnerOnceOptions): Promise<JsonRecord> {
const stopHeartbeat = startHeartbeat(api, options.runId, runner.id, leaseMs);
const idleTimeoutMs = options.idleTimeoutMs ?? 120_000;
const pollIntervalMs = options.pollIntervalMs ?? 2_000;
const pollIntervalMs = normalizePollIntervalMs(options.pollIntervalMs);
const commandResults: CommandExecutionResult[] = [];
let workspacePath: string | undefined;
let materializationAttempted = false;
@@ -231,3 +231,8 @@ function noPendingResult(runner: RunnerRecord, claimed: RunRecord, commandResult
function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function normalizePollIntervalMs(value: number | undefined): number {
if (!Number.isFinite(value ?? NaN)) return 250;
return Math.max(50, Math.min(2_000, Math.floor(value!)));
}