Source: https://docs.cumuluslabs.io/reference/test_runs.cancel
Content version: 14ec934b

# test_runs.cancel

Cancel a test run: no new trials start and running trials are cancelled; settled results stay

## Request {#request}

`POST /api/v1/test-runs/{test_run_id}/cancel`

- MCP: `test_runs_cancel`
- SDK: `client.test_runs.cancel` (SDK path arguments use `path`; MCP uses `params`).
- Minimum API key role: **member**.
- Idempotency: **natural**.

Use the request schema below. Read IDs from earlier operation results.

## Input schema {#input-schema}

```json
{
  "parameters": [
    {
      "name": "test_run_id",
      "in": "path",
      "required": true,
      "schema": {
        "type": "string",
        "format": "uuid"
      }
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/TestRunsCancelRequest"
        }
      }
    }
  }
}
```

## Responses {#responses}

```json
{
  "202": {
    "description": "Cancel a test run: no new trials start and running trials are cancelled; settled results stay",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/TestRun"
        }
      }
    }
  },
  "4XX": {
    "description": "Typed error (ApiError)",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/ApiError"
        }
      }
    }
  },
  "5XX": {
    "description": "Typed error (ApiError)",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/ApiError"
        }
      }
    }
  }
}
```

## Referenced schemas {#schemas}

```json
{
  "components": {
    "schemas": {
      "TestRunsCancelRequest": {
        "type": "object",
        "properties": {},
        "additionalProperties": false
      },
      "TestRun": {
        "type": "object",
        "properties": {
          "owner_id": {
            "type": "string",
            "minLength": 1
          },
          "environment": {
            "type": "string",
            "minLength": 1
          },
          "tenant_id": {
            "type": "string",
            "format": "uuid"
          },
          "test_run_id": {
            "type": "string",
            "format": "uuid"
          },
          "agent_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]*$"
          },
          "publication": {
            "$ref": "#/components/schemas/PublicationRef"
          },
          "purpose": {
            "type": "string",
            "enum": [
              "manual",
              "publish_gate",
              "schedule",
              "release"
            ]
          },
          "suites": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "suite_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "revision": {
                  "type": "integer",
                  "exclusiveMinimum": true,
                  "minimum": 0,
                  "maximum": 2147483647
                },
                "digest": {
                  "type": "string",
                  "pattern": "^sha256:[a-f0-9]{64}$"
                }
              },
              "required": [
                "suite_id",
                "revision",
                "digest"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "maxItems": 10
          },
          "state": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "completed",
              "cancelled"
            ]
          },
          "verdict": {
            "type": "string",
            "enum": [
              "passed",
              "failed",
              "errored"
            ],
            "nullable": true
          },
          "progress": {
            "type": "object",
            "properties": {
              "trials": {
                "type": "integer",
                "minimum": 0
              },
              "admitted": {
                "type": "integer",
                "minimum": 0
              },
              "settled": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "trials",
              "admitted",
              "settled"
            ],
            "additionalProperties": false
          },
          "summary": {
            "type": "object",
            "properties": {
              "cases": {
                "type": "integer",
                "minimum": 0
              },
              "passed": {
                "type": "integer",
                "minimum": 0
              },
              "flaky_passed": {
                "type": "integer",
                "minimum": 0
              },
              "failed": {
                "type": "integer",
                "minimum": 0
              },
              "errored": {
                "type": "integer",
                "minimum": 0
              },
              "invalid": {
                "type": "integer",
                "minimum": 0
              },
              "trials": {
                "type": "integer",
                "minimum": 0
              },
              "regressed": {
                "type": "integer",
                "minimum": 0
              },
              "fixed": {
                "type": "integer",
                "minimum": 0
              },
              "guard_events": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "cases",
              "passed",
              "flaky_passed",
              "failed",
              "errored",
              "invalid",
              "trials",
              "regressed",
              "fixed",
              "guard_events"
            ],
            "additionalProperties": false,
            "nullable": true
          },
          "baseline_test_run_id": {
            "allOf": [
              {
                "type": "string",
                "format": "uuid"
              }
            ],
            "nullable": true
          },
          "judge_model": {
            "allOf": [
              {
                "$ref": "#/components/schemas/ModelIdentity"
              }
            ],
            "nullable": true
          },
          "cost": {
            "type": "object",
            "properties": {
              "estimated_usd": {
                "type": "number",
                "minimum": 0
              },
              "measured_usd": {
                "type": "number",
                "minimum": 0,
                "nullable": true
              }
            },
            "required": [
              "estimated_usd",
              "measured_usd"
            ],
            "additionalProperties": false
          },
          "created_by": {
            "$ref": "#/components/schemas/PrincipalRef"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "finished_at": {
            "allOf": [
              {
                "type": "string",
                "format": "date-time"
              }
            ],
            "nullable": true
          }
        },
        "required": [
          "owner_id",
          "environment",
          "tenant_id",
          "test_run_id",
          "agent_id",
          "publication",
          "purpose",
          "suites",
          "state",
          "verdict",
          "progress",
          "summary",
          "baseline_test_run_id",
          "judge_model",
          "cost",
          "created_by",
          "created_at",
          "finished_at"
        ],
        "additionalProperties": false
      },
      "PublicationRef": {
        "type": "object",
        "properties": {
          "agent_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]*$"
          },
          "version": {
            "type": "integer",
            "minimum": 0,
            "maximum": 2147483647
          },
          "digest": {
            "type": "string",
            "pattern": "^sha256:[a-f0-9]{64}$"
          }
        },
        "required": [
          "agent_id",
          "version",
          "digest"
        ],
        "additionalProperties": false
      },
      "ModelIdentity": {
        "type": "object",
        "properties": {
          "model_id": {
            "type": "string",
            "minLength": 1,
            "pattern": "\\S"
          },
          "provider": {
            "type": "string",
            "minLength": 1,
            "pattern": "\\S"
          },
          "tier": {
            "type": "string",
            "enum": [
              "frontier",
              "cumulus-served",
              "customer-gpu"
            ]
          }
        },
        "required": [
          "model_id",
          "provider",
          "tier"
        ],
        "additionalProperties": false
      },
      "PrincipalRef": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "owner_id": {
                "type": "string",
                "minLength": 1
              },
              "environment": {
                "type": "string",
                "minLength": 1
              },
              "kind": {
                "type": "string",
                "enum": [
                  "user"
                ]
              },
              "id": {
                "type": "string",
                "format": "uuid"
              }
            },
            "required": [
              "owner_id",
              "environment",
              "kind",
              "id"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "owner_id": {
                "type": "string",
                "minLength": 1
              },
              "environment": {
                "type": "string",
                "minLength": 1
              },
              "kind": {
                "type": "string",
                "enum": [
                  "api_key"
                ]
              },
              "id": {
                "type": "string",
                "format": "uuid"
              }
            },
            "required": [
              "owner_id",
              "environment",
              "kind",
              "id"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "owner_id": {
                "type": "string",
                "minLength": 1
              },
              "environment": {
                "type": "string",
                "minLength": 1
              },
              "kind": {
                "type": "string",
                "enum": [
                  "system"
                ]
              },
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256
              }
            },
            "required": [
              "owner_id",
              "environment",
              "kind",
              "id"
            ],
            "additionalProperties": false
          }
        ]
      },
      "ApiError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "unauthenticated",
                  "forbidden",
                  "not_found",
                  "conflict",
                  "invalid_request",
                  "idempotency_conflict",
                  "policy_denied",
                  "capability_unavailable",
                  "provider_unavailable",
                  "knowledge_unavailable",
                  "publication_invalid",
                  "run_not_active",
                  "rate_limited",
                  "outcome_unknown",
                  "internal"
                ]
              },
              "message": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              },
              "outcome": {
                "type": "string",
                "enum": [
                  "none",
                  "unknown"
                ]
              },
              "details": {
                "type": "object",
                "additionalProperties": {}
              }
            },
            "required": [
              "code",
              "message",
              "retryable",
              "outcome"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      }
    }
  }
}
```

## Errors and recovery {#errors}

See [API error handling](https://docs.cumuluslabs.io/api#errors) and [Troubleshooting](https://docs.cumuluslabs.io/troubleshooting).

## Related guides {#related-guides}

- [Test an agent](https://docs.cumuluslabs.io/testing)
- [Build and test recipes](https://docs.cumuluslabs.io/recipes)
