Skip to content

Tasks: allow openclaw tasks cancel for CLI runtime (#62419)#62506

Merged
obviyus merged 4 commits into
openclaw:mainfrom
neeravmakwana:fix/cli-tasks-cancel-62419
Apr 9, 2026
Merged

Tasks: allow openclaw tasks cancel for CLI runtime (#62419)#62506
obviyus merged 4 commits into
openclaw:mainfrom
neeravmakwana:fix/cli-tasks-cancel-62419

Conversation

@neeravmakwana

Copy link
Copy Markdown
Contributor

Summary

  • Problem: openclaw tasks cancel returned "Task runtime does not support cancellation yet" for CLI-tracked tasks (for example gateway agent runs), so operators could not clear stuck running rows.
  • Why it matters: CLI tasks can remain running when follow-up bookkeeping never runs; without a working cancel path there was no supported way to mark them terminal.
  • What changed: cancelTaskById treats runtime === "cli" like other local cancellations: record cancelled in the task registry (CLI uses the main session as childSessionKey; 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_running is unchanged (audit remains informational).

Change Type

  • Bug fix

Scope

  • Gateway / orchestration

Linked Issue/PR

Root Cause

  • Root cause: cancelTaskById only 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 to cancelled, does not call ACP/subagent hooks, and delivers the expected terminal message when delivery is pending.

User-visible / Behavior Changes

  • openclaw tasks cancel succeeds for active CLI-tracked tasks and sets status to cancelled with 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

  1. Create a running CLI task record with childSessionKey set.
  2. Call cancelTaskById.
  3. Expect cancelled: true and 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.

Made with Cursor

@greptile-apps

greptile-apps Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds cli as a supported runtime in cancelTaskById so openclaw tasks cancel no longer returns "Task runtime does not support cancellation yet" for CLI-tracked tasks. The implementation is correct for the normal case and is well-tested and documented. Two minor P2 issues noted below.

Confidence Score: 5/5

Safe to merge; all findings are P2 style/edge-case issues that do not affect the primary cancel path.

The core logic change is correct, covered by a focused new test, and properly documented. Remaining comments are a changelog placement policy violation and a defensive guard-ordering concern for an edge case the PR author acknowledges is not exercised in production.

CHANGELOG.md (entry placement); src/tasks/task-registry.ts (childSessionKey guard ordering for the CLI branch).

Comments Outside Diff (1)

  1. src/tasks/task-registry.ts, line 1721-1728 (link)

    P2 childSessionKey guard fires before the CLI branch

    This guard returns early for any task whose childSessionKey is absent, including cli tasks. For the cli runtime there is no separate process to kill — childSessionKey is only a session reference — so a CLI task without this field could still be safely cancelled. If a legacy record or a partial-write leaves childSessionKey unset on a CLI task, the operator gets "Task has no cancellable child session" instead of a successful cancellation, even though there is nothing to stop. Consider either evaluating the cli branch before this guard, or exempting runtime === "cli" from the guard entirely.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/tasks/task-registry.ts
    Line: 1721-1728
    
    Comment:
    **`childSessionKey` guard fires before the CLI branch**
    
    This guard returns early for any task whose `childSessionKey` is absent, including `cli` tasks. For the `cli` runtime there is no separate process to kill — `childSessionKey` is only a session reference — so a CLI task without this field could still be safely cancelled. If a legacy record or a partial-write leaves `childSessionKey` unset on a CLI task, the operator gets "Task has no cancellable child session" instead of a successful cancellation, even though there is nothing to stop. Consider either evaluating the `cli` branch before this guard, or exempting `runtime === "cli"` from the guard entirely.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: CHANGELOG.md
Line: 32

Comment:
**Changelog entry at top of section**

This entry is placed immediately after the `### Fixes` heading, making it the first entry in the section. The repo rule in `CLAUDE.md` says to append new entries to the **end** of the target section; do not insert at the top. Move this line to after the last existing entry in the `### Fixes` block.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/tasks/task-registry.ts
Line: 1721-1728

Comment:
**`childSessionKey` guard fires before the CLI branch**

This guard returns early for any task whose `childSessionKey` is absent, including `cli` tasks. For the `cli` runtime there is no separate process to kill — `childSessionKey` is only a session reference — so a CLI task without this field could still be safely cancelled. If a legacy record or a partial-write leaves `childSessionKey` unset on a CLI task, the operator gets "Task has no cancellable child session" instead of a successful cancellation, even though there is nothing to stop. Consider either evaluating the `cli` branch before this guard, or exempting `runtime === "cli"` from the guard entirely.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Tasks: allow openclaw tasks cancel for C..." | Re-trigger Greptile

Comment thread CHANGELOG.md Outdated
@neeravmakwana

Copy link
Copy Markdown
Contributor Author

Follow-up (review feedback)

Greptile / changelog

  • Moved the Unreleased → Fixes changelog line to the end of the ### Fixes block per repo policy (append, not prepend).

Greptile / childSessionKey guard

  • The early return for a missing childSessionKey now does not apply to runtime === "cli", so operator cancel can still clear legacy or partial CLI rows with no session key. ACP/subagent behavior is unchanged (they still require a key).
  • Added unit test: cancels CLI-tracked tasks without childSessionKey.

Aisle (lifecycle vs operator cancel)

  • The agent lifecycle listener no longer applies a patch.status update when the task is already terminal (isTerminalTaskStatus). That prevents a late lifecycle end from overwriting cancelled with succeeded after operator cancel (or any other terminal row from being “revived” by lifecycle).
  • Added unit test: does not overwrite operator-cancelled terminal status with lifecycle end.

Verification

  • pnpm test src/tasks/task-registry.test.ts (full file) — all green.

Commit: 42fcba7dd7 on fix/cli-tasks-cancel-62419.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42fcba7dd7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/tasks/task-registry.ts Outdated
@obviyus obviyus force-pushed the fix/cli-tasks-cancel-62419 branch from 43f3f12 to 189fc01 Compare April 9, 2026 11:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 189fc0118f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CHANGELOG.md Outdated
@obviyus obviyus self-assigned this Apr 9, 2026

@obviyus obviyus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed latest changes; landing now.

@obviyus obviyus merged commit 7f71460 into openclaw:main Apr 9, 2026
23 of 26 checks passed
@obviyus

obviyus commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Landed on main.

Thanks @neeravmakwana.

steipete pushed a commit that referenced this pull request Apr 10, 2026
…@neeravmakwana)

* Tasks: allow openclaw tasks cancel for CLI runtime (#62419)

Made-with: Cursor

* Tasks: address review — changelog order, CLI cancel without session, lock terminal status

Made-with: Cursor

* fix: freeze terminal task listener updates

* fix: clean changelog block for CLI task cancel (#62506) (thanks @neeravmakwana)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
… (thanks @neeravmakwana)

* Tasks: allow openclaw tasks cancel for CLI runtime (openclaw#62419)

Made-with: Cursor

* Tasks: address review — changelog order, CLI cancel without session, lock terminal status

Made-with: Cursor

* fix: freeze terminal task listener updates

* fix: clean changelog block for CLI task cancel (openclaw#62506) (thanks @neeravmakwana)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
… (thanks @neeravmakwana)

* Tasks: allow openclaw tasks cancel for CLI runtime (openclaw#62419)

Made-with: Cursor

* Tasks: address review — changelog order, CLI cancel without session, lock terminal status

Made-with: Cursor

* fix: freeze terminal task listener updates

* fix: clean changelog block for CLI task cancel (openclaw#62506) (thanks @neeravmakwana)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
… (thanks @neeravmakwana)

* Tasks: allow openclaw tasks cancel for CLI runtime (openclaw#62419)

Made-with: Cursor

* Tasks: address review — changelog order, CLI cancel without session, lock terminal status

Made-with: Cursor

* fix: freeze terminal task listener updates

* fix: clean changelog block for CLI task cancel (openclaw#62506) (thanks @neeravmakwana)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
… (thanks @neeravmakwana)

* Tasks: allow openclaw tasks cancel for CLI runtime (openclaw#62419)

Made-with: Cursor

* Tasks: address review — changelog order, CLI cancel without session, lock terminal status

Made-with: Cursor

* fix: freeze terminal task listener updates

* fix: clean changelog block for CLI task cancel (openclaw#62506) (thanks @neeravmakwana)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
… (thanks @neeravmakwana)

* Tasks: allow openclaw tasks cancel for CLI runtime (openclaw#62419)

Made-with: Cursor

* Tasks: address review — changelog order, CLI cancel without session, lock terminal status

Made-with: Cursor

* fix: freeze terminal task listener updates

* fix: clean changelog block for CLI task cancel (openclaw#62506) (thanks @neeravmakwana)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: tasks cancel returns 'Task runtime does not support cancellation yet' - no way to clear stale_running CLI tasks

2 participants