Skip to content

Task maintenance leaves multi-day running tasks stale; doctor/manual cancel required #79226

Description

@Cuttingwater

Summary

OpenClaw can retain very old running task rows for days. openclaw tasks maintenance --apply prunes task-flow records, but does not mark these stale running tasks lost/cancelled. In this state the gateway became intermittently non-responsive and required openclaw doctor --fix to recover the control path.

Observed environment

  • OpenClaw: 2026.5.2 (8b2a6e5)
  • macOS: 26.4.1 arm64
  • Node: 25.8.1
  • Gateway LaunchAgent: ai.openclaw.gateway

Evidence

openclaw status showed:

  • Tasks: 4 active · 0 queued · 4 running · 67 issues
  • repeated gateway liveness warnings: event_loop_delay,event_loop_utilization,cpu
  • websocket handshake timeouts / connectivity probe timeouts while PID was still listening on port 18789

openclaw tasks maintenance --apply initially reported task-flow pruning, but still left stale running tasks:

Tasks maintenance (applied): tasks 0 reconcile · 0 recovered · 0 cleanup stamp · 0 prune; task-flows 0 reconcile · 65 prune
Tasks health after apply: 0 queued · 3 running · 3 audit errors · 25 audit warnings

The remaining running tasks were days old:

9906af0e-df96-4840-921f-42ced79e82e7  created 2026-04-29 21:53  owner agent:main:web_b015a645b1_47aed28cc700
5e098c13-da22-45b8-91f9-4aa9e88c271e  created 2026-05-01 22:22  owner agent:main:subagent:771e97dc-c137-4af7-9e9b-570e40b8225c
b0fa03c6-460f-4bc6-9d4f-1240f231cc1d  created 2026-05-01 22:22  owner agent:main:subagent:22a5d09c-f5da-474f-a5c3-792f6d48026a

Manual cancellation cleared the task audit errors:

openclaw tasks cancel 9906af0e-df96-4840-921f-42ced79e82e7
openclaw tasks cancel 5e098c13-da22-45b8-91f9-4aa9e88c271e
openclaw tasks cancel b0fa03c6-460f-4bc6-9d4f-1240f231cc1d

Tasks health after apply: 0 queued · 0 running · 0 audit errors · 25 audit warnings

Expected behavior

Task maintenance should detect impossible/stale running tasks, probably by age + missing live run/session/process signal, then mark them lost, timed_out, or cancelled without requiring manual lookup/cancel.

A conservative default would be to treat running tasks older than 24h as stale unless there is clear evidence of active work.

Actual behavior

Maintenance pruned task-flow records but left multi-day running task rows untouched. These showed as audit errors until manually cancelled.

Suggested fix

  • Extend openclaw tasks maintenance --apply to reconcile stale running tasks.
  • Add an age threshold or config knob, e.g. --max-running-age 24h / default 24h.
  • Include a dry-run line that lists stale running tasks that would be marked lost/cancelled.
  • Consider having doctor --fix invoke the same stale-running-task reconciliation.

Related liveness symptoms

During the stale-task period the gateway repeatedly hit event-loop liveness warnings and websocket timeouts. A macOS sample during high CPU showed the gateway hot in V8 microtasks/JSON parsing, but the precise JS caller was not available without a Node CPU profile. This issue is specifically about the stale task cleanup gap, not claiming stale tasks are the sole CPU root cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions