From 3e2c776aafc94e9ee8978cdf5063a5b2a2a9ef05 Mon Sep 17 00:00:00 2001 From: shuicici Date: Thu, 12 Mar 2026 20:06:29 +0800 Subject: [PATCH] fix(cron): avoid false legacy payload kind migrations --- src/cron/store-migration.test.ts | 21 +++++++++++++++++++++ src/cron/store-migration.ts | 21 ++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/cron/store-migration.test.ts b/src/cron/store-migration.test.ts index 79f3314c019..1cf43318815 100644 --- a/src/cron/store-migration.test.ts +++ b/src/cron/store-migration.test.ts @@ -75,4 +75,25 @@ describe("normalizeStoredCronJobs", () => { channel: "slack", }); }); + + it("does not report legacyPayloadKind for already-normalized payload kinds", () => { + const jobs = [ + { + id: "normalized-agent-turn", + name: "normalized", + enabled: true, + wakeMode: "now", + schedule: { kind: "every", everyMs: 60_000, anchorMs: 1 }, + payload: { kind: "agentTurn", message: "ping" }, + sessionTarget: "isolated", + delivery: { mode: "announce" }, + state: {}, + }, + ] as Array>; + + const result = normalizeStoredCronJobs(jobs); + + expect(result.mutated).toBe(false); + expect(result.issues.legacyPayloadKind).toBeUndefined(); + }); }); diff --git a/src/cron/store-migration.ts b/src/cron/store-migration.ts index 11789422e61..260b89cfe6a 100644 --- a/src/cron/store-migration.ts +++ b/src/cron/store-migration.ts @@ -28,14 +28,21 @@ function incrementIssue(issues: CronStoreIssues, key: CronStoreIssueKey) { } function normalizePayloadKind(payload: Record) { - const raw = typeof payload.kind === "string" ? payload.kind.trim().toLowerCase() : ""; - if (raw === "agentturn") { - payload.kind = "agentTurn"; - return true; + const original = typeof payload.kind === "string" ? payload.kind.trim() : ""; + const lowered = original.toLowerCase(); + if (lowered === "agentturn") { + if (original !== "agentTurn") { + payload.kind = "agentTurn"; + return true; + } + return false; } - if (raw === "systemevent") { - payload.kind = "systemEvent"; - return true; + if (lowered === "systemevent") { + if (original !== "systemEvent") { + payload.kind = "systemEvent"; + return true; + } + return false; } return false; }