{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agenticdecks.com/schemas/v1/deckrun-job-status.json",
  "$comment": "© 2026 Agentic Decks. Publicly readable. Not open source. See https://agenticdecks.com/schemas for usage terms.",
  "title": "Deckrun job status",
  "description": "Response shape for job status: sync/async generate, GET /jobs/{id}, and queued responses. Supports queue visibility (queue_position, estimated_wait_seconds) and terminal statuses (success, failure, timeout, cancelled). Returned exclusively by the bouncer. Workers emit internal result payloads and billable_units, which are normalized into this shape.",
  "type": "object",
  "required": ["job_id", "status"],
  "properties": {
    "job_id": {
      "type": "string",
      "description": "Bouncer-assigned job identifier. Stable for polling and idempotency."
    },
    "status": {
      "type": "string",
      "enum": ["queued", "in-flight", "success", "failure", "timeout", "cancelled"],
      "description": "queued = not yet assigned to a worker; in-flight = assigned, not yet terminal; success|failure|timeout|cancelled = terminal."
    },
    "queue_position": {
      "type": "integer",
      "minimum": 0,
      "description": "Present when status is 'queued'. 1-based position in queue; agents can use this for backoff or progress."
    },
    "estimated_wait_seconds": {
      "type": "number",
      "minimum": 0,
      "description": "Present when status is 'queued'. Rough estimate in seconds; helps agents poll less aggressively."
    },
    "result": {
      "type": "object",
      "description": "Present when status is 'success'. Artifact URLs (pdf_url, zip_url, output_url, output_path, slack_message_url, video_url, notes_*, audio_url, manifest_url). When output_bundle was zip, exactly one of zip_url or output_url. When output sent to connector: output_url (remote storage), output_path (filesystem), or slack_message_url (Slack). Connector object names are timestamped.",
      "properties": {
        "pdf_url": { "type": "string", "format": "uri-reference", "description": "Legacy; transient artifact URL when no connector." },
        "zip_url": { "type": "string", "format": "uri-reference", "description": "When output_bundle was zip and response delivery." },
        "output_url": { "type": "string", "format": "uri-reference", "description": "When output_destination was a remote storage connector; URL in that store." },
        "output_path": { "type": "string", "description": "When output_destination was filesystem; server-local path where file(s) were written (e.g. volume or NFS)." },
        "slack_message_url": { "type": "string", "format": "uri-reference", "description": "When output_destination was slack; message permalink." },
        "notes_html_url": { "type": "string", "format": "uri-reference" },
        "notes_text_url": { "type": "string", "format": "uri-reference" },
        "audio_url": { "type": "string", "format": "uri-reference" },
        "video_url": { "type": "string", "format": "uri-reference" },
        "manifest_url": { "type": "string", "format": "uri-reference" },
        "render_units": {
          "type": "object",
          "description": "Render Unit breakdown for this job. Present when the worker computed it (v1+). Omitted for legacy or connector-only jobs.",
          "properties": {
            "logical_units": { "type": "integer", "minimum": 0, "description": "Logical pages or slides in the input document." },
            "base_ru": { "type": "number", "minimum": 0, "description": "Base RU: logical_units × base_ru_per_logical_unit from live-infra-costs.json." },
            "output_contributions": {
              "type": "array",
              "description": "Per-output-type RU contributions: each element is [output_type, ru_amount].",
              "items": { "type": "array", "minItems": 2, "maxItems": 2, "prefixItems": [{ "type": "string" }, { "type": "number" }] }
            },
            "cache_discount": { "type": "number", "description": "RU discount applied when caching discount is enabled." },
            "subtotal": { "type": "number", "minimum": 0, "description": "base_ru + sum(output_contributions) − cache_discount." },
            "minimum_applied": { "type": "boolean", "description": "True when total_ru was raised to the minimum_job_ru floor." },
            "total_ru": { "type": "integer", "minimum": 0, "description": "Final RU charged for this job (ceil of subtotal, at least minimum_job_ru)." }
          },
          "required": ["logical_units", "base_ru", "subtotal", "minimum_applied", "total_ru"],
          "additionalProperties": false
        }
      },
      "additionalProperties": true
    },
    "error": {
      "type": "object",
      "description": "Present when status is 'failure' or 'timeout'. code and message for client handling.",
      "required": ["code", "message"],
      "properties": {
        "code": { "type": "string" },
        "message": { "type": "string" }
      },
      "additionalProperties": false
    },
    "idempotency_key": {
      "type": "string",
      "description": "Echo of Idempotency-Key request header when provided."
    },
    "idempotency_status": {
      "type": "string",
      "enum": ["new", "replay", "in-flight", "completed"],
      "description": "Idempotency-Status: new = first request with this key; replay = returning cached; in-flight = same key, job running; completed = same key, terminal result returned."
    },
    "request_id": {
      "type": "string",
      "description": "Echo of X-Request-Id (bouncer-generated if client did not send). For tracing and logs."
    },
    "started_at": {
      "type": "string",
      "format": "date-time",
      "description": "Optional. When the job started (worker picked up). Useful for billing audits, UI timelines, SLA debugging."
    },
    "completed_at": {
      "type": "string",
      "format": "date-time",
      "description": "Optional. When the job reached a terminal status. Useful for billing audits, UI timelines, SLA debugging."
    }
  },
  "allOf": [
    {
      "if": { "properties": { "status": { "const": "success" } } },
      "then": { "required": ["result"] }
    },
    {
      "if": { "properties": { "status": { "enum": ["failure", "timeout"] } } },
      "then": { "required": ["error"] }
    },
    {
      "if": { "properties": { "status": { "const": "queued" } } },
      "then": { "required": ["queue_position"] }
    }
  ]
}
