Skip to content

Commit 697b814

Browse files
committed
fix(cron): preserve padded duplicate keys when canonical form already exists (#95407)
When both a padded key (e.g. 'schedule ') and its canonical form ('schedule') exist, the padded key is now preserved so strict gateway validation rejects the ambiguous input rather than silently picking one value. Only padded keys without a canonical counterpart are trimmed.
1 parent f7c500f commit 697b814

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎src/agents/tools/cron-tool-canonicalize.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,22 @@ function canonicalizeCronToolPayload(value: Record<string, unknown>): void {
250250
* validation to reject the job with "unexpected property" errors.
251251
*
252252
* Only recognized CRON_RECOVERABLE_OBJECT_KEYS are trimmed — arbitrary keys
253-
* (including special ones like "__proto__") are never mutated. If both the
254-
* padded and canonical form of a key exist (e.g. "schedule " and "schedule"),
255-
* the canonical key wins and the padded variant is discarded.
253+
* (including special ones like "__proto__") are never mutated.
254+
*
255+
* If both the padded and canonical form of a key exist (e.g. "schedule " and
256+
* "schedule"), the padded key is preserved so strict gateway validation
257+
* rejects the ambiguous input rather than silently picking one value.
256258
*/
257259
function repairPaddedCronKeys(value: Record<string, unknown>): void {
258260
for (const key of Object.keys(value)) {
259261
const trimmed = key.trim();
260262
if (trimmed !== key && CRON_RECOVERABLE_OBJECT_KEYS.has(trimmed)) {
261263
if (!(trimmed in value)) {
262264
value[trimmed] = value[key];
265+
delete value[key];
263266
}
264-
delete value[key];
267+
// When the canonical key already exists, preserve the padded duplicate
268+
// so strict gateway validation sees the conflict and rejects the input.
265269
}
266270
}
267271
}

‎src/agents/tools/cron-tool.flat-params.test.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,18 @@ describe("cron tool flat-params", () => {
264264
expect(params).toHaveProperty("constructor ");
265265
});
266266

267-
it("preserves canonical key when both padded and clean form exist (#95407)", async () => {
267+
it("preserves padded duplicate when canonical key already exists (#95407)", async () => {
268+
// When both canonical and padded forms exist, the padded key is preserved
269+
// so strict gateway validation rejects the ambiguous input rather than
270+
// silently picking one value.
268271
const tool = createCronTool(undefined, { callGatewayTool: callGatewayToolMock });
269272

270273
await tool.execute("call-duplicate-keys", {
271274
action: "add",
272275
job: {
273276
name: "Duplicate test",
274277
schedule: { kind: "cron", expr: "0 9 * * 1-5", tz: "UTC" },
275-
// Both "schedule" and "schedule " exist — canonical wins
278+
// Both "schedule" and "schedule " exist — padded preserved for rejection
276279
"schedule ": { kind: "every", everyMs: 60000 },
277280
payload: { kind: "agentTurn", message: "work" },
278281
"enabled ": true,
@@ -282,12 +285,14 @@ describe("cron tool flat-params", () => {
282285

283286
const [method, _gatewayOpts, params] = firstGatewayToolCall<Record<string, unknown>>();
284287
expect(method).toBe("cron.add");
285-
// Canonical keys should not be overwritten by padded variants
288+
// Canonical key is untouched
286289
expect((params.schedule as Record<string, unknown>)?.kind).toBe("cron");
287290
expect(params.enabled).toBe(false);
288-
// Padded keys should be removed
289-
expect(params).not.toHaveProperty("schedule ");
290-
expect(params).not.toHaveProperty("enabled ");
291+
// Padded keys are preserved so gateway schema validation sees the conflict
292+
// and rejects with "unexpected property 'schedule '" instead of silently
293+
// accepting one of the two conflicting values.
294+
expect(params).toHaveProperty("schedule ");
295+
expect(params).toHaveProperty("enabled ");
291296
});
292297

293298
it("preserves normal keys without any whitespace", async () => {

0 commit comments

Comments
 (0)