Skip to content

Commit a58a18f

Browse files
[AI-assisted] fix(cron): preserve cron tool keys during tool call argument repair
1 parent e35e5f1 commit a58a18f

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎src/agents/embedded-agent-runner/run/attempt.tool-call-argument-repair.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,30 @@ const re = /\d+/;
465465
});
466466
expect(result.finalArgs).not.toHaveProperty("foo");
467467
});
468+
469+
it("repairs smart-quoted cron add args without mangling keys", async () => {
470+
const result = await runToolCallRepairCase({
471+
toolName: "cron",
472+
delta: String.raw` {“action”:“add”,“job”:{“name”:“Holiday Check-in”,“description”:“Casual check-in while on holiday, 2x per day”,“schedule”:{“kind”:“cron”,“expr”:“30 10,20 * * *”,“tz”:“Europe/Madrid”},“sessionTarget”:“isolated”,“payload”:{“kind”:“agentTurn”,“message”:“Holiday check-in: how’s everything going? Anything you need help with today?”},“enabled”:true}}`,
473+
});
474+
475+
expectAllToolCallArgs(result, {
476+
action: "add",
477+
job: {
478+
name: "Holiday Check-in",
479+
description: "Casual check-in while on holiday, 2x per day",
480+
schedule: {
481+
kind: "cron",
482+
expr: "30 10,20 * * *",
483+
tz: "Europe/Madrid",
484+
},
485+
sessionTarget: "isolated",
486+
payload: {
487+
kind: "agentTurn",
488+
message: "Holiday check-in: how’s everything going? Anything you need help with today?",
489+
},
490+
enabled: true,
491+
},
492+
});
493+
});
468494
});

‎src/agents/embedded-agent-runner/run/attempt.tool-call-argument-repair.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,66 @@ const TOOLCALL_REPAIR_RESPONSES_APIS = new Set([
2828
const TOOLCALL_REPAIR_SMART_QUOTES = new Set(["\u201c", "\u201d", "\u201e", "\u201f"]);
2929
const MAX_TOOLCALL_REPAIR_MEMBER_KEY_CHARS = 96;
3030
const TOOLCALL_REPAIR_KNOWN_ARG_KEYS = new Set([
31+
"action",
32+
"allowUnsafeExternalContent",
33+
"anchorMs",
3134
"args",
35+
"at",
3236
"backupDir",
3337
"cmd",
3438
"command",
3539
"content",
40+
"cron",
3641
"cwd",
42+
"description",
3743
"edits",
44+
"enabled",
45+
"every",
46+
"everyMs",
47+
"exact",
48+
"expr",
49+
"fallbacks",
3850
"file",
3951
"file_path",
4052
"filePath",
4153
"filepath",
4254
"from",
55+
"job",
56+
"jobId",
57+
"kind",
4358
"line_end",
4459
"line_start",
4560
"lines",
61+
"lightContext",
4662
"message",
63+
"model",
64+
"name",
4765
"new_str",
4866
"new_string",
4967
"newText",
5068
"old_str",
5169
"old_string",
5270
"oldText",
5371
"path",
72+
"patch",
5473
"paths",
74+
"payload",
5575
"pattern",
5676
"query",
5777
"replacement",
78+
"runMode",
79+
"schedule",
80+
"sessionTarget",
81+
"stagger",
82+
"staggerMs",
5883
"text",
84+
"thinking",
5985
"timeoutMs",
86+
"timeoutSeconds",
6087
"title",
6188
"to",
89+
"toolsAllow",
90+
"tz",
6291
"url",
6392
"urls",
6493
"workdir",
@@ -423,6 +452,12 @@ function readObjectValue(
423452
if (key === "edits" && char === "[") {
424453
return readSmartQuotedEditArray(raw, startIndex);
425454
}
455+
if (char === "{") {
456+
const obj = parseSmartQuotedToolCallObject(raw, startIndex, toolName);
457+
if (obj) {
458+
return { value: obj.args, endIndex: obj.endIndex };
459+
}
460+
}
426461
return readJsonValue(raw, startIndex);
427462
}
428463

0 commit comments

Comments
 (0)