Skip to content

fix #95407: [Bug]: cron tool add action mangles certain key names in job parameter - #95453

Closed
mikasa0818 wants to merge 3 commits into
openclaw:mainfrom
mikasa0818:feat/issue-95407
Closed

mikasa0818 wants to merge 3 commits into
openclaw:mainfrom
mikasa0818:feat/issue-95407

Conversation

@mikasa0818

@mikasa0818 mikasa0818 commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #95407.

  • Behavior or issue addressed: cron.add rejected local parser outputs where recognized top-level job keys had trailing spaces, such as schedule , sessionTarget , payload , and enabled .
  • Why it matters / User impact: affected local-model users could not create cron jobs through the function-call interface even though the generated job shape was otherwise valid.

Summary

Recover whitespace-padded top-level cron job keys before cron.add gateway validation. This keeps the gateway schema strict while allowing the cron tool's existing model-friendly canonicalization seam to repair a concrete parser corruption shape.

The update also preserves ambiguous duplicate input when both a canonical key and its whitespace-padded duplicate are present. In that case the padded duplicate remains on the normalized object so strict CronAddParamsSchema validation rejects the extra property instead of silently choosing one value.

For flat cron.add inputs, recovered synthetic jobs/patches are not canonicalized a second time. This keeps moved flat shorthand conflicts such as cron + cron and allowUnsafeExternalContent + allowUnsafeExternalContent visible to final strict validation instead of re-recovering the padded shorthand and overwriting nested schedule or payload values.

Root Cause

  • Root cause: canonicalizeCronToolObject only recovered the earlier concatenated-key corruption shape (namePayload, scheduleKind, sessionTargetName). It copied whitespace-padded keys as-is, so strict gateway validation saw missing canonical fields plus unexpected padded fields.
  • Follow-up root cause from review: the first recovery pass deleted a whitespace-padded key even when the canonical key already existed, which could hide ambiguous/conflicting input from strict gateway validation.
  • Second follow-up root cause from review: flat synthetic job recovery was already canonicalized once, but the cron.add path canonicalized the synthetic job again. For flat shorthands moved into schedule or payload, that second pass could recover the remaining padded shorthand and overwrite the nested canonical value before strict validation saw the duplicate.
  • Why this is root-cause fix: the cron tool canonicalizer is the existing boundary that normalizes model/parser-shaped cron arguments immediately before gateway dispatch. Normalizing only known cron field names there repairs the corrupted parser output before validation without widening the gateway protocol contract; preserving duplicate conflicts and avoiding double canonicalization for recovered flat objects keeps the gateway schema as the final source-of-truth rejector for ambiguous input.

Why This Change Was Made

The gateway schema is the source of truth and should continue rejecting unknown fields. This patch trims only property names whose trimmed form is already a known cron job/patch/recovery field; unsupported fields remain unsupported. Flat cron parameter recovery uses the same known-key normalization so flat and nested job inputs handle this whitespace-padded key shape consistently. If a parser supplies both enabled and enabled , or both a flat shorthand such as cron and cron / allowUnsafeExternalContent and allowUnsafeExternalContent , the padded duplicate is not discarded or re-applied; strict validation rejects the extra property.

Real behavior proof

  • Real environment tested: local source checkout on Windows Git Bash; Node v22.17.0; pnpm 11.2.2. pnpm emitted the repo engine warning because the repo requests Node >=22.19.0.
  • Exact steps or command run after this patch:
    • pnpm exec oxfmt --check --threads=1 src/agents/tools/cron-tool.ts src/agents/tools/cron-tool-canonicalize.ts src/agents/tools/cron-tool.test.ts
    • node scripts/run-vitest.mjs src/agents/tools/cron-tool.test.ts src/agents/tools/cron-tool.flat-params.test.ts
    • pnpm test src/agents/tools/cron-tool.test.ts src/agents/tools/cron-tool.flat-params.test.ts
    • git diff --check
    • pnpm exec tsx --input-type=module with production canonicalizeCronToolObject, recoverCronObjectFromFlatParams, normalizeCronJobCreate, createCronTool, and gateway protocol CronAddParamsSchema against padded-only, duplicate/conflicting padded-key, and flat shorthand duplicate cron add shapes.
  • Evidence after fix: the focused regression tests exercise both job and flat cron.add inputs with padded top-level cron keys; nested and flat duplicate enabled inputs; a flat schedule shorthand duplicate (cron + cron ); and a flat security-sensitive payload shorthand duplicate (allowUnsafeExternalContent + allowUnsafeExternalContent ). The strict schema proof produced canonical keys and schema.accepted: true for padded-only input. For duplicate nested and flat inputs it preserved the canonical value, kept the padded duplicate as an additional top-level property, and CronAddParamsSchema rejected the payload with the expected additionalProperties entry.
  • Observed result after fix: reported padded-only keys are canonicalized before strict cron add validation, while conflicting canonical+padded duplicates remain visible to strict validation and are rejected. Flat shorthand conflicts no longer get re-recovered on a second canonicalization pass.
  • What was not tested: I did not run a live qwen35b/llamacpp provider route; proof is source-level regression coverage plus production canonicalizer/normalizer/cron-tool/schema-validator output.

Evidence

  • Formatting check passed for all touched files.
  • node scripts/run-vitest.mjs src/agents/tools/cron-tool.test.ts src/agents/tools/cron-tool.flat-params.test.ts passed.
  • pnpm test src/agents/tools/cron-tool.test.ts src/agents/tools/cron-tool.flat-params.test.ts passed: 136 tests passed across 2 files.
  • Strict schema-validator proof passed outside Vitest mocks for the accepted padded-only path and the rejected duplicate nested/flat paths, including flat schedule shorthand and flat security-sensitive payload shorthand conflicts captured through createCronTool dispatch.
  • git diff --check passed.

Regression Test Plan

  • Target test file: src/agents/tools/cron-tool.test.ts.
  • The new tests cover cron.add with a job object whose top-level schedule , sessionTarget , payload , and enabled keys have trailing spaces.
  • The same table also covers flat cron.add input with those whitespace-padded fields recovered into a job before dispatch.
  • Duplicate/conflict regression coverage checks both nested job and flat cron.add inputs containing enabled plus enabled , and asserts strict CronAddParamsSchema rejects the outgoing cron.add params because the padded duplicate remains an additional property.
  • Flat shorthand duplicate coverage checks cron plus cron and allowUnsafeExternalContent plus allowUnsafeExternalContent so moved schedule and payload fields cannot be overwritten by a second canonicalization pass.

Review findings addressed

  • RF-001 (status: ⏳ waiting on author): addressed by this update; the PR body documents the author-side flat-shorthand fix, regression coverage, and verification results.
  • RF-002 (schedule and payload/security-sensitive shorthand regression coverage): fixed. src/agents/tools/cron-tool.test.ts covers cron plus cron and allowUnsafeExternalContent plus allowUnsafeExternalContent .
  • RF-003 (flat canonical-plus-padded shorthand conflicts can be re-recovered): fixed. Recovered flat synthetic jobs/patches now skip the second canonicalization pass in the add/update dispatch path, preserving padded shorthand duplicates through final gateway params.
  • RF-004 (allowUnsafeExternalContent security-sensitive overwrite): fixed and covered. Regression and production-path proof preserve payload.allowUnsafeExternalContent: false while keeping top-level allowUnsafeExternalContent : true as an additional property rejected by strict validation.
  • RF-005 (multiple sibling PRs / canonical landing path): maintainer decision. This patch keeps this PR narrowly focused and does not choose among sibling PRs beyond making this branch maintainer-ready.
  • RF-006 (mechanical repair for padded flat shorthand duplicates): fixed via the flat synthetic-job dispatch repair plus focused regression tests; maintainer selection among sibling PRs remains separate.
  • RF-007 (src/agents/tools/cron-tool-canonicalize.ts:309-312 / keep flat shorthand duplicates rejectable): fixed by avoiding duplicate canonicalization of already-recovered flat cron objects before gateway submission.
  • RF-008 (node scripts/run-vitest.mjs src/agents/tools/cron-tool.test.ts src/agents/tools/cron-tool.flat-params.test.ts): passed.
  • RF-009 (pnpm exec oxfmt --check --threads=1 src/agents/tools/cron-tool-canonicalize.ts src/agents/tools/cron-tool.test.ts): passed. I also checked src/agents/tools/cron-tool.ts, which is touched by the final dispatch fix.
  • RF-010 (git diff --check): passed.

Merge risk

  • Risk labels considered: merge-risk:low / no compatibility-expanding protocol change.
  • Risk explanation: the change touches model-facing cron argument canonicalization and flat add/update dispatch, but it does not change the gateway schema, persisted cron data, public protocol fields, or defaults.
  • Why acceptable: recovery is limited to known cron fields. If a parser supplies an actually unknown field, strict validation still rejects it. If a parser supplies conflicting canonical and padded keys, the conflict is preserved for strict validation instead of being silently resolved or re-applied.
  • Fix classification: minimal canonical root-cause fix at the cron tool canonicalization boundary and the flat synthetic-job dispatch seam that previously caused a second canonicalization pass.
  • Maintainer-ready confidence: high for source-level reproduction, strict schema-validator proof, duplicate-conflict regression coverage including flat schedule/payload shorthands, and unchanged gateway schema behavior; live provider proof intentionally not claimed.
  • Patch quality notes: production changes are confined to cron key canonicalization and avoiding duplicate canonicalization of already-recovered flat cron objects, paired with targeted regression tests.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jun 21, 2026
@clawsweeper

clawsweeper Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed June 22, 2026, 12:42 AM ET / 04:42 UTC.

Summary
The PR adds cron-tool canonicalization for whitespace-padded known cron job keys, avoids second canonicalization of recovered flat add/update objects, and adds regression coverage for accepted and duplicate-conflict cron.add inputs.

PR surface: Source +35, Tests +160. Total +195 across 3 files.

Reproducibility: yes. Source inspection shows current main and v2026.6.9 do not recover whitespace-padded cron keys before strict CronAddParamsSchema validation; I did not run the live qwen35b/llamacpp route in this read-only review.

Review metrics: 1 noteworthy metric.

  • Lint blocker: 1 error. The required lint lane fails on a touched line, so this mechanical issue must be fixed before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #95407
Summary: This PR is one candidate fix for the canonical whitespace-padded cron job key bug; sibling PRs attempt the same symptom at either the cron canonicalizer or broader tool-call parsing layers.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Replace Object.prototype.hasOwnProperty.call(params, recoveredKey) with Object.hasOwn(params, recoveredKey).
  • [P2] Rerun the lint lane or equivalent focused lint proof after the mechanical repair.

Risk before merge

  • [P1] The branch currently fails the required lint lane on one touched line, so it needs a mechanical repair before merge.
  • [P1] Several open sibling PRs target the same canonical bug; maintainers should land exactly one implementation path and close superseded candidates after merge.
  • [P1] The proof is production-path source/schema/test output rather than a live qwen35b/llamacpp provider run.

Maintainer options:

  1. Decide the mitigation before merge
    Land one cron-scoped fix that recovers only recognized padded cron keys, preserves duplicate conflicts for strict validation, and passes lint/checks; this branch needs the Object.hasOwn repair first.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] A single mechanical lint repair is clear and safe for an automated PR-branch fix; maintainer selection among duplicate candidate PRs remains separate after that.

Security
Cleared: The diff touches the security-sensitive allowUnsafeExternalContent shorthand only to preserve duplicate conflicts for strict validation, and I found no concrete security or supply-chain regression.

Review findings

  • [P3] Use Object.hasOwn for the flat-key check — src/agents/tools/cron-tool-canonicalize.ts:308
Review details

Best possible solution:

Land one cron-scoped fix that recovers only recognized padded cron keys, preserves duplicate conflicts for strict validation, and passes lint/checks; this branch needs the Object.hasOwn repair first.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows current main and v2026.6.9 do not recover whitespace-padded cron keys before strict CronAddParamsSchema validation; I did not run the live qwen35b/llamacpp route in this read-only review.

Is this the best way to solve the issue?

Yes for the product fix boundary: the cron tool canonicalizer is the narrowest maintainable place because existing malformed cron argument recovery already lives there. The submitted branch still needs the lint repair before it can be considered merge-ready.

Full review comments:

  • [P3] Use Object.hasOwn for the flat-key check — src/agents/tools/cron-tool-canonicalize.ts:308
    The current CI lint lane fails on this added Object.prototype.hasOwnProperty.call() usage because the repo enforces prefer-object-has-own. Use Object.hasOwn(params, recoveredKey) so the branch can pass required lint without changing behavior.
    Confidence: 0.98

Overall correctness: patch is correct
Overall confidence: 0.92

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a594d2ce7325.

Label changes

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded cron tool bug fix for affected local-model tool calls with limited blast radius.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes after-fix terminal commands and production-path canonicalizer, cron-tool, and strict-schema evidence for reported and duplicate inputs; it does not claim a live provider route.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal commands and production-path canonicalizer, cron-tool, and strict-schema evidence for reported and duplicate inputs; it does not claim a live provider route.
Evidence reviewed

PR surface:

Source +35, Tests +160. Total +195 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 41 6 +35
Tests 1 160 0 +160
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 201 6 +195

Acceptance criteria:

  • [P1] pnpm lint --threads=8.
  • [P1] node scripts/run-vitest.mjs src/agents/tools/cron-tool.test.ts src/agents/tools/cron-tool.flat-params.test.ts.

What I checked:

  • Repository policy read: Read root AGENTS.md plus src/agents/AGENTS.md and src/agents/tools/AGENTS.md; the review applied the policy to inspect current main, scoped tool code, sibling tests, related PRs, CI, and history before verdict. (AGENTS.md:1, a594d2ce7325)
  • Current main still lacks the requested recovery: On current main, canonicalizeCronToolObject copies cron job keys, repairs only concatenated key names, and then canonicalizes schedule/payload; there is no whitespace-padded key recovery before strict validation. (src/agents/tools/cron-tool-canonicalize.ts:247, a594d2ce7325)
  • Latest release still lacks the requested recovery: The latest release tag v2026.6.9 has the same concatenated-key-only canonicalizer and cron.add path, so the reported behavior is not already shipped as fixed. (src/agents/tools/cron-tool-canonicalize.ts:247, c645ec4555c0)
  • Strict schema explains the failure mode: CronAddParamsSchema requires exact schedule, sessionTarget, wakeMode, and payload fields and sets additionalProperties to false, matching the reported unexpected padded-key validation failure. (packages/gateway-protocol/src/schema/cron.ts:478, a594d2ce7325)
  • PR recovers only known cron keys: At PR head, recoverCronToolKey maps a padded key only when the trimmed form is already in CRON_RECOVERABLE_OBJECT_KEYS, preserving strict rejection for genuinely unknown fields. (src/agents/tools/cron-tool-canonicalize.ts:88, 52c26d212d8a)
  • PR preserves duplicate flat conflicts: At PR head, recovered flat jobs and patches skip a second canonicalization pass, keeping duplicate padded shorthand fields visible for final strict schema rejection. (src/agents/tools/cron-tool.ts:939, 52c26d212d8a)

Likely related people:

  • vincentkoc: Current-main blame for the recoverable cron key set, canonicalizer, and cron.add flat recovery path points to Vincent Koc, and recent release/main history carries the same code. (role: current source carrier and recent area contributor; confidence: high; commits: 095a44c8de4d, c645ec4555c0; files: src/agents/tools/cron-tool-canonicalize.ts, src/agents/tools/cron-tool.ts, src/agents/tools/cron-tool.test.ts)
  • steipete: Symbol history shows Peter Steinberger authored the shared cron flat-recovery refactor and several adjacent cron/tool refactors that shape the current boundary. (role: recent related refactor author; confidence: high; commits: efda761724fb, fd3ca8a34c72, cc9be84b9c5b; files: src/agents/tools/cron-tool-canonicalize.ts, src/agents/tools/cron-tool.ts, src/agents/tools/cron-tool.test.ts)
  • Tyler Yust: History shows Tyler Yust authored the earlier cron flat-params recovery behavior that this PR extends for padded-key parser output. (role: adjacent flat-params contributor; confidence: medium; commits: 07375a65d898; files: src/agents/tools/cron-tool.ts, src/agents/tools/cron-tool.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 21, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jun 21, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jun 21, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 22, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Thanks @mikasa0818 for the work on this. Clownfish is closing #95453 because the same #95407 cron key repair has now landed in #95674.

The merged fix trims recognized whitespace-padded cron job keys and preserves duplicate padded keys so validation can still reject conflicts. This branch helped validate the same failure mode, and the cleanup record keeps its context as a source PR with credit/attribution alongside the merged fix.

Original issue: #95407. If this branch covers a different reproduction path that still fails on current main, please reply and we can reopen or split it back out.

@vincentkoc vincentkoc closed this Jun 22, 2026
@vincentkoc vincentkoc added the clownfish Tracked by Clownfish automation label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clownfish Tracked by Clownfish automation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: cron tool add action mangles certain key names in job parameter

2 participants