openapi: 3.1.0
info:
  title: MTHDS Protocol
  version: 2.0.1
  summary: The minimal HTTP contract every MTHDS runner implements.
  description: >
    Five required routes, two optional blob routes for a runner that keeps a blob
    store, and two optional run reads for a runner that keeps a run store, which also
    honours an Idempotency-Key header on /execute and /start. Any server implementing
    the five required routes is an MTHDS-compliant runner. A runner executes and
    validates methods, each sent as its whole method tree, a map of file entries; the
    protocol requires no run store of it, and it owns no user, billing, or catalog
    concepts. Paths are relative to an implementation-chosen base URL.
    Implementations may extend the surface (extra routes, extra request properties)
    but must not change the meaning or shape of the protocol routes. Every error is an
    RFC 9457 application/problem+json problem document carrying the MTHDS core
    members (the Problem schema).
  license:
    name: MIT
    identifier: MIT
servers:
  - url: http://localhost:8081/v1
    description: Example — a self-hosted runner. The version segment belongs to the server base URL; protocol paths are version-agnostic.
  - url: https://api.example.com/v1
    description: Example — a hosted, protocol-compliant superset.
security:
  - bearer: []
  - {} # auth is implementation-defined; anonymous allowed self-hosted
tags:
  - name: run
    description: Execute methods, synchronously or asynchronously.
  - name: validate
    description: Static + dry-run validation of MTHDS bundles.
  - name: discovery
    description: What this runner is and what it can route to.
  - name: blobs
    description: >
      Optional. A runner whose /version declares blob_store true keeps a blob store
      (bytes keyed by their SHA-256, written once, never changed), so a sender uploads
      a file at most once and then sends it by hash.
  - name: runs
    description: >
      Optional. A runner whose /version declares run_store true keeps a run store (a
      record of the runs it has started, by their pipeline_run_id), so a caller reads a
      run's status and its results after the fact, and it honours an Idempotency-Key
      header on /execute and /start, so a request repeated under its key within 24
      hours of the first request under it runs at most once.
paths:
  /execute:
    post:
      operationId: executeMethod
      tags: [run]
      summary: Execute a method synchronously and return its full output.
      description: >
        Blocking. The protocol sets no time limit; deployments cap it at their proxy
        layer. For long-running methods prefer /start. Implementations MAY return
        202 + RunResultStart (id only) with a Location header pointing at an
        implementation-defined status resource when they cannot hold the connection
        open for the full execution (RFC 9110 asynchronous pattern); clients that
        cannot handle 202 should use /start instead. A runner whose /version declares
        run_store true points Location at the run's status read, keeps the run's
        output for its results read, and honours the Idempotency-Key header: the same
        request repeated under a held key is answered with the first answer when the
        runner can give it again, with a 202 naming the run while the run has not
        ended, and with a 409 coded run.answer_not_kept once it has ended and the
        runner kept neither its answer nor its output.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/RunRequest' }
      responses:
        '200':
          description: Method completed; full output included.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/RunResultExecute' }
        '202':
          description: >
            OPTIONAL (implementations MAY emit this; simple runners never do):
            execution continues in the background. The Location header points at an
            implementation-defined status resource, the run's status read on a runner
            that keeps a run store, which also answers a 202 to the same request
            repeated under a held idempotency key while its run has not ended.
          headers:
            Location:
              schema: { type: string }
              description: Implementation-defined status resource for this run, or its status read on a runner that keeps a run store.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/RunResultStart' }
        '409':
          $ref: '#/components/responses/IdempotencyProblem'
        '422':
          $ref: '#/components/responses/ValidationProblem'
        default:
          $ref: '#/components/responses/Problem'
  /start:
    post:
      operationId: startMethod
      tags: [run]
      summary: Start a method asynchronously; returns its pipeline_run_id immediately.
      description: >
        Asynchronous. Returns 202 + RunResultStart immediately (pipeline_run_id only).
        The protocol defines no completion channel: a runner whose /version declares
        run_store true serves the run reads, which a caller polls, and any channel that
        tells a caller a run has finished (callbacks, anything else) is
        implementation-defined and outside the protocol. The returned pipeline_run_id
        is always authoritative (server-generated). A runner that keeps a run store
        honours the Idempotency-Key header: the same request repeated under a held key
        is answered with the first 202, naming the run the first request started, and
        starts nothing.
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/RunRequest' }
      responses:
        '202':
          description: Accepted; execution proceeds in the background. Also the answer to the same request repeated under a held idempotency key once the first request has started its run.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/RunResultStart' }
        '409':
          $ref: '#/components/responses/IdempotencyProblem'
        '422':
          $ref: '#/components/responses/ValidationProblem'
        default:
          $ref: '#/components/responses/Problem'
  /validate:
    post:
      operationId: validateMethod
      tags: [validate]
      summary: Parse, validate, and dry-run an MTHDS bundle.
      description: >
        Diagnostic endpoint. Every verdict the validator can produce — valid or
        invalid — rides a 200, discriminated in the body on is_valid. Non-2xx is
        reserved for the cases where no verdict could be produced (a malformed
        request body, auth, a server fault), so a 422 here is a request-shape
        problem, never "the bundle is invalid".
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ValidateRequest' }
      responses:
        '200':
          description: A produced verdict — valid (ValidationReport) or invalid (InvalidValidationReport), discriminated on is_valid.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ValidationResult' }
        '422':
          $ref: '#/components/responses/ValidationProblem'
        default:
          $ref: '#/components/responses/Problem'
  /models:
    get:
      operationId: listModels
      tags: [discovery]
      summary: The model deck available on this runner.
      parameters:
        - name: type
          in: query
          required: false
          schema:
            type: string
            enum: [llm, extract, img_gen, search, judgment]
          description: >
            Filter the deck by model category. A value outside the enum is a 422: a
            runner MUST NOT accept a category the protocol does not define, so a
            category that a later protocol version adds is a 422 from a runner of an
            earlier one.
      responses:
        '200':
          description: The model deck.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ModelDeck' }
        '422':
          $ref: '#/components/responses/ValidationProblem'
        default:
          $ref: '#/components/responses/Problem'
  /version:
    get:
      operationId: getVersion
      tags: [discovery]
      summary: Protocol and runner versions.
      security: [] # always public — used for handshake/feature detection
      responses:
        '200':
          description: Version info.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/VersionInfo' }
        default:
          $ref: '#/components/responses/Problem'
  /blobs/missing:
    post:
      operationId: findMissingBlobs
      tags: [blobs]
      summary: Which of these blobs the runner lacks, and where to upload each.
      description: >
        OPTIONAL — served by a runner whose /version declares blob_store true. The
        answer lists every blob of the request the runner does not hold, each with an
        upload target; a blob it holds is left out, and an empty list means there is
        nothing to upload. The optional digest names the tree the blobs make up: a
        runner that records the trees it has held in full, recording one only after
        checking it holds every file the tree's listing names and never taking an
        uploaded blob as such a record, MAY answer an empty list when it holds the tree
        that digest names. A hash given twice with different sizes, or a blob past the
        runner's limits, is a 422, refused before anything is uploaded.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/MissingBlobsRequest' }
      responses:
        '200':
          description: The blobs of the request the runner does not hold, each with where to upload it.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/MissingBlobsResult' }
        '422':
          $ref: '#/components/responses/ValidationProblem'
        default:
          $ref: '#/components/responses/Problem'
  /blobs/{sha256}:
    put:
      operationId: putBlob
      tags: [blobs]
      summary: Upload one blob's bytes to a runner that stores them itself.
      description: >
        OPTIONAL — served by a runner that keeps a blob store and stores uploaded
        bytes itself, as the upload target its POST /blobs/missing answers name. The
        body is the blob's bytes and nothing else. A body whose SHA-256 differs from the
        path is a 422. A blob is written once and never changed, so uploading bytes the
        runner already holds succeeds without changing anything.
      parameters:
        - name: sha256
          in: path
          required: true
          schema: { type: string, pattern: '^[0-9a-f]{64}$' }
          description: The SHA-256 of the body, in lowercase hexadecimal.
      requestBody:
        required: true
        content:
          application/octet-stream:
            schema: { type: string, format: binary }
      responses:
        '204':
          description: The blob is stored, now or already.
        '422':
          $ref: '#/components/responses/ValidationProblem'
        default:
          $ref: '#/components/responses/Problem'
  /runs/{pipeline_run_id}/status:
    get:
      operationId: getRunStatus
      tags: [runs]
      summary: A run's status, and its problem once it has failed.
      description: >
        OPTIONAL — served by a runner whose /version declares run_store true. Answers
        200 for every run the caller can read, whatever became of it: a failed run's
        problem rides inside the answer as error rather than failing the read. A
        runner may set Retry-After on the 200 of a run that has not ended, to say when
        to read it again. An id naming no run the caller can read, a run the caller
        may not read included, is a 404 coded run.not_found.
      parameters:
        - $ref: '#/components/parameters/PipelineRunId'
      responses:
        '200':
          description: The run's status, and its problem once it has failed.
          headers:
            Retry-After:
              schema: { type: integer, minimum: 0 }
              description: Seconds to wait before reading a run that has not ended again (optional).
          content:
            application/json:
              schema: { $ref: '#/components/schemas/RunRead' }
        '404':
          $ref: '#/components/responses/RunNotFoundProblem'
        default:
          $ref: '#/components/responses/Problem'
  /runs/{pipeline_run_id}/results:
    get:
      operationId: getRunResults
      tags: [runs]
      summary: A completed run's output, as /execute answers it.
      description: >
        OPTIONAL — served by a runner whose /version declares run_store true. A
        completed run is answered with a 200 whose body is the one /execute answers
        with, its pipeline_run_id and its pipe_output. Any other run is a problem: a
        409 coded run.not_finished before the run has ended, a 409 coded run.failed,
        carrying the run's own problem as run_error, once it has ended without output,
        and a 404 coded run.results_not_stored for a completed run whose output
        travelled in /execute's answer and was not kept. An id naming no run the
        caller can read is a 404 coded run.not_found.
      parameters:
        - $ref: '#/components/parameters/PipelineRunId'
      responses:
        '200':
          description: The completed run's output.
          content:
            application/json:
              schema: { $ref: '#/components/schemas/RunResultExecute' }
        '404':
          description: >
            A problem coded run.not_found, for an id naming no run the caller can read,
            or run.results_not_stored, for a completed run whose output travelled in
            /execute's answer and was not kept. Like every problem response, it always
            carries status.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - required: [status]
        '409':
          description: >
            A problem coded run.not_finished, before the run has ended, with
            retry_after when the runner knows how long to wait, or run.failed, once the
            run has ended without output, carrying the run's own problem as run_error.
            Like every problem response, it always carries status.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - required: [status]
        default:
          $ref: '#/components/responses/Problem'
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: Token semantics are implementation-defined.
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        minLength: 1
        maxLength: 255
        pattern: '^[!-~]+$'
      description: >
        Names the request, so that a runner whose /version declares run_store true runs
        it at most once while it holds the key: a string of visible ASCII characters the
        client chooses and never uses for another request, such as a UUID. The runner
        keeps each key per caller, for at least 24 hours after the first request under
        it, and takes a request under a key it no longer holds as a first request, so
        the protocol promises nothing about a repeat past those 24 hours: a client that
        cannot repeat within them reads the run when it knows its pipeline_run_id, and
        otherwise treats the outcome as unknown and never repeats automatically. The same
        request, the same route with a body of the same JSON value whatever the order
        of its members and its whitespace, repeated under a held key is answered from
        the first execution: a 409 coded request.idempotency_key_in_use while the
        first request is still being handled and has started no run, the first answer
        once it has started its run, and as a first request when the first was refused
        before it started a run, which leaves the key free. A different request under a
        held key is a 409 coded request.idempotency_conflict. A key outside this form
        is a 422 coded request.invalid. A runner that keeps no run store ignores the
        header, so a client repeats a request under its key only against a runner that
        declares run_store true.
    PipelineRunId:
      name: pipeline_run_id
      in: path
      required: true
      schema: { type: string, minLength: 1 }
      description: The run's identifier, as /execute or /start answered it.
  responses:
    Problem:
      description: >
        An RFC 9457 problem document carrying the MTHDS core members. As the body of
        an HTTP response it always carries status, which the shared Problem schema
        leaves optional for a problem kept elsewhere, such as in a run's record.
      content:
        application/problem+json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Problem'
              - required: [status]
    ValidationProblem:
      description: >
        A 422 problem document. On /execute and /start a method that does not
        validate also lands here, one item per fault in errors; on /validate an
        invalid method is a 200 verdict, so there a 422 is about the request alone.
        A request whose files map is not a tree is a 422 naming the offending path,
        and a request whose files map breaks no other rule but names a hash entry the
        runner does not hold, or any hash entry when it keeps no blob store, is a 422
        coded request.blobs_missing whose params.missing_blobs lists each such hash. Like every problem response, it
        always carries status.
      content:
        application/problem+json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Problem'
              - required: [status]
    IdempotencyProblem:
      description: >
        A 409 problem about the request's Idempotency-Key, answered only by a runner
        whose /version declares run_store true: request.idempotency_conflict for a
        different request under a held key; request.idempotency_key_in_use for the same
        request while the first one is still being handled and has started no run,
        with retry_after when the runner knows how long to wait; and, on /execute,
        run.answer_not_kept for the same request once its run has ended and the runner
        kept neither its answer nor its output. Like every problem response, it always
        carries status.
      content:
        application/problem+json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Problem'
              - required: [status]
    RunNotFoundProblem:
      description: >
        A 404 problem coded run.not_found: the id names no run the caller can read. A
        runner answers an id naming a run the caller may not read exactly as one naming
        no run, so an id never tells a caller about a run it cannot read. Like every
        problem response, it always carries status.
      content:
        application/problem+json:
          schema:
            allOf:
              - $ref: '#/components/schemas/Problem'
              - required: [status]
  schemas:
    RunRequest:
      type: object
      description: >
        At least one of pipe_code / files is required (enforced by the anyOf rule
        below). If files is provided without pipe_code, the run starts at the
        manifest's main_pipe when the tree holds a METHODS.toml at its root, or else,
        in a method with no manifest, at the one main_pipe its bundles declare; a tree
        whose manifest declares none, or with no manifest whose bundles declare none
        or several, is a 422 naming its bundles by their tree paths. Extension-open:
        implementations MAY accept extra top-level properties (extension args).
      additionalProperties: true
      anyOf:
        - required: [pipe_code]
          properties:
            pipe_code: { type: string, minLength: 1 }
        - required: [files]
          properties:
            files: { $ref: '#/components/schemas/MethodFiles' }
      properties:
        pipe_code:
          type: [string, 'null']
          description: Code of the pipe to execute (a pipe the runner already holds, or one defined in a bundle of files).
        files:
          description: The method to load, as its whole method tree. Implementations bound a file's size, the tree's file count and total size, and the total of the inline entries.
          anyOf:
            - $ref: '#/components/schemas/MethodFiles'
            - type: 'null'
        inputs:
          type: [object, 'null']
          description: 'Method inputs: map of input name to { concept, content }. Content shapes follow the concept''s structure; content validation is deliberately loose here and strict inside the runtime.'
          additionalProperties:
            type: object
            required: [concept, content]
            properties:
              concept: { type: string }
              content: {}
        output_name:
          type: [string, 'null']
          description: Name of the output slot to return as the main output.
        output_multiplicity:
          oneOf: [{ type: boolean }, { type: integer }, { type: 'null' }]
          description: Output multiplicity override (false/true or an explicit count).
        dynamic_output_concept_ref:
          type: [string, 'null']
          description: Override for the dynamic output concept reference.
    RunResultExecute:
      type: object
      description: >
        POST /execute 200 — the completed run, and the 200 of the results read of a
        runner that keeps a run store, which answers a completed run with the body
        /execute answers with. Two base fields: the
        server-generated authoritative pipeline_run_id and the method's
        pipe_output (always present — a completed run has output, either a value
        or an explicit absence document). Extension-open:
        anything more an implementation returns (a run state, timestamps, output
        naming) is an extension on top.
      additionalProperties: true
      required: [pipeline_run_id, pipe_output]
      properties:
        pipeline_run_id:
          type: string
          description: The run identifier — server-generated and authoritative.
        pipe_output:
          description: The method's serialized output (working memory of serialized stuffs).
          type: object
    RunResultStart:
      type: object
      description: >
        POST /start 202 (and the optional /execute 202 degrade) — the started
        run's authoritative pipeline_run_id, nothing else. A started run has no
        output yet. A runner that keeps a run store serves it through the results
        read once the run has completed; any other way it is delivered (callbacks,
        anything else) is implementation-defined and outside the protocol.
        Extension-open.
      additionalProperties: true
      required: [pipeline_run_id]
      properties:
        pipeline_run_id:
          type: string
          description: The run identifier — server-generated and authoritative.
    RunRead:
      type: object
      description: >
        The 200 of the status read of a runner that keeps a run store: the run's id,
        its status, and its problem once it has failed. Extension-open; an unset member
        is left out, never written as null.
      required: [pipeline_run_id, status]
      additionalProperties: true
      properties:
        pipeline_run_id:
          type: string
          description: The run identifier, as /execute or /start answered it.
        status: { $ref: '#/components/schemas/RunStatus' }
        error:
          $ref: '#/components/schemas/Problem'
          description: >
            The run's own problem, as the run's record keeps it, without status since it
            is not the body of a response. Present exactly when status is failed; its
            code says why the run ended without output, such as run.cancelled,
            run.timed_out or run.lost.
    RunStatus:
      type: string
      enum: [pending, running, completed, failed]
      description: >
        Where a run is in its life. pending: accepted, not yet executing. running:
        executing. completed: ended with its output, which the results read serves.
        failed: ended without output, its problem in the read's error. The statuses of
        a run that has ended are closed, completed and failed, and a later protocol
        version may add a status only for a run that has not ended. A runner MUST NOT
        emit a value outside this enum; a reader that meets one it does not know reads
        the run as not ended and reads it again later, and a client that derives its
        types from this document widens the field to any string.
    ValidateRequest:
      type: object
      required: [files]
      properties:
        files:
          $ref: '#/components/schemas/MethodFiles'
          description: The method to validate, as its whole method tree; the runner judges every bundle and every file a bundle names.
        allow_signatures:
          type: boolean
          default: false
          description: When true, the validation sweep tolerates unimplemented pipe signatures (signatures dry-run by minting a mock). Strict by default.
    ValidationResult:
      description: >
        The 200 response of POST /validate — a produced verdict discriminated on
        the mandatory is_valid field. A client pattern-matches is_valid to learn
        the verdict; it never inspects a status code or catches an exception body.
        Non-2xx is a no-verdict condition (a request-shape problem, auth, a server
        fault), never an invalid bundle.
      oneOf:
        - $ref: '#/components/schemas/ValidationReport'
        - $ref: '#/components/schemas/InvalidValidationReport'
    ValidationReport:
      type: object
      description: >
        The is_valid:true arm of the validate response — the bundle is valid. The
        protocol declares only the is_valid discriminant, the runnability facts and
        the advisory warnings; implementations MAY include their own artifacts
        (parsed structures, graphs, anything else) as additional properties.
      required: [is_valid, is_runnable, pending_signatures]
      additionalProperties: true
      properties:
        is_valid:
          type: boolean
          enum: [true]
          description: Discriminant — the bundle is valid.
        is_runnable:
          type: boolean
          description: >
            Whether the validated library is complete enough to run — false when
            pipe signatures remain unimplemented (a runnability fact, not an error).
        pending_signatures:
          type: array
          items: { type: string }
          description: Refs of pipes still declared as unimplemented signatures.
        warnings:
          type: array
          items: { $ref: '#/components/schemas/ProblemItem' }
          description: >
            Advisory findings, one problem item each, which never make the bundle
            invalid. Absent or empty when there are none. An unset member of an item is
            left out, never written as null, as in errors.
    InvalidValidationReport:
      type: object
      description: >
        The is_valid:false arm of the validate response — the bundle is invalid. An
        invalid bundle is the successful product of a diagnostic call, not a
        transport failure, so it rides a 200. The structural artifacts of a valid
        report do not exist when load/parse/wiring failed, so this arm carries the
        faults, the advisory warnings and the runnability facts only.
      required: [is_valid, errors, is_runnable]
      additionalProperties: true
      properties:
        is_valid:
          type: boolean
          enum: [false]
          description: Discriminant — the bundle is invalid.
        errors:
          type: array
          minItems: 1
          items: { $ref: '#/components/schemas/ProblemItem' }
          description: >
            One problem item per fault, each with its own code, detail, params and
            location — non-empty on every invalid verdict. An unset member of an item
            is left out, never written as null.
        warnings:
          type: array
          items: { $ref: '#/components/schemas/ProblemItem' }
          description: >
            Advisory findings in the same item schema, which do not make the verdict
            invalid. Absent or empty when there are none.
        pending_signatures:
          type: array
          items: { type: string }
          description: Outstanding signatures (best-effort; empty when no library could be assembled).
        is_runnable:
          type: boolean
          enum: [false]
          description: An invalid bundle is never runnable.
        message:
          type: string
          description: Human-readable summary of the verdict.
    ModelDeck:
      type: object
      description: >
        The models this runner can route to. Implementations MAY add their own
        routing metadata (aliases, fallback chains, anything else) as
        additional properties — on the deck and on each model entry. A model of a
        family the protocol does not define, such as a vendor's own operator, is
        reported, if at all, under an extension property of the runner's choosing,
        never under an invented category and never as an entry of models without
        one.
      additionalProperties: true
      properties:
        models:
          type: array
          items:
            type: object
            additionalProperties: true
            properties:
              name: { type: string }
              type:
                type: string
                enum: [llm, extract, img_gen, search, judgment]
                description: >
                  The model's category: the inline settings family of the language
                  that the model serves, and so the pipes that can name it, as the
                  table under "Model categories" on the protocol page states. A
                  runner MUST NOT emit a value outside this enum. A client reading a
                  model list MUST NOT fail it because an entry carries a category it
                  does not recognize; it keeps that entry with its raw value or
                  leaves it out. The enum is the emitter's contract: a client that
                  derives its types or its validation from this document widens
                  this field to any string.
    VersionInfo:
      type: object
      description: >
        The handshake. The protocol defines protocol_version (required) plus an
        optional runner_version and the optional blob_store and run_store flags;
        implementations MAY add their own identification (a name, an underlying
        runtime version, anything else) as additional properties.
      required: [protocol_version]
      additionalProperties: true
      properties:
        protocol_version: { type: string, description: MTHDS Protocol version implemented. }
        runner_version: { type: [string, 'null'], description: Version of the runner serving this protocol (optional). }
        blob_store:
          type: boolean
          default: false
          description: >
            True when the runner keeps a blob store: it serves POST /blobs/missing and
            resolves hash entries in a files map. False or absent when it does not, in
            which case it answers a files map that breaks no other rule but holds hash
            entries with a 422 coded request.blobs_missing, listing their hashes in
            params.missing_blobs, and serves no upload route, so a sender sends those
            files inline instead.
        run_store:
          type: boolean
          default: false
          description: >
            True when the runner keeps a run store: it records every run it starts,
            serves GET /runs/{pipeline_run_id}/status and GET
            /runs/{pipeline_run_id}/results, and honours the Idempotency-Key header on
            /execute and /start. False or absent when it does not, in which case it
            serves neither read and ignores the header, so a client neither reads a run
            after the fact nor repeats a request under its key.
    MethodFiles:
      type: object
      description: >
        A method tree, as a map from tree path to file entry, holding every file of the
        tree. Each key is a tree path: a relative POSIX path already in Unicode NFC
        (a key that is not is refused, never normalized), with no
        empty, '.' or '..' segment, no segment starting with a dot, no backslash, colon
        or control character, at most 255 UTF-8 bytes per segment and 1024 for the
        path; no segment names a __pycache__ or node_modules directory, no key names
        a file called pyvenv.cfg, inputs.json or inputs.toml (a run's inputs file),
        and no key names a file called METHODS.toml anywhere but at the root, which
        the membership rule never admits. No key is given
        twice, as written or once its JSON escapes are decoded. No two keys collide,
        and no key collides with a directory of another, under Unicode full case
        folding (the entries of status C and F in the CaseFolding.txt of Unicode 14.0
        or later, with no locale tailoring) of the key in NFC, normalized to NFC
        again, so neither README.md
        and readme.md, nor straße.txt and STRASSE.txt, nor Templates and
        templates/letter.html share one map. As the method tree's file entry rules
        state, the collision check reads only the keys that are tree paths the
        membership rule could admit, and reads a key given twice once, so a map
        holding inputs.json beside Inputs.json is refused naming inputs.json alone,
        never because the two collide. The pattern below checks the
        characters and segments; the other rules are checked by the runner, which
        answers a map breaking any of them with a 422 naming the path.
      minProperties: 1
      propertyNames:
        pattern: '^[^/\\:\x00-\x1F\x7F-\x9F.][^/\\:\x00-\x1F\x7F-\x9F]*(/[^/\\:\x00-\x1F\x7F-\x9F.][^/\\:\x00-\x1F\x7F-\x9F]*)*$'
        maxLength: 1024
      additionalProperties: { $ref: '#/components/schemas/FileEntry' }
    FileEntry:
      description: >
        One file of a method tree: its text, its bytes in Base64, or the hash of bytes
        the runner already holds. There is no URL form, and an entry object that
        gives one of its keys twice is refused, as a key given twice in the map is.
        A runner holds an entry to this schema, and to the other entry checks of the
        method tree's file entry rules, only under a key that is a tree path the
        membership rule could admit: a map holding any other key is refused for that
        key, whatever its entry holds.
      oneOf:
        - type: string
          description: The file's text. Its bytes are the UTF-8 encoding of this string, exactly.
        - $ref: '#/components/schemas/Base64FileEntry'
        - $ref: '#/components/schemas/HashFileEntry'
    Base64FileEntry:
      type: object
      description: >
        Any bytes, in the standard Base64 alphabet of RFC 4648, padded, with no line
        breaks, and canonical as RFC 4648 section 3.5 defines it: an encoding whose
        pad bits are not zero is not valid Base64 and is refused.
      required: [base64]
      additionalProperties: false
      properties:
        base64: { type: string, contentEncoding: base64 }
    HashFileEntry:
      type: object
      description: >
        Bytes the runner already holds in its blob store, named by their SHA-256 and
        their length. A runner that does not hold them, holds them with another size,
        or keeps no blob store answers a files map that breaks no other rule with a
        422 coded request.blobs_missing, listing the hashes in params.missing_blobs.
        The sender then uploads each listed blob to a runner that keeps a blob store,
        and sends each listed file inline to one that keeps none. As the method
        tree's file entry rules state, the runner checks these bytes last and only
        under a key that is a tree path the membership rule could admit, so a map it
        refuses for any other fault is refused for that fault, and a sender never
        uploads blobs for a map that would be refused anyway.
      required: [sha256, size]
      additionalProperties: false
      properties:
        sha256: { type: string, pattern: '^[0-9a-f]{64}$', description: The SHA-256 of the bytes, in lowercase hexadecimal. }
        size:
          type: integer
          minimum: 0
          description: >
            The length of the bytes, a JSON integer written without a fraction or an
            exponent. A size written 13.0 is refused, although JSON Schema's integer
            type admits it.
    BlobRef:
      type: object
      description: A blob, named by its SHA-256 in lowercase hexadecimal and its length in bytes.
      required: [sha256, size]
      additionalProperties: false
      properties:
        sha256: { type: string, pattern: '^[0-9a-f]{64}$' }
        size:
          type: integer
          minimum: 0
          description: >
            The length of the bytes, a JSON integer written without a fraction or an
            exponent. A size written 13.0 is refused, although JSON Schema's integer
            type admits it.
    MissingBlobsRequest:
      type: object
      description: The blobs a sender is about to send by hash, and optionally the tree they make up.
      required: [blobs]
      additionalProperties: true
      properties:
        blobs:
          type: array
          items: { $ref: '#/components/schemas/BlobRef' }
          description: The blobs to check, each hash listed once.
        digest:
          type: string
          pattern: '^sha256:[0-9a-f]{64}$'
          description: The tree digest of the method tree the blobs make up (optional).
    MissingBlobsResult:
      type: object
      description: The blobs of the request the runner does not hold. Extension-open.
      required: [missing]
      additionalProperties: true
      properties:
        missing:
          type: array
          items: { $ref: '#/components/schemas/MissingBlob' }
    MissingBlob:
      type: object
      description: A blob the runner lacks, with where to upload it.
      required: [sha256, size, upload]
      additionalProperties: true
      properties:
        sha256: { type: string, pattern: '^[0-9a-f]{64}$' }
        size:
          type: integer
          minimum: 0
          description: >
            The length of the bytes, a JSON integer written without a fraction or an
            exponent. A size written 13.0 is refused, although JSON Schema's integer
            type admits it.
        upload: { $ref: '#/components/schemas/UploadTarget' }
    UploadTarget:
      type: object
      description: >
        Where to upload one blob. The sender sends the blob's bytes as the whole body of
        a request with this method to this URL, carrying exactly these headers. The
        target is the runner's choice: its own PUT /blobs/{sha256}, or any address that
        stores the bytes where the runner reads its blobs.
      required: [method, url, headers]
      additionalProperties: true
      properties:
        method: { type: string, description: 'The HTTP method, such as PUT.' }
        url: { type: string, format: uri }
        headers:
          type: object
          additionalProperties: { type: string }
          description: The headers to send, exactly.
    Problem:
      type: object
      description: >
        An RFC 9457 problem document carrying the MTHDS core members. type, title,
        status and detail are the RFC's; code, domain, retry, retry_after, next_step,
        params, location, errors, pipeline_run_id and run_error are the core's. The code decides:
        its domain, its retry verdict, its next step, its title and its HTTP status are
        properties of the code, carried on the wire so that a reader needs no lookup,
        and two cases that need different verdicts are two codes. Closed for emitters,
        open for readers: a runner emits only registered codes and the listed values,
        every schema of the document accepts members it does not know, and a reader
        ignores them, as RFC 9457 requires. A reader that meets a code, a domain or a
        step kind it does not know reads it by the code's family, then as the domain
        runtime and the step report. A member with no value is left out, never written
        as null, and no member carries the content of a run's inputs or outputs.
      required: [type, title, detail, code, domain, retry, next_step]
      additionalProperties: true
      properties:
        type:
          type: string
          format: uri
          description: >
            The code's documentation page, derived from the code and its owner's base
            URL: https://mthds.ai/errors/<code> for a core code, and for an extension
            code the base URL its prefix is registered with, a slash and the whole code.
            It names what code names, one to one; a client branches on code.
        title:
          type: string
          description: The code's short title, the same for every occurrence of the code.
        status:
          type: integer
          minimum: 100
          maximum: 599
          description: >
            The HTTP status of the response this problem is the body of. A runner sets
            it on every response, so the problem responses of this document require it;
            a problem kept elsewhere, such as in a run's record, leaves it out.
        detail:
          type: string
          description: >
            This occurrence, in one or two sentences a person can read. A client never
            parses it: every fact it states is in params or location.
        code: { $ref: '#/components/schemas/ProblemCode' }
        domain: { $ref: '#/components/schemas/ProblemDomain' }
        retry: { $ref: '#/components/schemas/RetryVerdict' }
        retry_after:
          type: number
          minimum: 0
          description: >
            Seconds to wait before repeating the operation, when known. Set only beside
            a retry of yes.
        next_step: { $ref: '#/components/schemas/NextStep' }
        params: { $ref: '#/components/schemas/ProblemParams' }
        location: { $ref: '#/components/schemas/ProblemLocation' }
        errors:
          type: array
          minItems: 1
          items: { $ref: '#/components/schemas/ProblemItem' }
          description: >
            One item per fault, for a problem with several, such as a method that does
            not validate. Absent when the problem has a single fault.
        pipeline_run_id:
          type: string
          description: >
            The run the error belongs to, as /execute and /start name it. Present when a
            run exists.
        run_error:
          $ref: '#/components/schemas/Problem'
          description: >
            The run's own problem, nested, on the problem coded run.failed that the
            results read of a runner keeping a run store answers for a run that ended
            without output. It is the problem the run's record keeps, without status,
            and it says why the run failed, while the problem holding it is about the
            read. Absent on every other problem.
    ProblemCode:
      type: string
      pattern: '^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*){1,2}$'
      description: >
        A registry code, lowercase and dotted, each segment matching [a-z][a-z0-9_]*. A
        core code is bare, exactly a family and a name, such as input.missing. Every
        other code starts with the prefix its owner registers, then a family and a name,
        such as acme.billing.credit_exhausted. A code's family is the code without its
        last segment. The pattern is the code's shape; which codes exist is the
        registries', so a new code moves no protocol number.
    ProblemDomain:
      type: string
      enum: [input, method, account, operator, runtime]
      description: >
        Who must act: input, the caller, by changing the request or its inputs;
        method, the method's author, by changing the method; account, the account's
        owner; operator, whoever runs the runtime; runtime, nobody beforehand, so wait,
        retry or report. A runner MUST NOT emit a value outside this enum. A reader
        that meets one it does not know reads the domain of the code's family, then
        runtime; a client that derives its types from this document widens the field
        to any string.
    RetryVerdict:
      type: string
      enum: ['no', 'yes', outcome_unknown]
      description: >
        Whether repeating the operation that produced the problem can succeed. no:
        repeating it fails the same way. yes: repeating it may succeed, after
        retry_after when it is given. outcome_unknown: the operation may already have
        taken effect, so a client never repeats it automatically and follows the next
        step to learn its outcome first. On a run's own problem the operation is the
        run, so yes means that a new run with the same inputs may succeed. A runner
        MUST NOT emit a value outside this enum; a reader that meets one it does not
        know reads it as no and repeats nothing on a guess.
    NextStep:
      type: object
      description: >
        What the reader should do next, aimed at whoever reads the problem: each code
        declares a step for its domain's actor and one for any other reader.
        Extension-open.
      required: [kind, detail]
      additionalProperties: true
      properties:
        kind: { $ref: '#/components/schemas/StepKind' }
        detail:
          type: string
          description: The step, in one sentence a person can read.
    StepKind:
      type: string
      enum:
        - retry
        - wait
        - read_run
        - refresh
        - change_input
        - change_method
        - change_model
        - check_credentials
        - request_access
        - check_account
        - fix_configuration
        - upgrade
        - contact_owner
        - report
      description: >
        The closed list of next steps, as the table under "Next steps" on the protocol
        page defines them: retry the operation; wait and check again later; read_run,
        read the run to learn its outcome; refresh, fetch the latest state, such as a
        fresh credential, and apply the change again; change_input, change the request
        or its inputs, supplying the files a runner lacks, uploaded or inline, included;
        change_method; change_model;
        check_credentials; request_access; check_account, its credit, plan or quotas;
        fix_configuration, the runtime's; upgrade, the client or the runtime;
        contact_owner, the owner of the method or of the account; report, with the
        identifiers the problem carries. A runner MUST NOT emit a value outside this
        enum. A reader that meets one it does not know reads the step of the code's
        family, then report; a client that derives its types from this document widens
        the field to any string.
    ProblemParams:
      type: object
      additionalProperties: true
      description: >
        The typed facts the problem's sentences were written from, so that a client
        acts on data rather than on prose. Each code declares its parameters and their
        types in its registry, the core's being mthds-error-registry.yaml beside this
        document; the member is present when the code declares any. A parameter holds
        an identifier, a number or an enumerated value, or, where its code declares so,
        the caller's own text, never the content of a run's inputs or outputs. The
        parameters a client relies on by shape are typed here, as the core registry
        types them.
      properties:
        missing_blobs:
          type: array
          items:
            type: string
            pattern: '^[0-9a-f]{64}$'
          description: >
            Carried by the protocol's own refusal of hash entries, request.blobs_missing:
            every hash the request's files map names that the runner does not hold, in
            lowercase hexadecimal, for a map that breaks no other rule.
    ProblemLocation:
      type: object
      additionalProperties: true
      description: >
        Where the error happened, in the method, the request or the run. Every member
        is optional, and the member is present when the error has a place. The location
        of a run's problem is its root fault's, so it names the pipe that failed rather
        than the controller around it.
      properties:
        pipe:
          type: string
          description: The failing pipe's code.
        path:
          type: array
          items: { type: string }
          description: The pipe codes from the run's main pipe down to the failing one.
        input:
          type: string
          description: The name of the input the error concerns.
        field:
          type: string
          description: A dotted path inside an input or a request body.
        item:
          type: integer
          minimum: 0
          description: The index of the batch item that failed, counted from 0.
        attempt:
          type: integer
          minimum: 1
          description: The attempt that failed, counted from 1.
        file:
          type: string
          description: The tree path of the method's file the error is in.
        line:
          type: integer
          minimum: 1
          description: The line in file, counted from 1.
        column:
          type: integer
          minimum: 1
          description: The column in line, counted from 1.
    ProblemItem:
      type: object
      description: >
        One fault of a problem with several, as an item of a problem's errors, and the
        schema of a validate verdict's errors and warnings. An item carries its own
        code but no verdict: the problem or the verdict holding it does, and a reader
        that needs an item's domain reads it from the item's code. Extension-open; an
        unset member is left out, never written as null.
      required: [code, detail]
      additionalProperties: true
      properties:
        code: { $ref: '#/components/schemas/ProblemCode' }
        detail:
          type: string
          description: This fault, in one or two sentences a person can read.
        params: { $ref: '#/components/schemas/ProblemParams' }
        location: { $ref: '#/components/schemas/ProblemLocation' }
        suggestions:
          type: array
          items: { type: string }
          description: The names a near miss most likely meant, the likeliest first.
        suggested_fix: { $ref: '#/components/schemas/SuggestedFix' }
    SuggestedFix:
      type: object
      description: >
        A deterministic fix for one fault: a semantic patch over a bundle of the
        method, a list of operations addressed by TOML key path rather than a text
        diff. The operations are the contract; any diff an applier renders from them is
        presentation. They apply in order, each to the document the previous one left.
        A deletion, a rename, a move or a remap whose target is absent is skipped.
        ensure_table creates its table when it is absent, and set_key creates its key
        when the table does not hold it, but a set_key whose table is absent, or an
        ensure_table whose parent table is absent, is skipped, so a fix that writes into
        a table that may be missing puts an ensure_table before the operations that
        need it, one for each level that may be missing, the outermost first. An
        operation already in the state it would produce is skipped too. One that could
        only proceed by overwriting a key or a table other than its own target, such as
        a rename or a move onto a key its destination table already holds, is a
        conflict and changes nothing. Rewriting its own target is no conflict, so
        set_key replaces a scalar or array value its key holds and remap_value rewrites
        its value by design, but a set_key whose key holds a table is a conflict, and so
        is an ensure_table whose table_path names a value other than a table. An
        applier reports both rather than forcing the change, and one that meets an
        operation kind it does not know applies none of the fix. Extension-open.
      required: [fix_code, description, safety, ops]
      additionalProperties: true
      properties:
        fix_code:
          type: string
          pattern: '^[a-z0-9]+(-[a-z0-9]+)*$'
          description: The implementation's kebab-case name for the rule that produced the fix, such as match-sequence-output.
        description:
          type: string
          description: What the fix does, in one sentence a person can read.
        safety:
          type: string
          enum: [safe, unsafe]
          description: >
            safe: the fix may be applied without asking anyone. unsafe: a likely
            correction that a person or an agent confirms before it is applied. A
            reader that meets a value it does not know reads it as unsafe.
        file:
          type: string
          description: >
            The tree path of the bundle the operations patch. When absent, they patch
            the file the item's location names.
        ops:
          type: array
          minItems: 1
          items: { $ref: '#/components/schemas/FixOp' }
    FixOp:
      description: >
        One operation of a suggested fix, whose kind selects its variant. table_path
        addresses a table of the bundle as its key path from the document root, each
        segment one key as written, and is empty for the root table. Each known
        operation fixes kind to a one-value enum, as ValidationResult's arms fix
        is_valid, and UnknownFixOp takes every other string, so an operation's kind
        leaves exactly one variant it can match. A runner emits only the kinds
        UnknownFixOp's kind excludes, which is the one list of the known kinds. The
        union is open for readers: an operation whose kind is none of them matches
        UnknownFixOp, the reader-side catch-all that no runner emits, so the fix, its
        item and the problem or verdict holding them still validate, and an applier
        applies none of that fix. The union carries no discriminator object, because a
        discriminator rejects a kind its mapping does not name and so would defeat that
        catch-all. A client that derives its types or its validation from this document
        matches the variants on kind as this oneOf does and keeps that catch-all, rather
        than closing the union on the kinds it lists.
      oneOf:
        - $ref: '#/components/schemas/SetKeyOp'
        - $ref: '#/components/schemas/EnsureTableOp'
        - $ref: '#/components/schemas/DeleteKeyOp'
        - $ref: '#/components/schemas/DeleteTableOp'
        - $ref: '#/components/schemas/RenameTableKeyOp'
        - $ref: '#/components/schemas/MoveKeyOp'
        - $ref: '#/components/schemas/RemapValueOp'
        - $ref: '#/components/schemas/UnknownFixOp'
    TablePath:
      type: array
      items: { type: string }
      description: A table's key path from the document root, each segment one key as written.
    TomlValue:
      description: A value set_key writes, a TOML scalar or an inline table of scalars.
      anyOf:
        - type: string
        - type: number
        - type: boolean
        - type: object
          additionalProperties:
            anyOf:
              - type: string
              - type: number
              - type: boolean
    SetKeyOp:
      type: object
      description: >
        Write key = value in the table at table_path, creating the key when the table
        does not hold it and replacing a scalar or array value the key holds. When the
        key holds a table, the operation is a conflict and changes nothing. When the
        table at table_path is absent, the operation is skipped, so a fix that needs
        that table puts an ensure_table before it.
      required: [kind, table_path, key, value]
      additionalProperties: true
      properties:
        kind: { type: string, enum: [set_key] }
        table_path: { $ref: '#/components/schemas/TablePath' }
        key: { type: string }
        value: { $ref: '#/components/schemas/TomlValue' }
    EnsureTableOp:
      type: object
      description: >
        Create the table at table_path when it is absent, leaving an existing one
        untouched. When the table above it is absent too, the operation is skipped, and
        when table_path names a value other than a table, it is a conflict and changes
        nothing. table_path names the table itself, so it is never empty.
      required: [kind, table_path]
      additionalProperties: true
      properties:
        kind: { type: string, enum: [ensure_table] }
        table_path:
          type: array
          minItems: 1
          items: { type: string }
          description: The key path of the table itself, from the document root.
    DeleteKeyOp:
      type: object
      description: Remove key from the table at table_path, skipped when the key or its table is absent.
      required: [kind, table_path, key]
      additionalProperties: true
      properties:
        kind: { type: string, enum: [delete_key] }
        table_path: { $ref: '#/components/schemas/TablePath' }
        key: { type: string }
    DeleteTableOp:
      type: object
      description: >
        Remove the table at table_path, every part of it included, skipped when the
        table is absent. table_path names the table itself, so it is never empty: the
        root table is never removed.
      required: [kind, table_path]
      additionalProperties: true
      properties:
        kind: { type: string, enum: [delete_table] }
        table_path:
          type: array
          minItems: 1
          items: { type: string }
          description: The key path of the table itself, from the document root.
    RenameTableKeyOp:
      type: object
      description: Rename key to new_key within the table at table_path, keeping its value and its position, skipped when the key or its table is absent.
      required: [kind, table_path, key, new_key]
      additionalProperties: true
      properties:
        kind: { type: string, enum: [rename_table_key] }
        table_path: { $ref: '#/components/schemas/TablePath' }
        key: { type: string }
        new_key: { type: string }
    MoveKeyOp:
      type: object
      description: >
        Move key, with its whole value, from the table at table_path into the table at
        new_table_path under new_key, creating the destination tables that do not
        exist. Skipped when the key or the table at table_path is absent.
      required: [kind, table_path, key, new_table_path, new_key]
      additionalProperties: true
      properties:
        kind: { type: string, enum: [move_key] }
        table_path: { $ref: '#/components/schemas/TablePath' }
        key: { type: string }
        new_table_path: { $ref: '#/components/schemas/TablePath' }
        new_key: { type: string }
    RemapValueOp:
      type: object
      description: >
        Rewrite the string value of key in the table at table_path through mapping,
        from an old value to its new one, doing nothing when the value is not a key of
        the mapping, and skipped when the key or its table is absent. It rewrites its
        own target by design, which is never a conflict.
      required: [kind, table_path, key, mapping]
      additionalProperties: true
      properties:
        kind: { type: string, enum: [remap_value] }
        table_path: { $ref: '#/components/schemas/TablePath' }
        key: { type: string }
        mapping:
          type: object
          minProperties: 1
          additionalProperties: { type: string }
    UnknownFixOp:
      type: object
      description: >
        The reader-side catch-all of FixOp: an operation whose kind is a string none of
        the kinds this document lists, such as one a later protocol version adds. No
        runner emits it. It lets a reader validate a fix holding an operation of a kind
        it does not know, and an applier that meets it applies none of the fix. Its kind
        excludes exactly the kinds FixOp's other variants fix, and this enum is the
        only list of them in the document: a kind the protocol adds takes a new variant
        of FixOp and joins this enum, the one place its name must be added.
      required: [kind]
      additionalProperties: true
      properties:
        kind:
          type: string
          not:
            enum: [set_key, ensure_table, delete_key, delete_table, rename_table_key, move_key, remap_value]
