Skip to content

# Bug Report — Scheduled automation runs fail with API 400 ("tool" role error) #655

Description

@Arjunan323

Reporter: Meesho supplier automation user (chat 1503962408)
Date: 2026-09-10 (IST)
Severity: High — scheduled runs fail silently; platform reports them as OK
Status: Recurring (2 consecutive scheduled runs, 2 different tasks)


Error (exact)

Error code: 400 - {'error': {'message': "Messages with role 'tool' must be a response to a preceding message with 'tool_calls'", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}

What happens

A scheduled (cron) task run starts, then aborts mid-execution with the error above.
The run produces no output artifacts (no report file, no Telegram message), yet the
task's last_status is recorded as "ok" and run_count increments — so there is no
visible failure signal other than the missing outputs.

Recurrence — both affected runs

# Task Schedule First run? When (IST) Result
1 Meesho daily pending-orders accept daily 23:00 No (had run ok before manually-created) 2026-09-09 23:00 400 error, no outputs
2 Meesho Label Download — Every 4 Hours 0 */4 * * * Yes — task created ~25 min earlier, never ran before 2026-09-10 00:00 400 error, no outputs

Key observation: run #2 was the first ever run of a brand-new task — so the failure is
not caused by long-running state, accumulated context, or the task's instructions.

What works

Interactive (chat) sessions running the same steps against the same website complete
successfully every time (same tools: browser automation via Puppeteer MCP, file writes,
send_message). The failure is specific to the scheduled-run execution path.

Hypothesis for the platform team

The scheduled-run engine compacts/rewrites the agent's message history mid-run; afterwards a
tool role message remains that no longer follows a matching tool_calls message, and the
model API rejects the request with this 400. Additionally, the runner does not propagate
this failure into last_status (reports "ok" instead of an error).

Requested fix

  1. Prevent tool-role messages from surviving context compaction without their tool_calls
    parent (drop or re-pair them before sending to the API).
  2. Record genuinely failed runs as failed (last_status error) so users/alerts can detect
    missed runs instead of discovering them from missing outputs.

Current state (so support can triage)

  • Tasks affected: task-272f869009 (Label Download — Every 4 Hours), task-ac6a7c2f06
    (Meesho daily pending-orders accept)
  • Both schedules remain enabled and will keep failing until the runner is fixed.
  • Business impact so far: 2 missed runs, recovered manually (~2 min each); no orders lost.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions