Skip to main content

:LovelaceCancel

Cancel a running or queued task to free up agent resources.

Command Signature

vim
:LovelaceCancel <task_id>

Alias: :LCancel

Arguments:

  • task_id (required) - The task identifier to cancel (e.g., task_abc123def456)

Description

The :LovelaceCancel command stops task execution and frees up the assigned agent worker. It works for both queued tasks (before execution starts) and running tasks (during execution).

What it does:

  • Stops task execution immediately
  • Frees assigned agent worker
  • Removes task from queue (if queued)
  • Marks task as cancelled in task history
  • Sends cancellation notification

When to use:

  • Task taking longer than expected
  • Realized task description was incorrect
  • Need to free up agent for higher priority work
  • Task stuck or not progressing
  • Accidentally submitted duplicate task

Usage

Basic Usage

vim
:LovelaceCancel task_abc123def456

Cancels the specified task and shows confirmation.

Get Task ID

First, find the task ID to cancel:

vim
:LovelaceTasks
" Find task in list
" Example: task_abc123 | "Refactor code" | Running

:LovelaceCancel task_abc123

From Lua

lua
require("lovelace.commands").cancel("task_abc123def456")

Cancellation Flow

Step 1: Identify Task to Cancel

vim
:LovelaceTasks

" Output:
" ## Running Tasks
" - task_abc123 | "Complex refactor" | Agent: 550e8400... | Running

Step 2: Cancel Task

vim
:LovelaceCancel task_abc123

Step 3: Confirmation

Cancellation request sent for task_abc123
Waiting for agent confirmation...

Step 4: Success Notification

✓ Task task_abc123 cancelled successfully
Agent 550e8400... is now idle

Cancellation States

Cancelling Queued Tasks

Behavior: Immediate cancellation (no agent assigned yet)

vim
:LovelaceTasks
" ## Queued Tasks
" - task_abc123 | "Add types" | Agent: (pending) | Queued

:LovelaceCancel task_abc123

" ✓ Task task_abc123 removed from queue

What happens:

  1. Task removed from queue immediately
  2. No agent involvement (not yet assigned)
  3. Instant confirmation
  4. Task marked as cancelled in history

Duration: < 1 second

Cancelling Running Tasks

Behavior: Graceful cancellation with agent acknowledgment

vim
:LovelaceTasks
" ## Running Tasks
" - task_abc123 | "Refactor module" | Agent: 550e8400... | Running

:LovelaceCancel task_abc123

" Cancellation request sent for task_abc123
" Waiting for agent confirmation...
"
" ✓ Task task_abc123 cancelled
" Agent 550e8400-e29b-41d4-a716-446655440000 stopped execution

What happens:

  1. Cancellation request sent to agent
  2. Agent stops current operation
  3. Agent cleans up resources
  4. Agent acknowledges cancellation
  5. Agent returns to idle state
  6. Confirmation shown

Duration: 2-5 seconds (graceful shutdown)

Cancellation Timeout

Behavior: Agent doesn't respond within timeout

vim
:LovelaceCancel task_abc123

" Cancellation request sent...
" Waiting for agent confirmation...
"
" ⚠ Agent did not confirm cancellation within 10 seconds
" Task may still be running. Check agent status with :LovelaceAgents

What it means:

  • Agent may be unresponsive
  • Task may still be executing
  • Agent may be in critical operation

Action: Check agent status, contact administrator if persistent

Common Scenarios

Scenario 1: Cancel Incorrect Task

Realize task description was wrong:

vim
" Submit task with typo
:LovelaceTask
" Description: "Add typos to user module"  ← Meant "types"!

" Task submitted (task_abc123) - Status: queued

" Cancel immediately
:LovelaceCancel task_abc123

" ✓ Task removed from queue

" Resubmit with correct description
:LovelaceTask
" Description: "Add types to user module"

Scenario 2: Task Taking Too Long

Cancel slow-running task:

vim
" Task running for 5 minutes
:LovelaceTaskStatus task_abc123
" Status: Running
" Duration: 5m 30s

" Cancel if taking too long
:LovelaceCancel task_abc123

" ✓ Task cancelled
" Agent now idle

" Resubmit with more specific requirements
:LovelaceTask
" Description: "Add TypeScript types to User interface only (not entire module)"

Scenario 3: Free Agent for Priority Task

Need agent for urgent work:

vim
" Check current tasks
:LovelaceTasks

" ## Running Tasks
" - task_abc123 | "Low priority cleanup" | Agent: 550e8400... | Running

" Cancel to free agent
:LovelaceCancel task_abc123

" ✓ Agent now available

" Submit urgent task
:LovelaceTask
" Description: "Fix critical authentication bug in login flow"

Scenario 4: Cancel Duplicate Task

Accidentally submitted same task twice:

vim
:LovelaceTasks

" ## Queued Tasks
" - task_abc123 | "Add tests" | Queued
" - task_def456 | "Add tests" | Queued  ← Duplicate!

" Cancel duplicate
:LovelaceCancel task_def456

" ✓ Task removed from queue

Cancellation Behavior

What Gets Cancelled

Cancelled:

  • Task execution stops immediately
  • Partial work is discarded
  • Agent resources freed
  • Task marked as cancelled

Not Cancelled (already completed):

  • File changes already applied
  • Results already saved
  • Agent already returned to idle

Agent State After Cancellation

Before cancellation:

Agent: 550e8400-e29b-41d4-a716-446655440000
Status: busy
Task: task_abc123

After cancellation:

Agent: 550e8400-e29b-41d4-a716-446655440000
Status: idle
Task: (none)

Timeline: Agent returns to idle within 2-5 seconds

Task History

Cancelled tasks remain in history with status:

vim
:LovelaceTasks

" ## Completed Tasks
" - task_abc123 | "Refactor code" | Agent: 550e8400... | Cancelled (2m ago)

Retention: Cancelled tasks retained for 24 hours, then archived

Multiple Cancellations

Cancel multiple tasks in sequence:

vim
" Cancel several queued tasks
:LovelaceCancel task_001
:LovelaceCancel task_002
:LovelaceCancel task_003

" Or use Lua for batch cancellation

Lua batch cancellation:

lua
local tasks_to_cancel = {"task_001", "task_002", "task_003"}

for _, task_id in ipairs(tasks_to_cancel) do
  require("lovelace.commands").cancel(task_id)
  vim.wait(1000)  -- Wait 1 second between cancellations
end

Troubleshooting

"Task not found" Error

Symptom: :LovelaceCancel task_abc123 shows "Task not found"

Solutions:

  1. Verify task ID:

    vim
    :LovelaceTasks
    " Check if task exists
    
  2. Check task state:

    • Task may have already completed
    • Task may have already been cancelled
    • Task ID may be incorrect
  3. Check task age:

    • Tasks older than 24 hours are archived
    • Cannot cancel archived tasks

"Task already completed" Error

Symptom: Cannot cancel task that already finished

✗ Cannot cancel task_abc123: Task already completed

Reason: Task finished before cancellation request processed

Action:

  • No action needed if task completed successfully
  • If task produced unwanted changes, revert manually

Cancellation Timeout

Symptom: Cancellation request sent but no confirmation

Cancellation request sent...
⚠ Agent did not confirm within 10 seconds

Solutions:

  1. Check agent status:

    vim
    :LovelaceAgents
    " Verify agent is responsive
    
  2. Check task status:

    vim
    :LovelaceTaskStatus task_abc123
    " See if task actually stopped
    
  3. Wait and retry:

    vim
    " Wait 30 seconds
    :LovelaceCancel task_abc123
    
  4. Contact administrator:

    • If agent consistently unresponsive
    • May need agent restart

"Cannot cancel system task" Error

Symptom: Some tasks cannot be cancelled

✗ Cannot cancel task_abc123: System task

Reason: Certain internal system tasks cannot be cancelled for safety

Examples:

  • Health check tasks
  • Daemon initialization tasks
  • Critical system operations

Action: Wait for task to complete naturally

Integration Patterns

Cancel and Resubmit Workflow

vim
" 1. Cancel incorrect task
:LovelaceCancel task_abc123

" 2. Wait for confirmation
" ✓ Task cancelled

" 3. Resubmit with corrections
:LovelaceTask
" Corrected description...

" 4. Verify new task
:LovelaceTasks

Cancel All Queued Tasks

lua
-- Cancel all queued tasks (Lua)
local lovelace = require("lovelace")
local tasks = lovelace.get_tasks()

for _, task in ipairs(tasks) do
  if task.status == "queued" then
    require("lovelace.commands").cancel(task.id)
    print("Cancelled: " .. task.id)
  end
end

Timeout-Based Cancellation

lua
-- Auto-cancel tasks running longer than 10 minutes
local lovelace = require("lovelace")
local tasks = lovelace.get_tasks()

local ten_minutes = 10 * 60  -- seconds

for _, task in ipairs(tasks) do
  if task.status == "running" and task.duration_seconds > ten_minutes then
    require("lovelace.commands").cancel(task.id)
    vim.notify("Auto-cancelled long-running task: " .. task.id)
  end
end

When to Cancel vs Wait

Cancel if:

✅ Task description was incorrect ✅ Task taking abnormally long (> 10 minutes) ✅ Need agent for higher priority work ✅ Accidentally submitted duplicate ✅ Task appears stuck (no progress updates)

Wait if:

⏳ Task is large and complex (expected to be slow) ⏳ Progress updates are still appearing ⏳ Task is almost complete (> 90% done) ⏳ Only a few seconds into execution

Rule of thumb:

  • Queued tasks: Cancel freely (instant)
  • Running tasks < 1 minute: Wait
  • Running tasks > 5 minutes with no progress: Cancel

Advanced Usage

Programmatic Cancellation

lua
local lovelace = require("lovelace")
local connection = lovelace.get_connection()

connection:call("task.cancel", {
  task_id = "task_abc123"
}, function(result, error)
  if result and result.success then
    vim.notify("Task cancelled successfully")
  else
    vim.notify("Cancellation failed: " .. (error or "unknown error"))
  end
end)

Conditional Cancellation

lua
-- Cancel task if it matches certain criteria
local function cancel_if_matches(task_id, criteria)
  local lovelace = require("lovelace")
  local status = lovelace.get_task_status(task_id)

  if not status then
    return false
  end

  -- Check criteria
  if criteria.min_duration and status.duration_seconds < criteria.min_duration then
    return false
  end

  if criteria.required_state and status.state ~= criteria.required_state then
    return false
  end

  -- Cancel if criteria match
  require("lovelace.commands").cancel(task_id)
  return true
end

-- Usage
cancel_if_matches("task_abc123", {
  min_duration = 300,  -- At least 5 minutes old
  required_state = "running"
})

Related Commands

CommandPurpose
:LovelaceTaskStatusCheck task status before cancelling
:LovelaceTasksList all tasks to find task ID
:LovelaceAgentsCheck agent availability
:LovelaceTaskResubmit task after cancelling

Next Steps

Related Documentation