Skip to content

Commit 93f2aee

Browse files
axisrowclaude
andcommitted
fix: reset idle deadline on in-item progress/delta notifications
The idle deadline was only reset on turn/started, item/started, and item/completed — not on the streaming progress notifications a single long-running item emits while active (item/commandExecution/outputDelta, item/mcpToolCall/progress, item/agentMessage/delta, etc). A large command execution or MCP tool call that runs past the idle budget while continuously streaming output was interrupted mid-flight despite being genuinely active — exactly the failure mode this PR set out to eliminate. Found by Codex adversarial review during cycle-review round 1. Co-Authored-By: Claude Sonnet 5 <[email protected]>
1 parent d118611 commit 93f2aee

3 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎plugins/codex/scripts/lib/codex.mjs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,23 @@ function applyTurnNotification(state, message) {
619619
emitProgress(state.onProgress, update?.message, update?.phase ?? null);
620620
}
621621
break;
622+
// In-item progress/delta notifications: a single item (a long command
623+
// execution, an MCP tool call, streamed model/reasoning output) can run
624+
// well past the idle budget while continuously producing these without
625+
// ever emitting another item/started or item/completed in between. Treat
626+
// them as activity too, or a genuinely progressing item gets interrupted
627+
// mid-flight — the exact failure mode this idle timeout exists to avoid.
628+
case "item/commandExecution/outputDelta":
629+
case "item/fileChange/outputDelta":
630+
case "item/mcpToolCall/progress":
631+
case "item/agentMessage/delta":
632+
case "item/plan/delta":
633+
case "item/reasoning/summaryTextDelta":
634+
case "item/reasoning/textDelta":
635+
case "command/exec/outputDelta":
636+
case "process/outputDelta":
637+
state.resetIdleDeadline?.();
638+
break;
622639
case "error":
623640
state.error = message.params.error;
624641
emitProgress(state.onProgress, `Codex error: ${message.params.error.message}`, "failed");

‎tests/fake-codex-fixture.mjs‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,48 @@ rl.on("line", (line) => {
786786
}
787787
});
788788
// Then silence — no further notifications for this turn, ever.
789+
} else if (BEHAVIOR === "single-item-progress-idle-ok") {
790+
// One item/started, then a long stream of commandExecution outputDelta
791+
// notifications spanning well past the idle budget with no other
792+
// item/started or item/completed in between, then item/completed.
793+
// Must NOT time out — the deltas count as activity too.
794+
send({ method: "turn/started", params: { threadId: thread.id, turn: buildTurn(turnId) } });
795+
send({
796+
method: "item/started",
797+
params: {
798+
threadId: thread.id,
799+
turnId,
800+
item: { type: "commandExecution", id: "cmd_" + turnId, command: "long-running step", status: "inProgress" }
801+
}
802+
});
803+
const gapMs = 700;
804+
const deltaCount = 6;
805+
let step = 0;
806+
const tick = () => {
807+
step += 1;
808+
send({
809+
method: "item/commandExecution/outputDelta",
810+
params: { threadId: thread.id, turnId, itemId: "cmd_" + turnId, delta: "chunk " + step + "\\n" }
811+
});
812+
if (step >= deltaCount) {
813+
send({
814+
method: "item/completed",
815+
params: {
816+
threadId: thread.id,
817+
turnId,
818+
item: { type: "commandExecution", id: "cmd_" + turnId, command: "long-running step", status: "completed" }
819+
}
820+
});
821+
send({
822+
method: "item/completed",
823+
params: { threadId: thread.id, turnId, item: { type: "agentMessage", id: "msg_" + turnId, text: payload, phase: "final_answer" } }
824+
});
825+
send({ method: "turn/completed", params: { threadId: thread.id, turn: buildTurn(turnId, "completed") } });
826+
return;
827+
}
828+
setTimeout(tick, gapMs);
829+
};
830+
setTimeout(tick, gapMs);
789831
} else {
790832
emitTurnCompleted(thread.id, turnId, items);
791833
}

‎tests/runtime.test.mjs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3228,3 +3228,29 @@ test("task that goes silent after the first event times out via the idle budget,
32283228
const storedJob = readPersistedJob(repo);
32293229
assert.equal(storedJob.status, "failed", "job must be marked failed");
32303230
});
3231+
3232+
test("task with in-item output-delta progress longer than the budget does NOT time out (single long item, idle not wall-clock)", () => {
3233+
const repo = makeTempDir();
3234+
const binDir = makeTempDir();
3235+
installFakeCodex(binDir, "single-item-progress-idle-ok");
3236+
initGitRepo(repo);
3237+
fs.writeFileSync(path.join(repo, "README.md"), "hello\n");
3238+
run("git", ["add", "README.md"], { cwd: repo });
3239+
run("git", ["commit", "-m", "init"], { cwd: repo });
3240+
3241+
// Fixture emits one item/started, then 6 item/commandExecution/outputDelta
3242+
// notifications spaced 700ms apart (~4.2s total) with no other item/started
3243+
// or item/completed in between, then completes. The gap between the initial
3244+
// item/started and the first delta (and each subsequent delta) is well
3245+
// under the 2s budget, but the total span from item/started to the final
3246+
// item/completed exceeds it. Must NOT time out: in-item progress deltas
3247+
// must reset the idle deadline just like item boundaries do.
3248+
const result = run("node", [SCRIPT, "task", "--turn-timeout-ms", "2000", "test prompt"], {
3249+
cwd: repo,
3250+
env: buildEnv(binDir)
3251+
});
3252+
3253+
assert.equal(result.status, 0, `must succeed despite one long item spanning the budget: ${result.stderr}`);
3254+
const storedJob = readPersistedJob(repo);
3255+
assert.equal(storedJob.status, "completed", "job must complete, not be killed mid-item");
3256+
});

0 commit comments

Comments
 (0)