fix(cron): keep manual runs non-blocking

This commit is contained in:
Peter Steinberger
2026-02-22 19:47:41 +01:00
parent 91f75a2b33
commit 5db1ee4ec6
4 changed files with 139 additions and 7 deletions

View File

@@ -162,6 +162,59 @@ describe("CronService read ops while job is running", () => {
}
});
it("keeps list and status responsive during manual cron.run execution", async () => {
const store = await makeStorePath();
const enqueueSystemEvent = vi.fn();
const requestHeartbeatNow = vi.fn();
const isolatedRun = createDeferredIsolatedRun();
const cron = new CronService({
storePath: store.storePath,
cronEnabled: true,
log: noopLogger,
enqueueSystemEvent,
requestHeartbeatNow,
runIsolatedAgentJob: isolatedRun.runIsolatedAgentJob,
});
try {
await cron.start();
const job = await cron.add({
name: "manual run isolation",
enabled: true,
deleteAfterRun: false,
schedule: {
kind: "at",
at: new Date("2030-01-01T00:00:00.000Z").toISOString(),
},
sessionTarget: "isolated",
wakeMode: "next-heartbeat",
payload: { kind: "agentTurn", message: "manual run" },
delivery: { mode: "none" },
});
const runPromise = cron.run(job.id, "force");
await isolatedRun.runStarted;
await expect(
withTimeout(cron.list({ includeDisabled: true }), 300, "cron.list during cron.run"),
).resolves.toBeTypeOf("object");
await expect(withTimeout(cron.status(), 300, "cron.status during cron.run")).resolves.toEqual(
expect.objectContaining({ enabled: true, storePath: store.storePath }),
);
isolatedRun.completeRun({ status: "ok", summary: "manual done" });
await expect(runPromise).resolves.toEqual({ ok: true, ran: true });
const completed = await cron.list({ includeDisabled: true });
expect(completed[0]?.state.lastStatus).toBe("ok");
expect(completed[0]?.state.runningAtMs).toBeUndefined();
} finally {
cron.stop();
await store.cleanup();
}
});
it("keeps list and status responsive during startup catch-up runs", async () => {
const store = await makeStorePath();
const enqueueSystemEvent = vi.fn();