Preserve cron task ledger run IDs

This commit is contained in:
Paul Frederiksen
2026-05-02 23:55:10 +00:00
parent 0e7244c389
commit 04ce879858
2 changed files with 30 additions and 3 deletions

View File

@@ -182,6 +182,35 @@ describe("cron service ops seam coverage", () => {
stop(state);
});
it("keeps manual acknowledgement IDs separate from recoverable task run IDs", async () => {
const { storePath } = await makeStorePath();
const now = Date.parse("2026-03-23T12:00:00.000Z");
const restoreStateDir = withStateDirForStorePath(storePath);
try {
await writeDueIsolatedJobSnapshot(storePath, now);
const state = createOkIsolatedCronState({ storePath, now, summary: "done" });
const manualRunId = `manual:isolated-timeout:${now}:1`;
await expect(
run(state, "isolated-timeout", "force", { runId: manualRunId }),
).resolves.toEqual({
ok: true,
ran: true,
});
expect(findTaskByRunId(`cron:isolated-timeout:${now}`)).toMatchObject({
runtime: "cron",
status: "succeeded",
sourceId: "isolated-timeout",
});
expect(findTaskByRunId(manualRunId)).toBeUndefined();
} finally {
restoreStateDir();
}
});
it("records timed out manual runs as timed_out in the shared task registry", async () => {
const { storePath } = await makeStorePath();
const now = Date.parse("2026-03-23T12:00:00.000Z");

View File

@@ -508,9 +508,8 @@ function tryCreateManualTaskRun(params: {
state: CronServiceState;
job: CronJob;
startedAt: number;
runId?: string;
}): string | undefined {
const runId = params.runId ?? createCronExecutionId(params.job.id, params.startedAt);
const runId = createCronExecutionId(params.job.id, params.startedAt);
try {
createRunningTaskRun({
runtime: "cron",
@@ -662,7 +661,6 @@ async function prepareManualRun(
state,
job,
startedAt: preflight.now,
runId: opts?.runId,
});
const executionJob = structuredClone(job);
return {