> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gp.scale.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Clean Task

> Delete content-bearing rows for a stale task.

Refuses on active tasks, in-flight workflows, or unprocessed events
regardless of `force`. The `force=true` flag only bypasses the
idle-threshold check.



## OpenAPI

````yaml https://agentex.dev-sgp.scale.com/openapi.json post /tasks/{task_id}/clean
openapi: 3.1.0
info:
  title: Agentex API
  version: 0.1.0
servers: []
security: []
paths:
  /tasks/{task_id}/clean:
    post:
      tags:
        - task-retention
      summary: Clean Task
      description: |-
        Delete content-bearing rows for a stale task.

        Refuses on active tasks, in-flight workflows, or unprocessed events
        regardless of `force`. The `force=true` flag only bypasses the
        idle-threshold check.
      operationId: clean_task_tasks__task_id__clean_post
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
            title: Task Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CleanTaskRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CleanTaskResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    CleanTaskRequest:
      properties:
        force:
          type: boolean
          title: Force
          description: >-
            Skip the idle-threshold check. Active-workflow and
            unprocessed-events checks still apply. Admin use only.
          default: false
        idle_days:
          type: integer
          minimum: 1
          title: Idle Days
          description: Idle threshold in days (ignored when force=true).
          default: 7
      type: object
      title: CleanTaskRequest
    CleanTaskResponse:
      properties:
        task_id:
          type: string
          title: Task Id
        cleaned_at:
          type: string
          format: date-time
          title: Cleaned At
        messages_deleted:
          type: integer
          title: Messages Deleted
        task_states_deleted:
          type: integer
          title: Task States Deleted
        events_deleted:
          type: integer
          title: Events Deleted
      type: object
      required:
        - task_id
        - cleaned_at
        - messages_deleted
        - task_states_deleted
        - events_deleted
      title: CleanTaskResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````