Skip to content

[Feature] Add cancel_task tool for stopping running background tasks #54

@randomm

Description

@randomm

Summary

The Project Manager agent can dispatch tasks via mcp_task and check status via mcp_check_task, but cannot cancel running tasks. This limits orchestration capability.

Problem

When requirements change or a better-scoped task is dispatched, old tasks continue running:

  • Wastes compute/tokens
  • May produce conflicting changes
  • No way to stop runaway or stuck tasks

Current State

  • mcp_task - dispatch tasks to specialists
  • mcp_check_task - check task status
  • cancel_task - missing

Requirements

  1. Add cancel_task tool that accepts task_id
  2. Should gracefully stop the running agent
  3. Return confirmation: { "status": "cancelled", "task_id": "..." }
  4. Handle edge cases: task already completed, task not found

Implementation

  • Find task management code (likely packages/opencode/src/tool/task.ts)
  • Add AbortController tracking per task
  • Implement cancel_task tool
  • Register tool in MCP tool registry
  • Add tests

Acceptance Criteria

  • cancel_task tool implemented
  • Cancelled tasks stop execution promptly
  • Status returns "cancelled" when checked
  • Works for all agent types

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions