Skip to content

Commit d01bd2c

Browse files
Jasmine ZhangJasmine Zhang
authored andcommitted
fix(cron): report sqlite path in cron status
1 parent ba080f9 commit d01bd2c

5 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/cron/service/ops.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export async function status(state: CronServiceState) {
247247
await ensureLoadedForRead(state);
248248
return {
249249
enabled: state.deps.cronEnabled,
250-
storePath: state.deps.storePath,
250+
storePath: state.deps.statusStorePath ?? state.deps.storePath,
251251
jobs: state.store?.jobs.length ?? 0,
252252
nextWakeAtMs: state.deps.cronEnabled ? (nextWakeAtMs(state) ?? null) : null,
253253
};

src/cron/service/state.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it, vi } from "vitest";
2+
import { status } from "./ops.js";
23
import { createCronServiceState } from "./state.js";
34

45
describe("cron service state seam coverage", () => {
@@ -18,6 +19,7 @@ describe("cron service state seam coverage", () => {
1819
error: vi.fn(),
1920
},
2021
storePath: "/tmp/cron/jobs.json",
22+
statusStorePath: "/tmp/state/openclaw.sqlite",
2123
cronEnabled: true,
2224
defaultAgentId: "ops",
2325
sessionStorePath: "/tmp/sessions.json",
@@ -36,6 +38,7 @@ describe("cron service state seam coverage", () => {
3638
expect(state.storeFileMtimeMs).toBeNull();
3739

3840
expect(state.deps.storePath).toBe("/tmp/cron/jobs.json");
41+
expect(state.deps.statusStorePath).toBe("/tmp/state/openclaw.sqlite");
3942
expect(state.deps.cronEnabled).toBe(true);
4043
expect(state.deps.defaultAgentId).toBe("ops");
4144
expect(state.deps.sessionStorePath).toBe("/tmp/sessions.json");
@@ -67,4 +70,24 @@ describe("cron service state seam coverage", () => {
6770

6871
nowSpy.mockRestore();
6972
});
73+
74+
it("reports statusStorePath instead of the internal cron mirror path", async () => {
75+
const state = createCronServiceState({
76+
log: {
77+
debug: vi.fn(),
78+
info: vi.fn(),
79+
warn: vi.fn(),
80+
error: vi.fn(),
81+
},
82+
storePath: "/tmp/cron/jobs.json",
83+
statusStorePath: "/tmp/state/openclaw.sqlite",
84+
cronEnabled: true,
85+
enqueueSystemEvent: vi.fn(),
86+
requestHeartbeat: vi.fn(),
87+
runIsolatedAgentJob: vi.fn(async () => ({ status: "ok" as const })),
88+
});
89+
90+
const summary = await status(state);
91+
expect(summary.storePath).toBe("/tmp/state/openclaw.sqlite");
92+
});
7093
});

src/cron/service/state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export type CronServiceDeps = {
5252
nowMs?: () => number;
5353
log: Logger;
5454
storePath: string;
55+
/** Optional user-facing storage location reported by cron.status / CLI. */
56+
statusStorePath?: string;
5557
cronEnabled: boolean;
5658
/** CronConfig for session retention settings. */
5759
cronConfig?: CronConfig;

src/gateway/server-cron.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
} from "../routing/session-key.js";
4343
import { defaultRuntime } from "../runtime.js";
4444
import { parseAgentSessionKey } from "../sessions/session-key-utils.js";
45+
import { resolveOpenClawStateSqlitePath } from "../state/openclaw-state-db.paths.js";
4546
import {
4647
dispatchGatewayCronFinishedNotifications,
4748
sendGatewayCronFailureAlert,
@@ -307,6 +308,7 @@ export function buildGatewayCronService(params: {
307308

308309
const cron = new CronService({
309310
storePath,
311+
statusStorePath: resolveOpenClawStateSqlitePath(process.env),
310312
cronEnabled,
311313
cronConfig: params.cfg.cron,
312314
defaultAgentId,

src/gateway/server.cron.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type WebSocket from "ws";
77
import { resetConfigRuntimeState } from "../config/config.js";
88
import type { GuardedFetchOptions } from "../infra/net/fetch-guard.js";
99
import { peekSystemEvents } from "../infra/system-events.js";
10+
import { resolveOpenClawStateSqlitePath } from "../state/openclaw-state-db.paths.js";
1011
import type { GatewayCronState } from "./server-cron.js";
1112
import {
1213
connectOk,
@@ -1133,7 +1134,7 @@ describe("gateway server cron", () => {
11331134
| undefined;
11341135
expect(statusPayload?.enabled).toBe(true);
11351136
const storePath = typeof statusPayload?.storePath === "string" ? statusPayload.storePath : "";
1136-
expect(storePath).toContain("jobs.json");
1137+
expect(storePath).toBe(resolveOpenClawStateSqlitePath(process.env));
11371138

11381139
const autoRes = await directCronReq(cronState, "cron.add", {
11391140
name: "auto run test",

0 commit comments

Comments
 (0)