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
+1
View File
@@ -156,6 +156,7 @@ function assertRunnerJobUsesWritableCodexHome(manifest: JsonRecord, expectedCode
assert.equal(value("CODEX_HOME"), expectedCodexHome);
assert.equal(value("AGENTRUN_CODEX_SECRET_HOME"), projectionPath);
assert.equal(value("AGENTRUN_RUNNER_IDLE_TIMEOUT_MS"), "600000");
assert.equal(value("AGENTRUN_RUNNER_POLL_INTERVAL_MS"), "250");
assert.equal(value("AGENTRUN_RUNNER_ONE_SHOT"), undefined);
assert.notEqual(value("CODEX_HOME"), value("AGENTRUN_CODEX_SECRET_HOME"));
}
@@ -100,6 +100,11 @@ console.log(JSON.stringify({ apiVersion: manifest.apiVersion, kind: manifest.kin
assert.equal(starts.length, 1, "same-run multiturn runner must keep one codex app-server process alive instead of restarting per command");
const multiEventsResponse = await client.get(`/api/v1/runs/${multiTurn.runId}/events?afterSeq=0&limit=200`) as { items?: Array<{ type?: string; payload?: JsonRecord }> };
const multiEvents = multiEventsResponse.items ?? [];
const secondCommandCreatedAt = await commandCreatedAt(client, multiTurn.runId, secondCommand.id);
const reuseEvent = multiEvents.find((event) => event.type === "backend_status" && event.payload?.phase === "codex-app-server:reused" && event.payload?.commandId === secondCommand.id);
assert.ok(secondCommandCreatedAt, "second command must expose createdAt for pickup latency assertion");
assert.ok(reuseEvent?.payload, "second command must produce codex-app-server:reused event");
assert.ok(Date.parse(String((reuseEvent as JsonRecord).createdAt ?? "")) - Date.parse(secondCommandCreatedAt) < 1_000, "same-run runner should pick up the next command without multi-second polling latency");
assert.equal(multiEvents.filter((event) => event.type === "backend_status" && event.payload?.phase === "codex-app-server-starting").length, 1);
assert.equal(multiEvents.filter((event) => event.type === "backend_status" && event.payload?.phase === "codex-app-server:reused").length, 1);
assert.equal(multiEvents.filter((event) => event.type === "backend_status" && event.payload?.phase === "resource-bundle-materialized").length, 1);
@@ -164,6 +169,11 @@ async function waitForCommandState(client: ManagerClient, runId: string, command
throw new Error(`command ${commandId} did not reach ${state}`);
}
async function commandCreatedAt(client: ManagerClient, runId: string, commandId: string): Promise<string> {
const command = await client.get(`/api/v1/runs/${runId}/commands/${commandId}`) as { createdAt?: string };
return command.createdAt ?? "";
}
async function readTextIfExists(filePath: string): Promise<string> {
try {
return await readFile(filePath, "utf8");