CLI tasks now cancellable via openclaw tasks cancel
The `openclaw tasks cancel` command now works for CLI-tracked tasks. Operators can finally clear stuck running tasks that were previously unkillable.
CLI-tracked tasks that got stuck in a running state had nowhere to go. When operators tried to cancel them with openclaw tasks cancel, the command returned "Task runtime does not support cancellation yet" — leaving orphaned rows with no escape hatch. The maintenance command didn't help either, doing nothing for these stale tasks.
The fix restructures cancelTaskById to recognize CLI runtime alongside ACP and subagent runtimes. Instead of attempting to kill a child session (CLI tasks run in the main session, so there's nothing separate to stop), the function now records the cancellation directly in the task registry. The task transitions to a cancelled terminal state and a delivery notification is sent when applicable.
The task listener also received a guardrail: terminal status tasks are now skipped during listener updates, preventing cancelled or completed tasks from being accidentally overwritten back to running.
In the task registry, the cancellation flow now branches by runtime type. ACP and subagent runtimes still kill their respective child sessions. CLI runtime skips the session kill entirely — it just records the cancellation in the registry and returns success.
Unit tests verify that CLI cancellation updates the task to cancelled, does not invoke ACP or subagent hooks, and delivers the expected message when delivery is pending.
View Original GitHub Description
Summary
- Problem:
openclaw tasks cancelreturned "Task runtime does not support cancellation yet" for CLI-tracked tasks (for example gateway agent runs), so operators could not clear stuckrunningrows. - Why it matters: CLI tasks can remain
runningwhen follow-up bookkeeping never runs; without a working cancel path there was no supported way to mark them terminal. - What changed:
cancelTaskByIdtreatsruntime === "cli"like other local cancellations: recordcancelledin the task registry (CLI uses the main session aschildSessionKey; there is no separate ACP/subagent session to stop). Docs and changelog updated; unit test covers the path. - What did NOT change: Cron and any other non-ACP/subagent/CLI runtimes still return the unsupported message. Maintenance/audit behavior for
stale_runningis unchanged (audit remains informational).
Change Type
- Bug fix
Scope
- Gateway / orchestration
Linked Issue/PR
- Closes #62419
- This PR fixes a bug or regression
Root Cause
- Root cause:
cancelTaskByIdonly wired teardown for ACP and subagent runtimes; CLI fell through to the unsupported branch despite using a normal session key. - Missing detection / guardrail: Unit tests only covered ACP and subagent cancellation.
Regression Test Plan
- Coverage: Unit test (
src/tasks/task-registry.test.ts) asserts CLI cancel updates the task tocancelled, does not call ACP/subagent hooks, and delivers the expected terminal message when delivery is pending.
User-visible / Behavior Changes
openclaw tasks cancelsucceeds for active CLI-tracked tasks and sets status tocancelledwith operator error text.
Diagram
N/A
Security Impact
- New permissions/capabilities? No
- Secrets/tokens handling changed? No
- New/changed network calls? No
- Command/tool execution surface changed? No (registry state only for CLI cancel)
- Data access scope changed? No
Repro + Verification
Environment
- Unit test run:
pnpm test src/tasks/task-registry.test.ts -t "cancels"
Steps
- Create a running CLI task record with
childSessionKeyset. - Call
cancelTaskById. - Expect
cancelled: trueand no ACP/subagent control calls.
Expected
- Task transitions to
cancelled.
Actual
- Matches test expectations.
Evidence
- New unit test for CLI cancel path
Human Verification
- Verified scenarios: Scoped Vitest for cancel tests in
task-registry.test.ts. - Edge cases checked: Confirms ACP/subagent mocks are not invoked for CLI.
- What I did not verify: Full
pnpm check/pnpm build(local tree has unrelated TS/build failures on this checkout).
Review Conversations
- I replied to or resolved every bot review conversation I addressed in this PR.
Compatibility / Migration
- Backward compatible? Yes
- Config/env changes? No
- Migration needed? No
Risks and Mitigations
- Risk: Cancelling while a CLI run is still live does not abort the agent run; it only updates task registry state (same class of limitation as other operator-driven terminal updates if completion races).
- Mitigation: Matches prior behavior for non-CLI paths that only had registry + session kill where applicable; documented in
docs/automation/tasks.md.
- Mitigation: Matches prior behavior for non-CLI paths that only had registry + session kill where applicable; documented in
Made with Cursor