Skip to content

Commit d0db8a9

Browse files
zyw02steipete
andauthored
fix(cli): let nested agent exec --timeout override the parent flag (#125256)
* fix(cli): let nested agent exec --timeout override the parent flag * fix(cli): keep nested exec --timeout inherit comment to the option-source invariant --------- Co-authored-by: zyw02 <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent a237bc1 commit d0db8a9

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎src/cli/program/register.agent-turn.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Command } from "commander";
44
import { formatDocsLink } from "../../../packages/terminal-core/src/links.js";
55
import { theme } from "../../../packages/terminal-core/src/theme.js";
66
import { THINKING_LEVELS_HELP } from "../../auto-reply/thinking.shared.js";
7+
import { inheritOptionFromParent } from "../command-options.js";
78
import { measureCliCommandStartup } from "../command-startup-timing.js";
89
import { formatHelpExamples } from "../help-format.js";
910
import { requestExitAfterOneShotOutput } from "../one-shot-exit.js";
@@ -190,7 +191,9 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/agent", "docs.openclaw.ai/cli/age
190191
messageFile: opts.messageFile ?? parentOpts?.messageFile,
191192
model: opts.model ?? parentOpts?.model,
192193
thinking: opts.thinking ?? parentOpts?.thinking,
193-
timeout: parentOpts?.timeout ?? opts.timeout,
194+
// Exec --timeout defaults to "600"; inherit a parent flag only when the
195+
// leaf source is default. An explicit nested --timeout must win.
196+
timeout: inheritOptionFromParent<string>(command, "timeout") ?? opts.timeout,
194197
json: opts.json === true || parentOpts?.json === true,
195198
};
196199
const [defaultRuntime, runCommandWithRuntime, agentExecCommand] = await Promise.all([

‎src/cli/program/register.agent.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ vi.mock("../one-shot-exit.js", () => ({
8080

8181
describe("agent command registration", () => {
8282
async function runCli(args: string[]) {
83-
const program = new Command();
83+
const program = new Command().enablePositionalOptions();
8484
registerAgentTurnCommand(program, { agentChannelOptions: "last|telegram|discord" });
8585
registerAgentsCommands(program);
8686
await program.parseAsync(args, { from: "user" });
@@ -262,6 +262,29 @@ describe("agent command registration", () => {
262262
);
263263
});
264264

265+
it("resolves nested exec --timeout from the explicit leaf, then the parent, then the default", async () => {
266+
await runCli(["agent", "exec", "fix it", "--timeout", "120"]);
267+
expect(agentExecCommandMock).toHaveBeenLastCalledWith(
268+
"fix it",
269+
expect.objectContaining({ timeout: "120" }),
270+
runtime,
271+
);
272+
273+
await runCli(["agent", "--timeout", "30", "exec", "fix it"]);
274+
expect(agentExecCommandMock).toHaveBeenLastCalledWith(
275+
"fix it",
276+
expect.objectContaining({ timeout: "30" }),
277+
runtime,
278+
);
279+
280+
await runCli(["agent", "--timeout", "30", "exec", "fix it", "--timeout", "120"]);
281+
expect(agentExecCommandMock).toHaveBeenLastCalledWith(
282+
"fix it",
283+
expect.objectContaining({ timeout: "120" }),
284+
runtime,
285+
);
286+
});
287+
265288
it("runs agents add and detects explicit automation options", async () => {
266289
await runCli(["agents", "add", "alpha"]);
267290
const [alphaOptions, alphaRuntime, alphaFlags] = commandCall(agentsAddCommandMock, 0);

0 commit comments

Comments
 (0)