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

# Request cancellation or replay an ended observation

> A queued job cancels atomically before execution claims it. An active job receives the run-scoped cancellation signal and returns 202 until its execution owner settles: the result may be success, failure or cancellation. The grace is fixed at 5 seconds from the signal: a run that has not reached a wave boundary and settled by then is dropped and the job settles `interrupted`, never an invented cancellation. A task still inside one long step when the signal arrives (an agent turn, a long wait) typically outlasts the grace. A paused or final observation returns its existing result unchanged.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/jobs/{id}/cancel
openapi: 3.1.0
info:
  description: >-
    Authenticated loopback remote execution, declarative schedules, verified
    downloads of the artifacts a settled job's sealed journal records, and
    stateless source-only authoring (POST /v1/compile never runs, admits or
    writes). Schedule list/delete/trigger/backfill, /v1/arm, and POST /v1/run
    are absent.
  title: nika serve
  version: 0.124.1
servers:
  - url: http://127.0.0.1
security:
  - bearerAuth: []
paths:
  /v1/jobs/{id}/cancel:
    post:
      summary: Request cancellation or replay an ended observation
      description: >-
        A queued job cancels atomically before execution claims it. An active
        job receives the run-scoped cancellation signal and returns 202 until
        its execution owner settles: the result may be success, failure or
        cancellation. The grace is fixed at 5 seconds from the signal: a run
        that has not reached a wave boundary and settled by then is dropped and
        the job settles `interrupted`, never an invented cancellation. A task
        still inside one long step when the signal arrives (an agent turn, a
        long wait) typically outlasts the grace. A paused or final observation
        returns its existing result unchanged.
      parameters:
        - in: path
          name: id
          required: true
          schema:
            format: uuid
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Job'
          description: Cancelled before execution, or already ended observation
        '202':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Job'
          description: Cancellation requested; execution has not yet settled
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Error envelope
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Error envelope
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Error envelope
components:
  schemas:
    Job:
      additionalProperties: false
      properties:
        error:
          additionalProperties: false
          properties:
            code:
              type: string
            message:
              type: string
          required:
            - code
            - message
          type: object
        evidence:
          $ref: '#/components/schemas/JournalEvidence'
        execution_id:
          type: string
        id:
          format: uuid
          type: string
        outputs:
          additionalProperties: true
          description: >-
            Declared workflow outputs; present only after settlement when
            supplied by the execution adapter
          type: object
        receipt:
          $ref: '#/components/schemas/JobReceipt'
        settlement:
          $ref: '#/components/schemas/RunSettlement'
        status:
          $ref: '#/components/schemas/JobStatus'
        trace_id:
          type: string
      required:
        - id
        - status
      type: object
    Error:
      additionalProperties: false
      properties:
        error:
          additionalProperties: false
          properties:
            code:
              type: string
            message:
              type: string
          required:
            - code
            - message
          type: object
      required:
        - error
      type: object
    JournalEvidence:
      additionalProperties: false
      description: >-
        Reported journal delivery loss, independent of execution status. The
        reason classifies the mirror's first error without exposing OS text or
        paths. Absence is not a claim that a journal exists.
      properties:
        reason:
          enum:
            - write_failed
            - record_refused
          type: string
        status:
          const: mirror_lost
          type: string
      required:
        - status
        - reason
      type: object
    JobReceipt:
      additionalProperties: false
      description: Terminal binding to the exact immutable admitted execution
      properties:
        chain_head:
          minLength: 1
          type: string
        execution_id:
          minLength: 1
          type: string
        job_id:
          format: uuid
          type: string
        origin:
          $ref: '#/components/schemas/JobOrigin'
        snapshot_digest:
          pattern: ^[0-9a-f]{64}$
          type: string
        trace_id:
          minLength: 1
          type: string
      required:
        - job_id
        - execution_id
        - trace_id
        - snapshot_digest
      type: object
    RunSettlement:
      additionalProperties: false
      description: >-
        The run's settlement (ADR-128), built once by the runtime and projected
        whole: the state word every door speaks, why, the elapsed time on the
        kernel clock, the task tally, the spend with its qualifier, the failure
        named. Unknown cost is never zero: `total_cost_usd` is absent when
        nothing was metered. Present on the terminal event and durable job
        response of a job whose runtime settled; absent when the resident lost
        the execution (interrupted) or refused it before any task. Reattachment
        and idempotent admission replay project the same hash-bound terminal
        event, never a new settlement.
      properties:
        cause:
          enum:
            - normal
            - human_gate
            - task_failed
            - output_contract
            - budget
            - operator
            - refused
          type: string
        elapsed_ms:
          minimum: 0
          type: integer
        error:
          additionalProperties: false
          properties:
            code:
              type: string
            message:
              type: string
            task:
              description: The task that failed · absent for a run-level cause
              type: string
          required:
            - code
            - message
          type: object
        spend:
          additionalProperties: false
          properties:
            by_source:
              additionalProperties:
                type: number
              type: object
            priced_calls:
              minimum: 0
              type: integer
            pricing_as_of:
              type: string
            qualifier:
              enum:
                - priced
                - partially_priced
                - unpriced
                - unmetered
              type: string
            total_cost_usd:
              description: Present only when at least one leaf metered real spend
              minimum: 0
              type: number
            unpriced_calls:
              minimum: 0
              type: integer
          required:
            - priced_calls
            - unpriced_calls
            - qualifier
          type: object
        status:
          enum:
            - succeeded
            - failed
            - paused
            - cancelled
          type: string
        stopped_calls:
          description: >-
            Every MCP call the run stopped waiting for, on every path (a task's
            timeout, an operator Stop, a task that continued or recovered after
            it): the task, the tool as the workflow names it, the call's id, and
            whether the call left. `unknown`: the call reached the server, which
            may have acted, so an effect's outcome is unknown; `not_sent`: it
            was stopped before it was sent. Absent when the run stopped no MCP
            call.
          items:
            additionalProperties: false
            properties:
              call_id:
                type: string
              outcome:
                enum:
                  - unknown
                  - not_sent
                type: string
              task:
                type: string
              tool:
                description: '`mcp:<server>/<tool>`'
                type: string
            required:
              - task
              - tool
              - call_id
              - outcome
            type: object
          minItems: 1
          type: array
        tasks:
          additionalProperties: false
          properties:
            cancelled:
              minimum: 0
              type: integer
            failed:
              minimum: 0
              type: integer
            never_started:
              description: >-
                Cancelled at the boundary without ever starting (counted in
                `cancelled` too)
              minimum: 0
              type: integer
            ok:
              description: A recovered task IS a success (counted here too)
              minimum: 0
              type: integer
            recovered:
              minimum: 0
              type: integer
            skipped:
              minimum: 0
              type: integer
            total:
              minimum: 0
              type: integer
          required:
            - total
            - ok
            - failed
            - recovered
            - skipped
            - cancelled
            - never_started
          type: object
      required:
        - status
        - cause
        - spend
      type: object
    JobStatus:
      description: >-
        queued and running: the resident owns the execution. interrupted:
        execution ownership was lost and effect settlement is unknown — an
        EVIDENCE state (the journal is INCOMPLETE), never a run state (ADR-129).
        paused, succeeded, failed and cancelled: the run's own settlement, the
        words its terminal frame carries (ADR-128).
      enum:
        - queued
        - running
        - interrupted
        - paused
        - succeeded
        - failed
        - cancelled
      type: string
    JobOrigin:
      oneOf:
        - additionalProperties: false
          properties:
            kind:
              const: manual
              type: string
          required:
            - kind
          type: object
        - additionalProperties: false
          dependentRequired:
            missed_count:
              - missed_first
            missed_first:
              - missed_count
          properties:
            arm_generation:
              pattern: ^[0-9a-f]{64}$
              type: string
            decision:
              enum:
                - scheduled
                - catch_up
              type: string
            fired_at:
              format: date-time
              type: string
            kind:
              const: schedule
              type: string
            missed_count:
              description: How many slots that silence holds
              minimum: 1
              type: integer
            missed_first:
              description: >-
                First slot of the silence a catch-up-once run answers for, on a
                catch_up firing only; scheduled_for is its last slot
              format: date-time
              type: string
            schedule_id:
              description: >-
                Origin-local identifier, bounded to 255 UTF-8 bytes by the
                server
              maxLength: 255
              minLength: 1
              type: string
            schedule_origin:
              enum:
                - project
                - api
              type: string
            schedule_revision:
              pattern: ^sha256:[0-9a-f]{64}$
              type: string
            scheduled_for:
              format: date-time
              type: string
            slot_id:
              pattern: ^[0-9a-f]{64}$
              type: string
          required:
            - kind
            - schedule_origin
            - schedule_id
            - schedule_revision
            - slot_id
            - decision
            - scheduled_for
            - fired_at
            - arm_generation
          type: object
  securitySchemes:
    bearerAuth:
      description: 'Exactly one Authorization: Bearer value from the token file'
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.