schema_version: 1
case_id: service-degradation-during-incident-window
ground_truth:
  root_cause: A dominant SQL join path drove the TiDB CPU hotspot on db-tidb-0, with stats-uninitialized plan misestimation, a TiFlash-to-TiKV plan shift, and intermediate result explosion amplifying the incident
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: 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_all_observed
      required: false
      description: Preferred evidence channels are all observed.
      match: all_of
      rules:
      - source: channel_fact
        matcher: subset_observed
        paths:
        - 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_all_observed
      weight: 6
      required: false
      description: Preferred evidence channels are all observed.
      match: all_of
      rules:
      - source: channel_fact
        matcher: subset_observed
        paths:
        - query_or_metric
  critical_evidence:
    weight: 30
    checks:
    - id: primary_symptom_evidence_present
      weight: 8
      description: Primary symptom evidence is present for the incident window.
      match: all_of
      rules:
      - source: artifact_json
        artifacts:
        - gate_checks
        matcher: json_text_contains_any
        keywords:
        - HOTSPOT DETECTED
        - CPU saturation
    - id: primary_query_evidence_present
      weight: 9
      description: Primary query evidence is present for the incident window.
      match: all_of
      rules:
      - source: artifact_json
        artifacts:
        - queries
        matcher: json_text_contains_any
        keywords:
        - TopSQL
        - digest
        - process_keys
        - cpu_time
    - id: root_cause_mechanism_evidence_present
      weight: 8
      description: Root-cause mechanism evidence is present for the incident window.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - queries
        matcher: json_values_contains_any
        path: slow_queries
        keywords:
        - unInitialized
        - statistics unInitialized
        - stats:pseudo
        - pseudo[
        - :pseudo[
      - source: artifact_json
        artifacts:
        - queries
        matcher: json_values_contains_any
        path: topsql
        keywords:
        - unInitialized
        - statistics unInitialized
        - stats:pseudo
        - pseudo[
        - :pseudo[
      - source: artifact_json
        artifacts:
        - queries
        matcher: json_values_contains_any
        path: decoded_plan
        keywords:
        - unInitialized
        - statistics unInitialized
        - stats:pseudo
        - pseudo[
        - :pseudo[
  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 refs resolve whenever the patch requires them.
      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 refs resolve whenever the patch requires them.
      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_specific_sql_hotspot_path
      mode: blended
      weight: 3
      required: true
      description: Identifies the specific SQL path driving the single-instance TiDB CPU hotspot.
      deterministic:
        match: all_of
        rules:
        - source: output_fact
          matcher: bool_true
          path: diagnosis_cpu_hotspot_asserted
        - source: output_text
          matcher: keyword_any
          keywords:
          - TopSQL
          - slow query
          - dominant query
          - hot JOIN path
          - hot join path
          - sql digest
          - JOIN path
      semantic:
        id: 1
        title: SQL 热点路径判断
        description: |
          判断回答是否把主路径识别为具体 SQL 或 join path 驱动的
          single-instance TiDB CPU hotspot，而不是 generic infra explanation。
    - id: identify_root_cause_mechanism
      mode: blended
      weight: 3
      required: false
      description: Explains the root-cause mechanism rather than stopping at symptom-level diagnosis.
      deterministic:
        match: any_of
        rules:
        - source: output_fact
          matcher: bool_true
          path: diagnosis_plan_stats_issue_asserted
        - source: output_fact
          matcher: any_true
          paths:
          - mentions_statistics_uninitialized
          - mentions_est_act_divergence
          - mentions_intermediate_result_explosion
      semantic:
        id: 2
        title: 根因机制解释
        description: |
          判断回答是否解释了 stats misestimation、uninitialized statistics
          或 intermediate-result amplification 这类机制，而不是只停留在表面症状。
    - id: identify_sql_plan_shift
      mode: blended
      weight: 3
      required: false
      description: Identifies that the dominant SQL path experienced a plan shift as part of the root-cause chain.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - plan shift
          - plan changed
          - plan switched
          - execution plan changed
          - plan regression
      semantic:
        id: 3
        title: 执行计划跳变
        description: |
          判断回答是否指出主 SQL 路径发生了执行计划跳变，
          并将其纳入根因链路解释。
    - id: identify_tiflash_to_tikv_execution_path_change
      mode: blended
      weight: 3
      required: false
      description: Identifies that the execution path shifted from TiFlash to TiKV.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - TiFlash to TiKV
          - switched from TiFlash to TiKV
          - plan switched to TiKV
          - TiFlash
          - TiKV
      semantic:
        id: 4
        title: TiFlash 到 TiKV 切换
        description: |
          判断回答是否指出执行路径从 TiFlash 切到 TiKV，
          并将这条切换纳入根因链路解释。
