{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "anu_v3/parallel_batch_state.schema.json",
  "title": "Parallel Batch State (task-2553+17 Track2)",
  "description": "Durable batch state. callback_track_registry uses the 9-R.2 canonical callback_track_record: track_id-keyed, 5 fields each.",
  "type": "object",
  "required": [
    "schema",
    "batch_id",
    "batch_label",
    "callback_track_registry",
    "dependency_matrix",
    "track_states",
    "batch_next_action"
  ],
  "properties": {
    "schema": { "const": "anu_v3.parallel_batch_state.v1" },
    "batch_id": { "type": "string", "pattern": "^batch-" },
    "batch_label": { "type": "string", "minLength": 1 },
    "callback_track_registry": {
      "type": "object",
      "description": "track_id -> callback_track_record (9-R.2)",
      "additionalProperties": { "$ref": "#/definitions/callback_track_record" }
    },
    "dependency_matrix": { "type": "object" },
    "track_states": {
      "type": "object",
      "additionalProperties": { "$ref": "#/definitions/track_state" }
    },
    "goal_loop_plans": { "type": "object" },
    "contamination": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["citing", "owner", "artifact"],
        "properties": {
          "citing": { "type": "string" },
          "owner": { "type": "string" },
          "artifact": { "type": "string" }
        }
      }
    },
    "batch_next_action": {
      "type": "string",
      "enum": [
        "BATCH_HOLD_CONTAMINATION",
        "CHAIR_DECISION_REQUIRED",
        "AWAIT_PENDING_CALLBACK",
        "CONTINUE_LOOP",
        "CONSOLIDATE_FOR_CHAIR"
      ]
    }
  },
  "definitions": {
    "callback_track_record": {
      "type": "object",
      "description": "9-R.2 canonical: 5 fields. callback identity 4-tuple = the 4 non-key fields.",
      "required": [
        "track_id",
        "task_id",
        "dispatch_cron_id",
        "normal_collector_cron_id",
        "fallback_callback_cron_id"
      ],
      "additionalProperties": false,
      "properties": {
        "track_id": { "type": "string", "minLength": 1 },
        "task_id": { "type": "string", "minLength": 1 },
        "dispatch_cron_id": { "type": "string", "minLength": 1 },
        "normal_collector_cron_id": { "type": "string", "minLength": 1 },
        "fallback_callback_cron_id": { "type": "string", "minLength": 1 }
      }
    },
    "track_state": {
      "type": "object",
      "required": ["track_id", "state", "terminal"],
      "properties": {
        "track_id": { "type": "string" },
        "state": {
          "type": "string",
          "enum": [
            "PLANNED",
            "DISPATCHED",
            "RUNNING",
            "NORMAL_COLLECTOR_COMPLETED",
            "CODEX_AUDIT_PENDING",
            "ANU_ADJUDICATION_PENDING",
            "AUTO_MICRO_FIX",
            "RETRY_WITHIN_SCOPE",
            "ACCEPTED",
            "LANDING_PENDING",
            "MERGE_READY",
            "MERGED",
            "HOLD_FOR_CHAIR"
          ]
        },
        "terminal": { "type": "boolean" },
        "retry_ceiling": { "type": "integer" },
        "retry_count": { "type": "integer" },
        "normal_collector_reached": { "type": "boolean" },
        "history": { "type": "array", "items": { "type": "string" } },
        "rejected_transitions": { "type": "array" }
      }
    }
  }
}
