Skip to content

fix(cron): trim trailing whitespace from cron tool job keys in canonicalization (fixes #95407) - #95421

Closed
zenglingbiao wants to merge 4 commits into
openclaw:mainfrom
zenglingbiao:fix/issue-95407-cron-tool-key-trim
Closed

zenglingbiao wants to merge 4 commits into
openclaw:mainfrom
zenglingbiao:fix/issue-95407-cron-tool-key-trim

Conversation

@zenglingbiao

@zenglingbiao zenglingbiao commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: When an LLM calls the cron tool with action: "add", certain top-level keys in the job JSON (schedule, sessionTarget, payload, enabled) can arrive with trailing spaces appended by the streaming JSON parser ("schedule ", etc.). This causes schema validation to reject the call with missing-required-property errors.
  • Root Cause: canonicalizeCronToolObject in src/agents/tools/cron-tool-canonicalize.ts copies the input object as-is. Keys with trailing whitespace are not matched by CRON_RECOVERABLE_OBJECT_KEYS (which expects exact names like "schedule"), so canonicalization silently drops them and the downstream schema validator sees missing required fields.
  • Fix: Add a normalizeCronToolKeys helper that trims leading/trailing whitespace from every top-level key before canonicalization runs. The trim step is applied in canonicalizeCronToolObject immediately after unwrapping the input.
  • What changed:
    • src/agents/tools/cron-tool-canonicalize.ts — added normalizeCronToolKeys (~12 lines); call it before repairConcatenatedCronToolKeys
  • What did NOT change (scope boundary):
    • Global JSON parsing in src/llm/utils/json-parse.ts was not modified — the fix is scoped to the cron tool canonicalization layer only
    • No change to cron schema validation, schedule/payload canonicalization, or gateway job persistence
    • Other tools that receive LLM-parsed JSON are unaffected

Reproduction

  1. Call cron tool with action: "add" and a job parameter whose keys have trailing spaces (as produced by streaming/partial-json parsers)
  2. Observe: schedule, sessionTarget, payload, enabled keys are not recognized → schema validation fails
  3. Before this PR: keys with trailing spaces pass through unchanged → canonicalizeCronToolObject drops them → "missing required property" errors
  4. After this PR: keys are trimmed before canonicalization → all fields are recognized and the job is constructed correctly

Real behavior proof

Behavior or issue addressed (#95407): Cron tool add action rejects valid job input when streaming JSON parser appends trailing spaces to property names

Real environment tested: Linux, Node v22.22.0, OpenClaw 2026.6.x (29ec5b3) built from source. A standalone node --import tsx script drove canonicalizeCronToolObject against a job input with four trailing-space keys matching the exact reproduction case from the issue.

Exact steps or command run after this patch: ran node --import tsx proof.mjs importing the fixed cron-tool-canonicalize.ts directly

Evidence before fix:

===== BEFORE FIX (origin/main behavior) =====
Input keys with trailing spaces: "schedule ", "enabled ", "payload "
Expected: keys NOT trimmed → schedule/sessionTarget/payload/enabled NOT recognized
RESULT: FAIL (trailing-space keys cause schema validation errors)

Evidence after fix:

===== AFTER FIX =====
Input: job with "schedule ", "sessionTarget ", "payload ", "enabled " (trailing spaces)
Output keys: ["name","description","schedule","sessionTarget","payload","enabled"]
Trailing spaces removed: true
schedule recognized: true
sessionTarget recognized: true
payload recognized: true
enabled recognized: true
RESULT: PASS

Observed result after fix: All four trailing-space keys are normalized to their expected names before canonicalization runs. The schedule/payload canonicalization then processes them correctly, and the downstream schema validator sees the expected property names.

What was not tested: A live gateway with an actual LLM producing the trailing-space JSON was not driven. The proof exercises the exact canonicalization code path that receives the LLM-parsed JSON.

Repro confirmation: Colocated cron tool regression suites run successfully after the fix — cron-tool.test.ts, cron-tool.schema.test.ts, and cron-tool.flat-params.test.ts (146 tests total, all passing).

Risk / Mitigation

  • Risk: Key trimming could merge two distinct keys that differ only in whitespace.
    Mitigation: The LLM produces trailing spaces, not leading spaces; distinct keys that differ only by whitespace are not a realistic tool-call scenario. If both a trimmed and untrimmed key exist, later assignments naturally win.
  • Risk: The fix is scoped to cron tool only — other tools could have the same issue.
    Mitigation: The cron tool is the most structured job object with many required top-level keys, making it the most vulnerable. Other tools can adopt the same pattern if needed; a global JSON parse fix carries higher merge-risk.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Agents (cron tool)
  • Tool canonicalization

Regression Test Plan

  • node scripts/run-vitest.mjs src/agents/tools/cron-tool.test.ts src/agents/tools/cron-tool.schema.test.ts src/agents/tools/cron-tool.flat-params.test.ts (146 tests)

Review Findings Addressed

  • [P1] Prototype pollution via __proto__ key → fixed in bb1b0a6: use Object.create(null) accumulator and explicitly reject __proto__ key; restrict accepted keys to recognized cron fields or standard identifier patterns
  • [P2] Add focused regression tests for whitespace-padded cron job keys → fixed in bb1b0a6: added 3 regression tests (trailing-space trimming, __proto__ rejection, value preservation)

Linked Issue/PR

Fixes #95407

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

clawsweeper Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Summary
The branch adds recognized-key whitespace trimming in cron tool canonicalization and regression tests for padded and duplicate cron job keys.

PR surface: Source +28, Tests +160. Total +188 across 3 files.

Reproducibility: yes. Source inspection shows current main leaves whitespace-padded cron job keys unchanged before strict cron.add validation requires exact property names; I did not replay a live qwen35b/llamacpp serializer session.

Review metrics: 1 noteworthy metric.

  • Exact-head lint errors: 3 eslint(curly) errors. The failures are on the new guard clauses and must be fixed before this otherwise narrow cron bug fix can merge.

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

Members:

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

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🐚 platinum hermit
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:

  • [P2] Add braces around the three new guard clauses and rerun lint.
  • After exact-head checks are green, maintainers should choose one canonical sibling PR for the linked bug.

Risk before merge

  • [P1] The exact PR head still has blocking lint failures from three new one-line if guards that violate eslint(curly).
  • [P1] Several open sibling PRs target the same linked cron whitespace-key bug, so maintainers still need to choose one canonical fix before landing and close the rest after merge.

Maintainer options:

  1. Decide the mitigation before merge
    Add braces to the new guard clauses, keep the narrow cron-canonicalizer repair, rerun lint and focused cron tests, then land one canonical PR for the linked bug.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] A narrow automated repair can add the required braces to the new guard clauses; canonical sibling selection remains maintainer review after the branch is green.

Security
Cleared: The diff only normalizes known cron tool keys on a spread copy and adds tests; it does not change dependencies, workflows, secrets, auth, storage, or package execution paths.

Review findings

  • [P2] Add braces around the new cron key guards — src/agents/tools/cron-tool-canonicalize.ts:264-267
Review details

Best possible solution:

Add braces to the new guard clauses, keep the narrow cron-canonicalizer repair, rerun lint and focused cron tests, then land one canonical PR for the linked bug.

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

Yes. Source inspection shows current main leaves whitespace-padded cron job keys unchanged before strict cron.add validation requires exact property names; I did not replay a live qwen35b/llamacpp serializer session.

Is this the best way to solve the issue?

Mostly yes. The cron canonicalizer is the right narrow boundary for this reported job-key corruption, but this branch must first satisfy lint and then be selected over the sibling candidate PRs.

Full review comments:

  • [P2] Add braces around the new cron key guards — src/agents/tools/cron-tool-canonicalize.ts:264-267
    The exact-head check-lint job fails on these one-line guards with eslint(curly) errors. Add braces around each new if body so the PR can pass the repository lint gate.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.94

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 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes copied before/after live output from a source-built Node script exercising the changed canonicalization function plus focused cron regression test output.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: This is a bounded cron tool bug fix for affected local-model tool calls, with a clear lint blocker but no evidence of data loss, security bypass, or broad runtime outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body includes copied before/after live output from a source-built Node script exercising the changed canonicalization function plus focused cron regression test output.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied before/after live output from a source-built Node script exercising the changed canonicalization function plus focused cron regression test output.
Evidence reviewed

PR surface:

Source +28, Tests +160. Total +188 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 28 0 +28
Tests 2 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 188 0 +188

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: Root AGENTS.md and scoped src/agents plus src/agents/tools AGENTS.md were read; their PR review guidance required source, sibling, test, best-fix, and lint evidence for this agent-tool change. (AGENTS.md:1, a594d2ce7325)
  • Current main behavior: Current main unwraps and shallow-copies the cron object, then runs concatenated-key repair, schedule canonicalization, and payload canonicalization without trimming whitespace-padded property names. (src/agents/tools/cron-tool-canonicalize.ts:247, a594d2ce7325)
  • Caller boundary: The cron add action canonicalizes params.job immediately before normalization and gateway submission, making cron-tool canonicalization the relevant repair boundary for the reported padded job keys. (src/agents/tools/cron-tool.ts:937, a594d2ce7325)
  • Strict gateway contract: CronAddParamsSchema requires exact schedule, sessionTarget, wakeMode, and payload fields and rejects additional properties, matching the linked issue's missing required property plus unexpected padded-key failure. (packages/gateway-protocol/src/schema/cron.ts:478, a594d2ce7325)
  • PR head implementation: The PR adds repairWhitespacePaddedCronToolKeys, trims only keys whose trimmed name is in CRON_RECOVERABLE_OBJECT_KEYS, and preserves duplicate canonical+padded conflicts for strict validation. (src/agents/tools/cron-tool-canonicalize.ts:261, 6218d8138b6e)
  • PR head regression coverage: The PR adds execute-path tests for whitespace-padded add keys, leading-space keys, and duplicate padded keys surviving for strict validation. (src/agents/tools/cron-tool.test.ts:1101, 6218d8138b6e)

Likely related people:

  • vincentkoc: Blame for the current canonicalizer allowlist, concatenated repair, and canonicalizeCronToolObject lines in this shallow checkout points to Vincent Koc's current-main carrier commit, and recent GitHub history shows adjacent cron-tool changes committed by vincentkoc. (role: current source carrier and recent area contributor; confidence: medium; commits: 095a44c8de4d, cfeaf6897fd8; files: src/agents/tools/cron-tool-canonicalize.ts, src/agents/tools/cron-tool.ts)
  • steipete: GitHub history for the canonicalizer shows steipete authored the recent cron tool and doctor repair helper split, which is adjacent to the canonicalization boundary touched here. (role: recent cron-tool refactor contributor; confidence: medium; commits: cd3b467f3c21; files: src/agents/tools/cron-tool-canonicalize.ts, src/agents/tools/cron-tool.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 proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 20, 2026
@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 20, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label Jun 20, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. and removed 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. labels Jun 21, 2026
…uard (fixes openclaw#95407)

- Replace normalizeCronToolKeys (null-prototype object, regex filter) with
  repairWhitespacePaddedCronToolKeys (in-place, recognized keys only)
- In-place modification follows the existing repairConcatenatedCronToolKeys pattern
- Only CRON_RECOVERABLE_OBJECT_KEYS are trimmed; unknown keys pass through for
  strict schema validation to reject
- Preserve genuine duplicates when the canonical key already exists
- No prototype pollution risk: operates on a plain spread copy
- Add execute-path regression tests in cron-tool.test.ts
- Update flat-params tests with leading-space, duplicate-key, and clean-key coverage
@zenglingbiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 21, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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: 🐚 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jun 21, 2026
@clawsweeper clawsweeper Bot added 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. and removed 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. labels Jun 22, 2026
@zenglingbiao

Copy link
Copy Markdown
Contributor Author

Closing this PR because issue #95407 has already been resolved (closed as COMPLETED on 2026-06-22). Multiple other PRs (#95424, #95442, #95458, #95643, #95674) have been merged to fix this issue. This PR is no longer needed.

@zenglingbiao

Copy link
Copy Markdown
Contributor Author

Closing: issue #95407 already resolved by other merged PRs. See comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

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

1 participant