{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "failure_envelope_schema.json",
  "title": "task-2712 Failure Callback Envelope",
  "description": "FAILURE_CALLBACK_BEFORE_EXIT_GUARD envelope. 11 mandatory field + 4 collector strict field. UTF-8 <= 3900 bytes hard. collector_role=ANU + collector_key/owner_key=ANU_KEY + self_key_used=false strict (SELF_COLLECTOR_FORBIDDEN).",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "task_id",
    "team",
    "bot",
    "session",
    "phase",
    "exit_code",
    "failure_kind",
    "artifact_paths",
    "critical7_match",
    "terminal_state",
    "chair_authorization_id",
    "collector_role",
    "collector_key",
    "owner_key",
    "self_key_used"
  ],
  "properties": {
    "task_id": {
      "type": "string",
      "description": "task 고유 ID (예: task-2712)."
    },
    "team": {
      "type": "string",
      "description": "executor team (예: dev4-team)."
    },
    "bot": {
      "type": "string",
      "description": "executor bot 이름 (예: vishnu)."
    },
    "session": {
      "type": "string",
      "description": "session id (ANU session-bound polling 회수 키)."
    },
    "phase": {
      "type": "string",
      "description": "종료 시점 phase (예: scope_guard / qc / postprocessing)."
    },
    "exit_code": {
      "type": "integer",
      "description": "프로세스 exit code. crash sentinel -1/-9/-15 허용 (SIGKILL/SIGTERM/OOM)."
    },
    "failure_kind": {
      "type": "string",
      "description": "failure 세부 종류 (예: scope_violation_count_61)."
    },
    "artifact_paths": {
      "type": "array",
      "items": { "type": "string" },
      "description": "산출물 경로 배열. byte limit 초과 시 본 필드만 유지."
    },
    "critical7_match": {
      "type": "boolean",
      "description": "Critical 7 매칭 여부 (true → CRITICAL_ESCALATION 즉시 cron)."
    },
    "terminal_state": {
      "type": "string",
      "enum": [
        "SUCCESS",
        "FAILURE",
        "BLOCKED",
        "SCOPE_GUARD_FAIL",
        "QC_FAIL",
        "INFRA_DEFECT",
        "PERMISSION_FAIL",
        "API_FAIL",
        "CRITICAL_ESCALATION",
        "CRASH_NO_EXIT_CODE",
        "UNCLASSIFIED_TERMINAL_STATE"
      ],
      "description": "10 terminal state enum + UNCLASSIFIED fallback (§4.3 envelope-write fail)."
    },
    "chair_authorization_id": {
      "type": "string",
      "description": "회장 verbatim 발급 authorization id."
    },
    "collector_role": {
      "const": "ANU",
      "description": "SELF_COLLECTOR_FORBIDDEN: 반드시 ANU."
    },
    "collector_key": {
      "const": "c119085addb0f8b7",
      "description": "ANU collector key strict."
    },
    "owner_key": {
      "const": "c119085addb0f8b7",
      "description": "ANU owner key strict."
    },
    "self_key_used": {
      "const": false,
      "description": "executor self-key 사용 0 강제 (explicit false)."
    },
    "registration_mode": {
      "type": "string",
      "description": "callback 등록 mode (normal_callback / failure_callback_before_exit_guard 등)."
    },
    "recorded_at": {
      "type": "string",
      "description": "marker 기록 ISO8601 timestamp."
    },
    "residual_pid": {
      "type": ["integer", "null"],
      "description": "INFRA_DEFECT.residual_process subcase 의 잔존 child pid."
    },
    "summary": {
      "type": "string",
      "description": "축약 가능한 요약 (byte limit 초과 시 우선 축소 대상)."
    }
  }
}
