{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "schemas/callback_ledger_v1.json",
  "title": "callback_ledger_v1",
  "description": "task-2644 ANU_CALLBACK_COLLECTOR_CONTROL_PLANE — durable record of every callback processed by the collector session. spec sha256: b27da557d4245bce476cd63f4ab174aefc8a25d2da07ec2c8d2c83b01ee96153. ANCHOR-3/4/9/11/14/15. RUNTIME_GUARDED scope. 회장 verbatim 보강-5.",
  "type": "object",
  "required": [
    "schema_version",
    "callback_id",
    "task_id",
    "envelope_parsed",
    "context_recovered",
    "terminal_state_classified",
    "next_action_decided",
    "next_action_attempted",
    "next_action_result",
    "next_action_evidence_path",
    "callback_ledger_written",
    "source_attribution",
    "state_version",
    "recorded_at"
  ],
  "properties": {
    "schema_version": {"const": "v1"},
    "callback_id": {"type": "string", "minLength": 1},
    "task_id": {"type": "string", "pattern": "^task-[0-9]+(\\+[0-9]+)?(-[A-Za-z0-9_-]+)?$"},
    "pr_number": {"type": ["integer", "null"]},
    "schedule_id": {"type": ["string", "null"]},
    "collector_session_id": {"type": "string", "minLength": 1},
    "envelope_parsed": {"type": "boolean"},
    "envelope_bytes_utf8": {"type": "integer", "minimum": 0, "maximum": 3900,
      "description": "envelope hard limit 3900 bytes (wc -c). >3500 warning."},
    "context_recovered": {"type": "boolean",
      "description": "task md + spec md + .anu_state + frozen anchor 자동 로드 완료"},
    "terminal_state_classified": {"type": "boolean"},
    "terminal_state": {
      "type": "string",
      "enum": [
        "TERMINAL_PASS",
        "TERMINAL_FAIL",
        "IN_PROGRESS",
        "BATCH_PENDING",
        "MERGE_READY",
        "CRITICAL7_HIT",
        "PERMISSION_EXPANSION",
        "CREDENTIAL_EXPANSION",
        "AUTO_REMEDIATION_CANDIDATE",
        "OWNER_GEMINI_TRIGGER",
        "SIBLING_INCOMPLETE",
        "SIBLING_FINAL",
        "STATE_STALE_OR_MISMATCH",
        "NOT_CONTROL_PLANE_COMPLIANT"
      ]
    },
    "policy_class": {
      "type": "string",
      "enum": [
        "MERGE_POLICY_LOCK",
        "AUTO_REMEDIATION_INSIDE_EXPECTED_FILES",
        "CRITICAL7_REPORT",
        "PERMISSION_OR_CREDENTIAL_EXPANSION",
        "PHASE3_TIMING_RACE",
        "OWNER_GEMINI_TRIGGER_NUDGE",
        "BATCH_WAIT",
        "BATCH_ADJUDICATE",
        "FOLLOWUP_TASK_SPEC",
        "REGRESSION_RERUN",
        "LEDGER_ONLY_NOOP",
        "HOLD_FOR_CHAIR",
        "SAFE_DEGRADED_MODE"
      ]
    },
    "critical7_hit": {"type": "boolean"},
    "next_action_decided": {
      "type": "string",
      "enum": [
        "REQUEST_CHAIR_MERGE_APPROVAL",
        "REPORT_CRITICAL7",
        "REPORT_PERMISSION_OR_CREDENTIAL_EXPANSION",
        "DISPATCH_AUTO_REMEDIATION",
        "RERUN_ALLOWED_GATE",
        "RUN_OWNER_GEMINI_TRIGGER_ROUTER",
        "CREATE_FOLLOWUP_TASK_SPEC",
        "WAIT_FOR_BATCH_SIBLINGS",
        "BATCH_ADJUDICATE",
        "NOOP_TERMINAL",
        "HOLD_FOR_CHAIR"
      ]
    },
    "next_action_branch": {
      "type": "string",
      "enum": ["auto-executable", "chair-required", "terminal_noop"],
      "description": "보강-2 3 분기 mutually exclusive · Telegram = chair-required 전용 의무 경로"
    },
    "next_action_attempted": {"type": "boolean"},
    "next_action_result": {
      "type": "string",
      "enum": [
        "DISPATCH_REGISTERED",
        "TELEGRAM_SENT",
        "LEDGER_ONLY",
        "HOLD_PACKET_CREATED",
        "BATCH_WAIT_RECORDED",
        "FAILED"
      ],
      "description": "보강-5 result enum 6종"
    },
    "next_action_evidence_path": {"type": "string", "minLength": 1,
      "description": "cron-list/cron-history/telegram outbox/ledger entry/hold packet path"},
    "auto_action_dispatched": {"type": "boolean"},
    "chair_report_emitted": {"type": "boolean"},
    "noop_terminal_recorded": {"type": "boolean"},
    "batch_wait_recorded": {"type": "boolean"},
    "callback_ledger_written": {"type": "boolean"},
    "source_attribution": {
      "type": "string",
      "enum": [
        "RECEIVED_INBOUND_THIS_SESSION",
        "LOG_LOOKUP_AFTER_CHAIR_QUESTION",
        "LOG_LOOKUP_PROACTIVE",
        "MEMORY_RECALL",
        "INFERENCE_ONLY",
        "CALLBACK_COLLECTOR_PROCESSED",
        "CALLBACK_LEDGER_RECONCILED",
        "LOG_LOOKUP_OR_SCHEDULE_HISTORY_VERIFICATION"
      ],
      "description": "보강-1 + 회장 추가 8 enum (★ CALLBACK_COLLECTOR_PROCESSED = 주 경로 · LOG_LOOKUP_OR_SCHEDULE_HISTORY_VERIFICATION = 1C0F6F52 박제)"
    },
    "state_version": {"type": ["string", "null"],
      "description": ".anu_state snapshot_id 또는 state_version · null 이면 stale/missing → SAFE_DEGRADED_MODE/HOLD_FOR_CHAIR 강제"},
    "state_freshness_status": {
      "type": "string",
      "enum": ["FRESH", "STALE", "MISSING", "MISMATCH"]
    },
    "recorded_at": {"type": "string", "format": "date-time"},
    "control_plane_compliant": {"type": "boolean",
      "description": "7 단계 protocol (envelope→recovery→classify→decide→action→ledger→source) 모두 충족 시 true. envelope 회수 + status=ok chain 만 본 경우 false (1C0F6F52 fixture-8)"},
    "compliance_failures": {
      "type": "array",
      "items": {"type": "string"},
      "description": "Stop hook 10 조건 중 위반된 항목 (control_plane_compliant=false 일 때)"
    }
  },
  "additionalProperties": true
}
