Skip to content

Commit 4f48041

Browse files
ai-hpcai-hpc
authored andcommitted
fix(agents): pass explicit CLI timeout overrides
1 parent 4891a67 commit 4f48041

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

src/agents/agent-command.live-model-switch.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,12 @@ vi.mock("./spawned-context.js", () => ({
775775
}));
776776

777777
vi.mock("./timeout.js", () => ({
778-
resolveAgentTimeoutMs: () => 30_000,
778+
resolveAgentTimeoutMs: ({ overrideSeconds }: { overrideSeconds?: number | null }) =>
779+
typeof overrideSeconds === "number" && Number.isFinite(overrideSeconds)
780+
? overrideSeconds === 0
781+
? 2_147_483_647
782+
: Math.max(overrideSeconds * 1000, 1)
783+
: 30_000,
779784
}));
780785

781786
vi.mock("./workspace.js", () => ({
@@ -1142,6 +1147,22 @@ describe("agentCommand – LiveSessionModelSwitchError retry", () => {
11421147
expect(state.updateSessionStoreAfterAgentRunMock).toHaveBeenCalledTimes(1);
11431148
});
11441149

1150+
it("passes explicit timeout overrides into agent attempts", async () => {
1151+
setupSingleAttemptFallback();
1152+
state.runAgentAttemptMock.mockResolvedValue(makeSuccessResult("openai", "gpt-5.4"));
1153+
1154+
await agentCommand({
1155+
message: "hello",
1156+
to: "+1234567890",
1157+
timeout: "600",
1158+
});
1159+
1160+
expectRecordFields(mockCallArg(state.runAgentAttemptMock), {
1161+
timeoutMs: 600_000,
1162+
runTimeoutOverrideMs: 600_000,
1163+
});
1164+
});
1165+
11451166
it("skips the initial session touch after gateway ingress already persisted activity", async () => {
11461167
setupSingleAttemptFallback();
11471168
state.runAgentAttemptMock.mockResolvedValue(makeSuccessResult("openai", "gpt-5.4"));

src/agents/agent-command.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,12 @@ async function prepareAgentCommandExecution(opts: AgentCommandOpts, runtime: Run
656656
const laneRaw = normalizeOptionalString(opts.lane) ?? "";
657657
const subagentLane: string = AGENT_LANE_SUBAGENT;
658658
const isSubagentLane = laneRaw === subagentLane;
659-
const timeoutSecondsRaw =
660-
opts.timeout !== undefined
661-
? (parseStrictNonNegativeInteger(opts.timeout) ?? Number.NaN)
662-
: isSubagentLane
663-
? 0
664-
: undefined;
659+
const hasExplicitTimeoutOption = opts.timeout !== undefined;
660+
const timeoutSecondsRaw = hasExplicitTimeoutOption
661+
? (parseStrictNonNegativeInteger(opts.timeout) ?? Number.NaN)
662+
: isSubagentLane
663+
? 0
664+
: undefined;
665665
if (
666666
timeoutSecondsRaw !== undefined &&
667667
(Number.isNaN(timeoutSecondsRaw) || timeoutSecondsRaw < 0)
@@ -672,6 +672,7 @@ async function prepareAgentCommandExecution(opts: AgentCommandOpts, runtime: Run
672672
cfg,
673673
overrideSeconds: timeoutSecondsRaw,
674674
});
675+
const runTimeoutOverrideMs = hasExplicitTimeoutOption ? timeoutMs : undefined;
675676

676677
const sessionResolution = resolveSession({
677678
cfg,
@@ -776,6 +777,7 @@ async function prepareAgentCommandExecution(opts: AgentCommandOpts, runtime: Run
776777
thinkOnce,
777778
verboseOverride,
778779
timeoutMs,
780+
runTimeoutOverrideMs,
779781
sessionId,
780782
sessionKey,
781783
sessionEntry: sessionEntryRaw,
@@ -819,6 +821,7 @@ async function agentCommandInternal(
819821
thinkOnce,
820822
verboseOverride,
821823
timeoutMs,
824+
runTimeoutOverrideMs,
822825
sessionId,
823826
sessionKey,
824827
sessionStore,
@@ -1776,6 +1779,7 @@ async function agentCommandInternal(
17761779
sessionEntry,
17771780
}).enabled,
17781781
timeoutMs,
1782+
runTimeoutOverrideMs,
17791783
runId,
17801784
opts,
17811785
runContext,

0 commit comments

Comments
 (0)