{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "anu_v3/schemas/generic_batch_state.schema.json",
  "title": "anu_v3.generic_batch_state.v0",
  "description": "task-2553+30 TRACK B. The single integrated generic batch_state emitted by anu_v3.generic_batch_coordinator for ANY parallel batch: per-track callback 4-tuple registry · 4-tuple consistency · dependency/overlap/forbidden matrix · runtime records · 13-state loop · contamination · final authority packets · independence join · batch next action · evidence-derived closeout proposal (confirmed hard-pinned false) · code-generated consolidated summary. Authority path is the NEW separate memory/events/task-2553.generic-batch-state.json (distinct from chair durable v1, byte-0).",
  "type": "object",
  "required": [
    "schema",
    "batch_id",
    "batch_label",
    "callback_track_registry",
    "callback_4tuple_consistency",
    "dependency_matrix",
    "track_runtime_records",
    "track_loop_states",
    "contamination",
    "authority_packets",
    "join_policy",
    "batch_next_action",
    "closeout_proposal",
    "consolidated_summary"
  ],
  "properties": {
    "schema": { "const": "anu_v3.generic_batch_state.v0" },
    "batch_id": { "type": "string", "pattern": "^batch-" },
    "batch_label": { "type": "string", "minLength": 1 },
    "decision_logic": { "type": "string" },
    "callback_track_registry": {
      "type": "object",
      "additionalProperties": { "$ref": "#/definitions/callback_track_record" }
    },
    "callback_4tuple_consistency": {
      "type": "object",
      "additionalProperties": { "type": "array", "items": { "type": "string" } }
    },
    "dependency_matrix": { "type": "object" },
    "track_runtime_records": {
      "type": "object",
      "additionalProperties": { "$ref": "#/definitions/track_runtime_record" }
    },
    "track_loop_states": { "type": "object" },
    "contamination": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["citing", "owner", "artifact"],
        "properties": {
          "citing": { "type": "string" },
          "owner": { "type": "string" },
          "artifact": { "type": "string" }
        }
      }
    },
    "authority_packets": { "type": "object" },
    "join_policy": {
      "type": "object",
      "required": [
        "independent_done_tracks",
        "held_tracks",
        "waiting_tracks",
        "batch_next_action"
      ],
      "properties": {
        "independent_done_tracks": { "type": "array", "items": { "type": "string" } },
        "held_tracks": { "type": "array", "items": { "type": "string" } },
        "waiting_tracks": { "type": "array", "items": { "type": "string" } },
        "blocking_relations": { "type": "array", "items": { "type": "string" } },
        "batch_next_action": { "type": "string" }
      }
    },
    "batch_next_action": { "type": "string" },
    "batch_next_action_resolver": { "type": "string" },
    "closeout_proposal": {
      "type": "object",
      "required": ["eligible", "derived_from", "confirmed", "reason"],
      "properties": {
        "eligible": { "type": "boolean" },
        "derived_from": { "const": "batch_state" },
        "confirmed": { "const": false },
        "reason": { "type": "string" }
      }
    },
    "consolidated_summary": {
      "type": "object",
      "required": ["tracks", "batch_next_action", "closeout_eligible"],
      "properties": {
        "tracks": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": ["terminal_outcome", "classification", "hold_for_chair"],
            "additionalProperties": false,
            "properties": {
              "terminal_outcome": { "type": "string" },
              "classification": { "type": "string" },
              "hold_for_chair": { "type": "boolean" }
            }
          }
        },
        "batch_next_action": { "type": "string" },
        "closeout_eligible": { "type": "boolean" }
      }
    }
  },
  "definitions": {
    "track_runtime_record": {
      "type": "object",
      "required": [
        "task_id",
        "classification",
        "recovery_eligible",
        "terminal_outcome",
        "hold_for_chair"
      ],
      "properties": {
        "task_id": { "type": "string" },
        "classification": {
          "type": "string",
          "enum": [
            "RESULT_READY_NO_NORMAL_CALLBACK",
            "NORMAL_COLLECTOR_COMPLETED",
            "WAIT_FOR_FALLBACK",
            "RESULT_MISSING_BOT_STALE",
            "DISPATCH_FAILED",
            "TRACK_MISMATCH"
          ]
        },
        "recovery_eligible": { "type": "boolean" },
        "terminal_outcome": {
          "type": "string",
          "enum": ["MERGED", "PASS", "DONE", "ACCEPT", "HOLD", "PENDING", "UNKNOWN"]
        },
        "hold_for_chair": { "type": "boolean" },
        "track_mismatch_reasons": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": true
    },
    "callback_track_record": {
      "type": "object",
      "required": [
        "track_id",
        "task_id",
        "dispatch_cron_id",
        "normal_collector_cron_id",
        "fallback_callback_cron_id"
      ],
      "properties": {
        "track_id": { "type": "string" },
        "task_id": { "type": "string" },
        "dispatch_cron_id": { "type": "string" },
        "normal_collector_cron_id": { "type": ["string", "null"] },
        "fallback_callback_cron_id": { "type": "string" }
      }
    }
  }
}
