Skip to content

Cron RPC queries timeout during job execution (lock contention) #4210

@stevenn

Description

@stevenn

Summary

Cron RPC queries (cron.list, cron.status) timeout when a job with wakeMode: "now" and sessionTarget: "main" is executing, because executeJob() holds the lock while awaiting runHeartbeatOnce().

Reproduction

  1. Create a cron job with wakeMode: "now" and sessionTarget: "main"
  2. Wait for the job to fire
  3. While the agent is processing the triggered turn, call cron list
  4. Query times out (10s default)

Root Cause

In dist/cron/service/timer.js lines 67-87:

// Inside executeJob(), which runs inside locked()
if (job.wakeMode === "now" && state.deps.runHeartbeatOnce) {
    for (;;) {
        heartbeatResult = await state.deps.runHeartbeatOnce({ reason });
        if (...) break;
        await delay(250);  // Loops up to 2 minutes
    }
}

The locked() function in ops.js serializes ALL cron operations through state.op. Since executeJob() awaits the agent turn completion while holding the lock, any concurrent RPC query blocks.

Evidence from Logs

⇄ res ✓ cron.list 34021ms  // Query took 34s (waited for lock)
⇄ res ✓ cron.status 15254ms // 15s wait

Suggested Fix

Options:

  1. Release lock before awaiting heartbeat - update job state after heartbeat completes
  2. Separate read/write locks - allow concurrent reads during job execution
  3. Move heartbeat await outside locked() - restructure to not hold lock during waits

Environment

  • Clawdbot: 2026.1.24-3
  • Node: v25.1.0
  • macOS (arm64)

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