Skip to content

Core ‐ Agent stop‐task

Bohdan Karpenko edited this page Apr 29, 2026 · 1 revision

Stop Task Request

This handler stops a running task managed by the system.


Request format

{
    "type": "request",
    "action": "stop-task",
    "id": 1,
    "data": {
        "task_id": 123
    }
}

Fields

  • type: must be "request"
  • action: must be "stop-task"
  • id: request identifier
  • data.task_id: integer (i64), required Identifier of the task that should be stopped

Behavior

  • Validates that data exists

  • Extracts task_id

  • Calls:

    • TaskManager::stop_task(task_id)
  • Stops execution of the specified task if it exists and is running

  • Returns success or structured error depending on task state


Successful Response

{
    "type": "response",
    "id": 1,
    "status": "ok",
    "code": 200,
    "message": "Successfully stopped task."
}

Error Responses

Missing data

{
    "type": "response",
    "id": 1,
    "status": "error",
    "code": 400,
    "message": "Missing data"
}

Invalid request format (missing or invalid task_id)

{
    "type": "response",
    "id": 1,
    "status": "error",
    "code": 400,
    "message": "Invalid stop-task request"
}

Task-related error (from TaskManager)

Returned when the operation fails at runtime.

{
    "type": "response",
    "id": 1,
    "status": "error",
    "code": 400,
    "message": "Failed to stop tasks",
    "data": {
        "error": "TaskNotFound"
    }
}

Possible error values:

  • FailedToRunTask — task execution failure
  • TaskNotFound — task does not exist
  • TaskAlreadyRunning — invalid state transition
  • TaskAlreadyStopped — task is already stopped
  • DatabaseError — DB operation failure
  • FailedToPrepareEnvironment(String) — environment setup failed (with message)
  • FailedToManageRun — runtime management failure

Notes

  • This operation is idempotent only if the task is already stopped; otherwise it may return an error.
  • task_id must be a valid signed 64-bit integer.
  • Error details from TaskManager are returned inside data.error as a string representation of TaskError.

Clone this wiki locally