Skip to content

fix(cron): trim whitespace-padded keys in job canonicalization - #95424

Closed
zhangqueping wants to merge 2 commits into
openclaw:mainfrom
zhangqueping:fix/issue-95407
Closed

zhangqueping wants to merge 2 commits into
openclaw:mainfrom
zhangqueping:fix/issue-95407

Conversation

@zhangqueping

@zhangqueping zhangqueping commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix whitespace-padded key name corruption in the cron tool canonicalization layer. When local LLM parsers (observed with qwen35b via llamacpp) emit JSON with trailing-space key names like "schedule " instead of "schedule", the canonicalizer now trims them before downstream repair and gateway validation. The gateway uses strict additionalProperties: false schemas, so the unpadded keys were rejected with schema validation errors.

Fixes #95407

Real behavior proof (required for external PRs)

Behavior addressed: Cron tool add action receives job parameters with trailing-space key names ("schedule ", "sessionTarget ", "payload ", "enabled ") from certain local LLM parsers, causing gateway schema validation to reject the call with unexpected property errors.

Real setup tested:

  • Runtime: Node 22.19, Linux
  • Code analysis path: See root cause analysis below
  • Test framework: Vitest

Root cause: Local model tool-call parsers (qwen35b via llamacpp) emit JSON with whitespace-padded key names. The existing repairConcatenatedCronToolKeys only handled concatenated-key variants (namePayload, scheduleKind, sessionTargetName) but not whitespace-padded canonical keys. The gateway CronAddParamsSchema requires exact key names with additionalProperties: false, so unpadded keys fail validation.

Exact steps or command run after this patch:

OPENCLAW_VITEST_MAX_WORKERS=1 pnpm vitest run \
  src/agents/tools/cron-tool-canonicalize.test.ts \
  --config test/vitest/vitest.agents.config.ts

After-fix evidence:

✓ canonicalizeCronToolObject whitespace-padded keys (#95407)
  ✓ trims trailing-space keys like 'schedule ' -> 'schedule'
  ✓ trims leading-space keys
  ✓ passes through already-clean keys unchanged
  ✓ handles mixed clean and whitespace-padded keys together
  ✓ wrapping via job property also trims keys
Test Files  1 passed (1)
     Tests  5 passed (5)

Observed result after the fix: All whitespace-padded keys are trimmed to canonical form before repair and gateway dispatch. The cron tool add action now succeeds with the exact input from the issue report. Existing cron tool tests (130 tests) continue to pass without regression.

What was not tested: Live end-to-end with qwen35b/llamacpp instance. The source-level fix is verified through unit tests that simulate the exact malformed input shape. The LLM serialization path itself is not directly testable in this environment.

Tests and validation

Test Type Result Details
Unit Tests ✅ 5 new tests for whitespace trimming + 130 existing cron tests pass
Type Check ✅ tsgo -p tsconfig.core.json clean
Lint ✅ oxlint clean on changed file

Risk checklist

Did user-visible behavior change? No - Cron jobs that were being rejected now succeed. No observable change for already-working cron job creation paths (clean JSON keys pass through unchanged).

Did config, environment, or migration behavior change? No

Did security, auth, secrets, network, or tool execution behavior change? No

Current review state

What is the next action? Maintainer review requested

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

clawsweeper Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close: this branch is superseded by a safer open sibling for the same cron whitespace-key bug, and its current helper rewrites arbitrary model-supplied keys before strict validation.

Root-cause cluster
Relationship: superseded
Canonical: #95421
Summary: This PR is a candidate fix for the same cron whitespace-key bug but is superseded by a safer open sibling landing path.

Members:

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

Canonical path: Live PR data for #95421 shows an open, mergeable, proof-sufficient sibling that targets the same issue with recognized-cron-key-only recovery and duplicate preservation.

So I’m closing this here and keeping the remaining discussion on #95421.

Review details

Best possible solution:

Land one cron-scoped fix that normalizes only recognized padded cron keys, preserves duplicate conflicts for strict gateway rejection, and then close the remaining sibling PRs.

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 CronAddParamsSchema validation rejects unexpected properties.

Is this the best way to solve the issue?

No. The cron canonicalizer is the right boundary, but this branch is not the best implementation while an open proof-positive sibling uses narrower recognized-key recovery and preserves duplicate conflicts.

Security review:

Security review needs attention: The diff introduces security-sensitive arbitrary key normalization before strict cron schema validation.

  • [medium] Arbitrary key rewrite before validation — src/agents/tools/cron-tool-canonicalize.ts:115
    The PR trims all model-supplied keys and assigns the trimmed names back before strict gateway validation, so unknown or conflicting padded keys can be transformed instead of remaining rejectable.
    Confidence: 0.9

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root AGENTS.md and scoped src/agents plus src/agents/tools policies were read and applied; they require full code-path, sibling, proof, best-fix, and security-sensitive review for model-supplied key normalization. (AGENTS.md:1, 675c56692ae2)
  • Current main lacks whitespace-key recovery: Current main unwraps and copies cron job params, then runs concatenated-key and schedule/payload canonicalization without trimming whitespace-padded keys. (src/agents/tools/cron-tool-canonicalize.ts:247, 675c56692ae2)
  • Cron add caller boundary: The cron add action calls canonicalizeCronToolObject before normalizing and dispatching cron.add to the gateway, so the canonicalizer is the relevant repair boundary. (src/agents/tools/cron-tool.ts:937, 675c56692ae2)
  • Strict gateway schema: CronAddParamsSchema requires exact cron field names and uses additionalProperties: false, matching the reported unexpected padded-key validation failure. (packages/gateway-protocol/src/schema/cron.ts:478, 675c56692ae2)
  • Latest release still affected: The latest release tag v2026.6.9 has the same exact-key and concatenated-key recovery but no whitespace-key repair, so the bug remains real even though this PR is not the best branch to land. (src/agents/tools/cron-tool-canonicalize.ts:247, c645ec4555c0)
  • Current PR unsafe shape: The PR helper trims every key in the copied object and writes the trimmed names back, so unknown padded keys and duplicate canonical-plus-padded conflicts can be transformed before strict validation. (src/agents/tools/cron-tool-canonicalize.ts:115, 17df2564ed43)

Likely related people:

  • vincentkoc: Current-main blame for the cron recoverable key set, concatenated-key repair, canonicalizeCronToolObject, and cron add path points to Vincent Koc's 29033e6 commit. (role: current source carrier and recent area contributor; confidence: high; commits: 29033e67af45, c645ec4555c0; files: src/agents/tools/cron-tool-canonicalize.ts, src/agents/tools/cron-tool.ts, src/agents/tools/cron-tool.test.ts)
  • steipete: Git history shows Peter Steinberger authored the earlier concatenated cron key recovery and related cron flat-recovery refactors in the same canonicalization boundary. (role: recent related repair and refactor author; confidence: high; commits: 810ef28557ed, efda761724fb, 13c2f22240e4; files: src/agents/tools/cron-tool-canonicalize.ts, src/agents/tools/cron-tool.ts, src/agents/tools/cron-tool.test.ts)
  • tyler6204: The earlier flat-parameter recovery for LLMs omitting the job wrapper was introduced in adjacent cron tool code by Tyler Yust. (role: earlier cron recovery contributor; confidence: medium; commits: 07375a65d898; files: src/agents/tools/cron-tool.ts, src/agents/tools/cron-tool.test.ts, src/cron/schedule.ts)

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

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 20, 2026
- Local LLM parsers (qwen35b/llamacpp) can emit JSON with trailing-space key names
- Add trimWhitespacePaddedCronKeys to strip whitespace before repair/canonicalization
- Gateway schemas use strict additionalProperties:false so unpadded keys are rejected

Fixes openclaw#95407
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jun 21, 2026
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 21, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 21, 2026
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 21, 2026
@clawsweeper clawsweeper Bot added status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 🛠️ actively grinding The PR author has acted after the latest ClawSweeper review and work remains. labels Jun 21, 2026
@zhangqueping

Copy link
Copy Markdown
Contributor Author

Closing — no longer needed.

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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