Skip to content

Commit 8d5dce0

Browse files
committed
fix(cron): guard watcher-state writes against replaced on-exit jobs
ClawSweeper P1: an old watcher's failure write could land on a job that was edited or converted to a different schedule, pushing the replacement into failure backoff or auto-disable. Watcher-state persistence now uses the same identity precondition as persistCompletion (enabled, on-exit, updatedAtMs match) and treats a mismatch as a no-op.
1 parent f979138 commit 8d5dce0

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎src/gateway/server-cron.ts‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,25 @@ export function buildGatewayCronService(params: {
11551155
);
11561156
},
11571157
updateWatcherState: async (job, patch) =>
1158-
await runWithGatewayIndependentRootWorkAdmission(
1159-
async () => await cron.update(job.id, { state: patch }),
1160-
),
1158+
await runWithGatewayIndependentRootWorkAdmission(async () => {
1159+
try {
1160+
// Same identity guard as persistCompletion: a watcher whose job was
1161+
// edited/replaced must not write failure state onto the successor
1162+
// (which could push it into failure backoff or auto-disable).
1163+
return await cron.updateWithPrecondition(job.id, { state: patch }, (current) => {
1164+
if (
1165+
!current.enabled ||
1166+
current.schedule.kind !== "on-exit" ||
1167+
current.updatedAtMs !== job.updatedAtMs
1168+
) {
1169+
throw new Error("cron on-exit job changed before watcher-state write");
1170+
}
1171+
});
1172+
} catch {
1173+
// Stale watcher identity is a no-op, not an error to surface.
1174+
return undefined;
1175+
}
1176+
}),
11611177
logger: cronLogger,
11621178
});
11631179
const updateCron = cron.update.bind(cron);

0 commit comments

Comments
 (0)