From ffe1937b924e961d4cf126265defafc8fba1cd71 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 2 Mar 2026 01:58:25 +0000 Subject: [PATCH] fix(cli): set cron run exit code from run outcome (land #31121 by @Sid-Qin) Landed-from: #31121 Contributor: @Sid-Qin Co-authored-by: Sid --- CHANGELOG.md | 1 + src/cli/cron-cli.test.ts | 52 ++++++++++++++++++++++++ src/cli/cron-cli/register.cron-simple.ts | 2 + 3 files changed, 55 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b98966ed..ab09adc22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ Docs: https://docs.openclaw.ai ### Fixes +- CLI/Cron run exit code: return exit code `0` only when `cron run` reports `{ ok: true, ran: true }`, and `1` for non-run/error outcomes so scripting/debugging reflects actual execution status. Landed from contributor PR #31121 by @Sid-Qin. Thanks @Sid-Qin. - Nodes/Screen recording guardrails: cap `nodes` tool `screen_record` `durationMs` to 5 minutes at both schema-validation and runtime invocation layers to prevent long-running blocking captures from unbounded durations. Landed from contributor PR #31106 by @BlueBirdBack. Thanks @BlueBirdBack. - Telegram/Empty final replies: skip outbound send for null/undefined final text payloads without media so Telegram typing indicators do not linger on `text must be non-empty` errors. Landed from contributor PR #30969 by @haosenwang1018. Thanks @haosenwang1018. - Routing/Binding peer-kind parity: treat `peer.kind` `group` and `channel` as equivalent for binding scope matching (while keeping `direct` separate) so Slack/public channel bindings do not silently fall through. Landed from contributor PR #31135 by @Sid-Qin. Thanks @Sid-Qin. diff --git a/src/cli/cron-cli.test.ts b/src/cli/cron-cli.test.ts index 1483a8ec6..1867605d5 100644 --- a/src/cli/cron-cli.test.ts +++ b/src/cli/cron-cli.test.ts @@ -151,6 +151,58 @@ async function expectCronEditWithScheduleLookupExit( } describe("cron cli", () => { + it("exits 0 for cron run when job executes successfully", async () => { + resetGatewayMock(); + callGatewayFromCli.mockImplementation(async (method: string) => { + if (method === "cron.status") { + return { enabled: true }; + } + if (method === "cron.run") { + return { ok: true, ran: true }; + } + return { ok: true }; + }); + + const runtimeModule = await import("../runtime.js"); + const runtime = runtimeModule.defaultRuntime as { exit: (code: number) => void }; + const originalExit = runtime.exit; + const exitSpy = vi.fn(); + runtime.exit = exitSpy; + try { + const program = buildProgram(); + await program.parseAsync(["cron", "run", "job-1"], { from: "user" }); + expect(exitSpy).toHaveBeenCalledWith(0); + } finally { + runtime.exit = originalExit; + } + }); + + it("exits 1 for cron run when job does not execute", async () => { + resetGatewayMock(); + callGatewayFromCli.mockImplementation(async (method: string) => { + if (method === "cron.status") { + return { enabled: true }; + } + if (method === "cron.run") { + return { ok: true, ran: false }; + } + return { ok: true }; + }); + + const runtimeModule = await import("../runtime.js"); + const runtime = runtimeModule.defaultRuntime as { exit: (code: number) => void }; + const originalExit = runtime.exit; + const exitSpy = vi.fn(); + runtime.exit = exitSpy; + try { + const program = buildProgram(); + await program.parseAsync(["cron", "run", "job-1"], { from: "user" }); + expect(exitSpy).toHaveBeenCalledWith(1); + } finally { + runtime.exit = originalExit; + } + }); + it("trims model and thinking on cron add", { timeout: CRON_CLI_TEST_TIMEOUT_MS }, async () => { await runCronCommand([ "cron", diff --git a/src/cli/cron-cli/register.cron-simple.ts b/src/cli/cron-cli/register.cron-simple.ts index bd8be34d3..49f09bd1e 100644 --- a/src/cli/cron-cli/register.cron-simple.ts +++ b/src/cli/cron-cli/register.cron-simple.ts @@ -100,6 +100,8 @@ export function registerCronSimpleCommands(cron: Command) { mode: opts.due ? "due" : "force", }); defaultRuntime.log(JSON.stringify(res, null, 2)); + const result = res as { ok?: boolean; ran?: boolean } | undefined; + defaultRuntime.exit(result?.ok && result?.ran ? 0 : 1); } catch (err) { defaultRuntime.error(danger(String(err))); defaultRuntime.exit(1);