#2071: fix: accept JSON string for cron.add job parameter (#1940)
agents
Cluster:
Swarm Bug Fixes and Feature Requests
gh pr create --title "fix: accept JSON string for cron.add job parameter (#1940)" --body "
## Summary
- Parse job parameter as JSON string when passed as string instead of object
- Fixes inconsistent 'must be object' error when AI tools pass job as JSON string
## Testing
- Added test: accepts cron.add job payloads as JSON strings
- All 16 cron-tool tests pass
- pnpm lint ✅
- pnpm build ✅
## AI/Vibe-Coded PR 🤖
- [x] Mark as AI-assisted in the PR title or description
- [x] Note the degree of testing: **fully tested locally**
- [x] Include prompts or session logs if possible: available on request
- [x] Confirm you understand what the code does
### AI Tools Used
- Claude Opus-4.5
- Cursor IDE
- Manual review performed
Fixes #1940"
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR makes the `cron` agent tool more tolerant of AI/client callers by accepting `job` as a JSON-encoded string for the `cron.add` action. The implementation parses `job` when it’s a string, validates it is a plain object (not null/array), then continues through existing normalization (`normalizeCronJobCreate`) and defaulting behavior before calling the gateway.
A new Vitest case covers passing `job` as a JSON string and asserts the tool still emits the same normalized `cron.add` request payload as when an object is provided.
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge; changes are localized and covered by a new test.
- The change only affects the `cron.add` branch by adding a small JSON-parse path and a stricter plain-object guard, with a new unit test validating the intended behavior. Main remaining risk is minor: the tool schema still advertises `job` as an object, so some tool runtimes may reject string input before it reaches this runtime parsing path.
- src/agents/tools/cron-tool.ts
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#9430: fix: accept flat params for cron.add tool action
by dbottme · 2026-02-05
81.1%
#8701: fix: default enabled to true for cron jobs created via tool API
by maximus-claw · 2026-02-04
80.7%
#8811: fix(cron): handle atMs fallback for kind=at jobs
by hlibr · 2026-02-04
79.0%
#8698: fix(cron): default enabled to true for new jobs
by emmick4 · 2026-02-04
78.9%
#18743: Cron Tool Hardening: Normalize Gateway Params and Enforce Valid Sch...
by cccat6 · 2026-02-17
78.8%
#9670: fix: handle numeric string timestamps in cron schedule normalizatio...
by divol89 · 2026-02-05
78.8%
#20559: Feature/cron tool control
by loeclos · 2026-02-19
78.4%
#5624: add support_human_readable_time_format in cron
by simran122 · 2026-01-31
77.8%
#8307: fix(cron): improve tool description with reliable reminder guidance
by vishaltandale00 · 2026-02-03
77.8%
#9467: Cron: support flat params in cron.add tool call
by M00N7682 · 2026-02-05
77.6%