{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/antfly/json-schema/antfly-table-repair-job-schema.json",
  "title": "TableRepairJob",
  "description": "Durable table repair job state.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/antfly-data-operations-api-openapi.yml#/components/schemas/TableRepairJob",
  "type": "object",
  "required": [
    "job_id",
    "attempt_id",
    "table_name",
    "phase",
    "repair_status",
    "target",
    "limit",
    "force",
    "result",
    "cancel_requested",
    "created_at_millis",
    "last_updated_at_millis",
    "expires_at_millis"
  ],
  "properties": {
    "job_id": {
      "type": "integer",
      "format": "uint64",
      "description": "Server-assigned durable repair job identifier."
    },
    "attempt_id": {
      "type": "integer",
      "format": "uint64",
      "description": "Monotonic execution attempt token for the current running pass."
    },
    "table_name": {
      "type": "string",
      "description": "Table being repaired."
    },
    "phase": {
      "type": "string",
      "enum": [
        "queued",
        "running",
        "succeeded",
        "failed",
        "cancelled"
      ],
      "description": "Lifecycle phase of the repair job."
    },
    "repair_status": {
      "type": "string",
      "enum": [
        "in_progress",
        "complete",
        "debt_remaining",
        "stopped"
      ],
      "description": "User-facing repair progress state. `debt_remaining` means the bounded job stopped because unsupported or failed debt still requires operator action."
    },
    "target": {
      "$ref": "#/$defs/RepairTarget"
    },
    "kind": {
      "$ref": "#/$defs/ArtifactRepairKind"
    },
    "index": {
      "type": "string",
      "description": "Index name when the job is restricted to one index."
    },
    "control": {
      "type": "string",
      "enum": [
        "pause_automatic",
        "resume_automatic",
        "cancel_current_attempt"
      ],
      "description": "Durable named-index control applied in bounded server-owned passes across every table group."
    },
    "repair_id": {
      "type": "string",
      "description": "Decimal repair attempt fence, preserved across every pass. A stale fence fails the control job."
    },
    "cursor": {
      "type": [
        "string",
        "null"
      ],
      "description": "Opaque continuation cursor for the next bounded repair pass."
    },
    "limit": {
      "type": "integer",
      "format": "uint32",
      "description": "Effective per-pass repair limit."
    },
    "force": {
      "type": "boolean",
      "description": "Whether the next bounded pass still needs to dispatch the job's one forced named-index generation."
    },
    "result": {
      "$ref": "#/$defs/TableRepairRunResult"
    },
    "last_error": {
      "type": [
        "string",
        "null"
      ],
      "description": "Last stable job-level error code."
    },
    "cancel_requested": {
      "type": "boolean",
      "description": "Whether cancellation is pending. For a named-index repair/rebuild job, cancellation durably pauses the matching repair in every group. Cancelling a control job stops remaining passes without undoing controls already applied."
    },
    "next_retry_at_millis": {
      "type": "integer",
      "format": "uint64",
      "description": "Unix epoch milliseconds when a deferred pass may next run; zero means immediately eligible."
    },
    "created_at_millis": {
      "type": "integer",
      "format": "uint64",
      "description": "Unix epoch milliseconds when the job was created."
    },
    "last_updated_at_millis": {
      "type": "integer",
      "format": "uint64",
      "description": "Unix epoch milliseconds when the job state was last updated."
    },
    "expires_at_millis": {
      "type": "integer",
      "format": "uint64",
      "description": "Unix epoch milliseconds when the job is eligible for cleanup."
    }
  },
  "$defs": {
    "ArtifactRepairKind": {
      "type": "string",
      "description": "Kind of stored artifact tracked by the repair queue.",
      "enum": [
        "embedding",
        "asset",
        "chunk",
        "graph",
        "full_text",
        "algebraic"
      ]
    },
    "RepairTarget": {
      "type": "string",
      "description": "Repair subsystem to inspect or run.",
      "enum": [
        "artifact",
        "index"
      ]
    },
    "TableRepairRunResult": {
      "type": "object",
      "description": "Result of one bounded table repair pass.",
      "required": [
        "scanned",
        "groups_scanned",
        "reprocessed",
        "repaired",
        "missing_source_docs",
        "failed",
        "unsupported",
        "unresolved",
        "in_progress",
        "indexes_rebuilt",
        "indexes_degraded_before",
        "indexes_degraded_after",
        "controls_applied",
        "limit",
        "has_more",
        "debt_remaining"
      ],
      "properties": {
        "scanned": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of repair records attempted by this pass."
        },
        "groups_scanned": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of table groups touched by this bounded repair pass."
        },
        "reprocessed": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of artifacts whose source was reprocessed."
        },
        "repaired": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of repair records cleared because the artifact became readable."
        },
        "missing_source_docs": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of repair records whose source document no longer exists."
        },
        "failed": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of supported repair attempts that failed."
        },
        "unsupported": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of repair records skipped because no automated repair exists for the selected target."
        },
        "unresolved": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of attempted repair records that remained queued after this pass."
        },
        "in_progress": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of selected repair records or indexes skipped because another repair pass already owns them."
        },
        "indexes_rebuilt": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of indexes rebuilt by this pass when target is index."
        },
        "indexes_degraded_before": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of selected indexes that were degraded or quarantined when this repair pass began."
        },
        "indexes_degraded_after": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of selected indexes that remain degraded or quarantined when this repair pass returns."
        },
        "controls_applied": {
          "type": "integer",
          "format": "uint64",
          "description": "Number of existing index repairs that accepted the requested control."
        },
        "limit": {
          "type": "integer",
          "format": "uint32",
          "description": "Effective repair limit."
        },
        "next_cursor": {
          "type": [
            "string",
            "null"
          ],
          "description": "Opaque cursor for the next artifact repair pass when has_more is true. Named-index operations may return a continuation cursor when table groups remain."
        },
        "has_more": {
          "type": "boolean",
          "description": "Whether another repair scan page is available via next_cursor."
        },
        "debt_remaining": {
          "type": "boolean",
          "description": "Whether repair debt remains after this bounded pass. If true and next_cursor is absent, rerun repair from the beginning after addressing failed or unsupported records."
        }
      }
    }
  }
}