openclaw - 💡(How to fix) Fix feat: Support task cancellation - allow user 'stop' command to interrupt long-running exec/blocking calls

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

OpenClaw's gateway runs a single-threaded event loop. When the agent calls a tool that blocks (like exec with a long yieldMs/ imeout, or waiting for a sub-agent result), the event loop is blocked and cannot process incoming messages - including the stop command - until the blocking call returns.

RAW_BUFFERClick to expand / collapse

Problem

When the agent is executing a long-running task (e.g., exec with a 60-second timeout, sessions_spawn waiting for a sub-agent), if the user says "?" (stop), the agent cannot respond immediately. The stop signal is queued and only processed after the current blocking call finishes.

This creates a poor user experience where the stop command feels ignored when the agent is "busy."

Root Cause

OpenClaw's gateway runs a single-threaded event loop. When the agent calls a tool that blocks (like exec with a long yieldMs/ imeout, or waiting for a sub-agent result), the event loop is blocked and cannot process incoming messages - including the stop command - until the blocking call returns.

Impact

  • Users feel the agent is unresponsive to stop commands during long operations
  • Cannot interrupt operations that are taking longer than expected (e.g., stuck downloads, infinite loops in generated code)
  • Forces users to wait full duration even after they decided to cancel

Suggested Solutions (in order of complexity)

1. Short-interval polling for exec (simplest)

Change exec tool's implementation to check a cancellation flag periodically instead of blocking for the full duration. Instead of one 60-second blocking call, use short intervals (e.g., 1-second) with cancellation checks between.

2. Background process + cancellation

Move long-running execs to background processes managed by a supervisor. The supervisor can receive SIGKILL/SIGTERM signals when a stop is requested.

3. Cooperative cancellation via context

Add a CancellationToken to the agent's context that is checked at tool execution boundaries. When user says "stop", set this token. Tools that support cancellation check it and throw early.

4. Async message pump (architectural)

Decouple message receiving from agent execution using an async message pump. This way stop signals can interrupt even during tool calls without waiting for the tool to return.

References

  • Related discussion: Agent cannot interrupt long-running tasks in single-threaded event loop
  • Similar issue in other async frameworks: cooperative cancellation with AbortController/CancellationToken

Reported by: shaomao555-byte (via OpenClaw workspace agent)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING