schema_version: 1
case_id: region-unavailable-escalation-during-incident-window
ground_truth:
  root_cause: A TiKV component-level panic/restart chain, not pending-peer alone, drove the incident; pending-peer buildup was the direct trigger for Region is unavailable, but the diagnosis must escalate to the underlying component failure path rather than stop at region-health symptoms.
judge:
  semantic_strategy: undecided
  contract:
    checks:
    - id: time_window_match
      required: true
      description: Actual diagnosis time window matches one allowed case window.
      match: all_of
      rules:
      - source: trace_fact
        matcher: bool_true
        path: time_window_match
    - id: cluster_scope_match
      required: true
      description: Actual diagnosis cluster scope matches expected cluster id.
      match: all_of
      rules:
      - source: trace_fact
        matcher: bool_true
        path: cluster_scope_match
  workflow:
    checks:
    - id: architecture_context_loaded
      weight: 5
      required: true
      description: Architecture context is loaded.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: architecture_context_loaded
    - id: misdiagnosis_guardrails_loaded
      weight: 5
      required: true
      description: Misdiagnosis guardrails are loaded.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: misdiagnosis_guardrails_loaded
    - id: diagnosis_run_initialized
      weight: 5
      required: true
      description: Diagnosis run is initialized.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: diagnosis_run_initialized
    - id: evidence_collection_completed
      weight: 10
      required: true
      description: Evidence collection completes.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: evidence_collection_completed
    - id: summary_read_completed
      weight: 5
      required: false
      description: Summary artifact is read when available.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: summary_read_completed
    - id: targeted_panic_log_query_completed
      weight: 10
      required: false
      description: Targeted panic log query is completed rather than stopping at generic symptom checks.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: targeted_panic_log_query_completed
    - id: final_answer_emitted
      weight: 0
      required: false
      description: Final answer is emitted.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: final_answer_emitted
  execution_contract:
    checks:
    - id: required_workflow_present
      required: true
      description: Required workflow milestones are present.
      match: all_of
      rules:
      - source: workflow_check
        matcher: subset_observed
        paths:
        - architecture_context_loaded
        - misdiagnosis_guardrails_loaded
        - diagnosis_run_initialized
        - evidence_collection_completed
    - id: required_artifacts_present
      required: true
      description: Required evidence artifacts are present.
      match: all_of
      rules:
      - source: artifact_fact
        matcher: subset_observed
        paths:
        - core_evidence_bundle_present
    - id: preferred_channels_minimum_observed
      required: true
      description: At least one preferred evidence channel is observed.
      match: all_of
      rules:
      - source: channel_fact
        matcher: count_gte
        paths:
        - logs
        - query_or_metric
        threshold: 1
    - id: preferred_channels_all_observed
      required: false
      description: Preferred evidence channels are all observed.
      match: all_of
      rules:
      - source: channel_fact
        matcher: subset_observed
        paths:
        - logs
        - query_or_metric
  evidence_collection:
    weight: 5
    checks:
    - id: required_artifacts_present
      weight: 4
      required: true
      description: Required evidence artifacts are present and readable.
      match: all_of
      rules:
      - source: artifact_fact
        matcher: subset_observed
        paths:
        - core_evidence_bundle_present
    - id: preferred_channels_minimum_observed
      weight: 0
      required: true
      description: At least the minimum number of preferred evidence channels are observed.
      match: all_of
      rules:
      - source: channel_fact
        matcher: count_gte
        paths:
        - logs
        - query_or_metric
        threshold: 1
    - id: preferred_channels_all_observed
      weight: 6
      required: false
      description: Preferred evidence channels are all observed.
      match: all_of
      rules:
      - source: channel_fact
        matcher: subset_observed
        paths:
        - logs
        - query_or_metric
  critical_evidence:
    weight: 30
    checks:
    - id: primary_symptom_evidence_present
      weight: 8
      required: true
      description: Direct region-health symptom evidence is present within the incident window.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_text_contains_any
        keywords:
        - pending-peer-region-count
        - pd_pending_peer
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - pending-peer-region-count
        - pending peer
    - id: root_cause_mechanism_evidence_present
      weight: 10
      required: true
      description: Root-cause mechanism evidence is present beyond the direct region-health symptom.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - "resolved_ts"
        - "commit_ts"
        - "cdc::delegate"
        - "sink_txn_put"
        - "delegate.rs"
        - "panic:"
        - "fatal"
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - resolved_ts
        - commit_ts
        - panic
        - fatal
        - cdc
    - id: restart_signal_present
      weight: 6
      required: false
      description: Direct restart evidence is present within the incident window.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - "restart"
        - "restarted"
        - "fatal"
        - "Welcome to TiKV"
        - "Welcome to TiDB"
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - restart
        - panic
        - fatal
  evidence_routing:
    weight: 5
    checks:
    - id: analysis_patch_valid_json
      weight: 1
      required: true
      description: Analysis patch is valid JSON whenever the patch exists.
      match: any_of
      rules:
      - source: routing_fact
        matcher: bool_false
        path: analysis_patch_present
      - source: routing_fact
        matcher: bool_true
        path: analysis_patch_valid_json
    - id: analysis_items_shape_valid
      weight: 2
      required: true
      description: Analysis patch items are structurally valid whenever the patch exists.
      match: any_of
      rules:
      - source: routing_fact
        matcher: bool_false
        path: analysis_patch_present
      - source: routing_fact
        matcher: bool_true
        path: analysis_items_shape_valid
    - id: analysis_key_evidence_present
      weight: 2
      required: true
      description: Analysis patch includes key evidence whenever the patch exists.
      match: any_of
      rules:
      - source: routing_fact
        matcher: bool_false
        path: analysis_patch_present
      - source: routing_fact
        matcher: bool_true
        path: analysis_has_key_evidence
    - id: metric_refs_resolvable
      weight: 1
      required: true
      description: Metric references are resolvable whenever the patch contains metric refs.
      match: any_of
      rules:
      - source: routing_fact
        matcher: bool_false
        path: analysis_metric_refs_required
      - source: routing_fact
        matcher: bool_true
        path: analysis_metric_refs_resolvable
    - id: query_refs_resolvable
      weight: 1
      required: true
      description: Query references are resolvable whenever the patch contains query refs.
      match: any_of
      rules:
      - source: routing_fact
        matcher: bool_false
        path: analysis_query_refs_required
      - source: routing_fact
        matcher: bool_true
        path: analysis_query_refs_resolvable
    - id: supporting_evidence_present
      weight: 0
      required: false
      description: Analysis patch includes supporting evidence whenever the patch exists.
      match: any_of
      rules:
      - source: routing_fact
        matcher: bool_false
        path: analysis_patch_present
      - source: routing_fact
        matcher: bool_true
        path: analysis_has_supporting_evidence
    - id: analysis_log_or_event_channel_resolvable
      weight: 0
      required: false
      description: Routed log or event items stay resolvable against observed channels.
      match: all_of
      rules:
      - source: routing_fact
        matcher: bool_true
        path: analysis_log_or_event_channel_resolvable
  diagnosis:
    checks:
    - id: identify_pending_peer_as_direct_trigger
      mode: blended
      weight: 4
      required: true
      description: Identifies pending-peer or equivalent region-health buildup as the direct trigger for Region is unavailable.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - pending-peer-region-count
          - pending peer
          - pending-peer
      semantic:
        id: 1
        title: direct cause 识别
        description: |
          判断回答是否把 pending peer 或等价的 region-health 异常放在
          direct cause 层，而不是完全跳过用户报错为什么发生这一层。
    - id: identify_root_cause_mechanism
      mode: blended
      weight: 4
      required: true
      description: Explains the component-level root-cause mechanism rather than stopping at region-health symptoms.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - panic
          - resolved_ts
          - commit_ts
          - cdc::delegate
          - sink_txn_put
          - assertion
      semantic:
        id: 2
        title: 根因机制解释
        description: |
          判断回答是否从 pending peer 继续升级到组件级故障路径，
          例如 panic、restart、assertion 或 CDC 相关异常，
          而不是把分析收口在 region-health 表层症状。
    - id: distinguish_direct_cause_and_deeper_root_cause
      mode: blended
      weight: 2
      required: false
      description: Explicitly separates the direct cause seen by users from the deeper root cause or strongest current hypothesis.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - 直接原因
          - 更底层根因
          - 更深层根因
          - 当前最强假设
          - 中间现象
          - 不是最终根因
      semantic:
        id: 3
        title: 分层结论表达
        description: |
          判断回答是否明确区分：
          1. 为什么用户当时看到了 Region is unavailable；
          2. 更底层真正需要继续追的组件级根因或当前最强假设。
          不能把这两层混成一个泛化结论。
    - id: reject_pending_peer_as_final_root_cause
      mode: blended
      scoring_mode: penalty
      weight: 3
      required: false
      description: Does not stop at pending-peer as the final root cause.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: regex_any
          patterns:
          - "pending[- ]peer.{0,80}(is|was|是|就是).{0,40}(the )?(final )?(primary )?root cause"
          - "pending[- ]peer.{0,60}(根因|主因|最终根因)"
          - "pending-peer-region-count.{0,60}(根因|主因|root cause)"
      semantic:
        id: 4
        title: symptom-only 误诊排除
        description: |
          判断回答是否把 pending peer 这种直接症状错误地抬升成最终根因，
          而没有继续升级到组件级机制层解释。若回答本质上停在
          symptom-only diagnosis，应判为命中 penalty。
  critical:
  - id: identify_pending_peer_direct_trigger
    description: Identifies pending-peer or equivalent region-health buildup as the direct trigger for Region is unavailable.
  - id: identify_root_cause_mechanism
    description: Explains the component-level root-cause mechanism beyond region-health symptoms.
  - id: distinguish_direct_cause_and_deeper_root_cause
    description: Separates direct cause from deeper root cause or strongest current hypothesis.
  - id: reject_pending_peer_as_final_root_cause
    description: Does not stop at pending-peer as the final root cause.
