Skip to content

[Bug]: cron.add tool call always fails with empty/invalid job object — works via CLI #9283

@Displayer226

Description

@Displayer226

Bug: cron.add tool call systematically fails due to schema mismatch & infinite retry loop

Summary

What went wrong?
The cron.add tool call fails systematically due to a schema mismatch between the LLM's perception (the tool definition) and the Gateway's internal validator. The LLM (e.g., Qwen 3 Coder) attempts to send a nested job: { ... } object, but the Gateway validator rejects it, explicitly requiring properties (name, schedule, sessionTarget, payload) at the top level. Additionally, the Gateway/Agent fails to handle the INVALID_REQUEST error as a fatal exception, causing the agent to enter an infinite retry loop, which results in a continuous stream of validation errors in the logs.

Steps to reproduce

  1. Start OpenClaw Gateway (v2026.2.2-3) from a local npm build.
  2. Use an LLM agent and ask it to: "Create a cron job named 'test' to run 'echo hello' every day at 5am".
  3. Observe the Gateway logs: the tool call is sent with a nested job object as per the LLM's system instructions/tool schema.
  4. The Gateway returns errorCode=INVALID_REQUEST with the message: must have required property 'name'; ....
  5. The agent retries the call immediately, looping indefinitely every ~3 seconds with the same payload.

Expected behavior

  • The cron.add tool call should succeed when provided with valid parameters, aligning with the flat structure used by the CLI:
    openclaw cron add --name "test" --cron "0 5 * * *" --session main --system-event "echo hello"
  • The tool definition (JSON Schema) provided to the LLM should be synchronized with the Gateway's internal validator (either both should be nested or both should be flat).
  • The agent should stop and report a fatal error upon receiving an INVALID_REQUEST (validation error) instead of retrying the same invalid payload.

Actual behavior

The tool call is rejected by the validator because it expects root-level properties instead of a nested job object. This triggers an infinite loop of failed tool calls, flooding the logs and preventing the task from ever finishing.

Environment

  • OpenClaw version: 2026.2.2-3 (9c5941b)
  • Node version: v25.5.0
  • OS: Linux 6.8.0-94-generic (x64) / Ubuntu 24.04
  • Install method: Local build / npm
  • Model used: Local GPU / QWEN 3 CODER NEXT Q4_KXL

Logs or screenshots

02:18:03 info gateway/ws ⇄ res ✗ cron.add 0ms errorCode=INVALID_REQUEST errorMessage=invalid cron.add params: must have required property 'name'; must have required property 'schedule'; must have required property 'sessionTarget'; must have required property 'payload' conn=0021d9e7…2bd1 id=33fff351…dab1
02:18:03 error [tools] cron failed: invalid cron.add params: must have required property 'name'; must have required property 'schedule'; must have required property 'sessionTarget'; must have required property 'payload'
02:18:06 debug agent/embedded embedded run tool start: tool=cron
02:18:06 info gateway/ws ⇄ res ✗ cron.add 0ms errorCode=INVALID_REQUEST ...

Diagnosis

  • The CLI openclaw cron add works with flat flags (--name, --cron, --session, --system-event).
  • The tool call schema (as received by the LLM) expects nested job: { ... }.
  • The Gateway validator expects flat top-level fields (name, schedule, sessionTarget, payload).
  • The agent retries validation failures, causing the infinite loop.

Suggested Fix

  1. Align tool schema with validator
    Update the cron.add tool definition to match the Gateway's internal validator — use flat, top-level fields (name, schedule, sessionTarget, payload) instead of nested job: { ... }.

  2. Prevent infinite retry on INVALID_REQUEST
    Modify the agent to treat INVALID_REQUEST errors as terminal (no retry), since they indicate a user/tool mistake rather than a transient failure.

  3. Improve error messages
    When validation fails, return a working CLI equivalent in the error response so users can work around the issue:

    Example usage:
    openclaw cron add --name "test" --cron "0 5 * * *" --session main --system-event "echo hello"
    
  4. Add tool call test suite
    Include a test for cron.add to ensure the tool schema and Gateway validator stay in sync during future changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions