schema_version: 1
case_id: tikv-node-slowdown-during-incident-window
ground_truth:
  root_cause: A single-TiKV flow control / backpressure path on db-tikv-9 is the strongest current explanation for the observed query latency regression; the diagnosis should not stop at pending compaction or generic CPU explanations.
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: premise_verification_recorded
      weight: 5
      required: false
      description: The user's tikv-9 slowness claim is verified in its own
        dimension and recorded in premise_verification.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: premise_verification_recorded
    - 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_minimum_observed
      required: true
      description: At least one preferred evidence channel is observed.
      match: all_of
      rules:
      - source: channel_fact
        matcher: count_gte
        paths:
        - 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:
        - 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:
        - 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:
        - query_or_metric
  critical_evidence:
    weight: 30
    checks:
    - id: query_slowdown_signal_present
      weight: 9
      required: true
      description: Evidence shows the incident is tied to query slowdown or tail-latency symptoms.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - queries
        - workspace_report
        - summary_json
        matcher: json_text_contains_any
        keywords:
        - slow query
        - query slowdown
        - query latency regression
        - latency
        - tail latency
        - stall
        - timeout
    - id: flow_control_signal_present
      weight: 10
      required: true
      description: Evidence shows TiKV flow control or backpressure on the target node.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        - workspace_report
        - summary_json
        matcher: json_text_contains_any
        keywords:
        - flow control
        - backpressure
        - admission control
        - write stall
        - throttle
        - throttled
        - pause
    - id: single_node_scope_evidence_present
      weight: 7
      required: true
      description: Evidence isolates the issue to db-tikv-9 rather than cluster-wide scope.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        - workspace_report
        - summary_json
        matcher: json_text_contains_any
        keywords:
        - db-tikv-9
        - single TiKV
        - one TiKV instance
    - id: broad_instance_regex_absent
      weight: 4
      required: true
      description: Evidence does not rely on an over-broad instance regex that can drag sibling TiKV nodes into the analysis.
      match: all_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_values_not_contains_any
        path: metrics.promql
        keywords:
        - instance=~"db-tikv-9.*"
  diagnosis:
    checks:
    - id: identify_flow_control_as_primary_driver
      mode: blended
      weight: 4
      required: true
      description: Identifies flow control / backpressure on the target TiKV node as the primary slowdown driver.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - flow control
          - backpressure
          - write stall
          - throttle
          - admission control
          - 限流
          - 背压
      semantic:
        id: 1
        title: 主路径判断
        description: |
          判断回答是否把 flow control / backpressure 识别为引发查询变慢的主路径，
          而不是 pending compaction、generic CPU 或 cluster-wide explanation。
    - id: identify_single_node_hotspot_scope
      mode: blended
      weight: 4
      required: true
      description: Explicitly states that the slowdown is scoped to db-tikv-9.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - db-tikv-9
          - single TiKV
          - single node
          - one TiKV instance
          - 单个 TiKV
          - 单节点
      semantic:
        id: 2
        title: 热点范围识别
        description: |
          判断回答是否明确把问题范围锁定到 db-tikv-9，并避免把它说成
          cluster-wide 或对象漂移后的现象。
    - id: reject_pending_compaction_as_final_root_cause
      mode: blended
      scoring_mode: penalty
      weight: 4
      required: false
      description: Does not stop at pending compaction alone as the final root cause.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: regex_any
          patterns:
          - "pending compaction.{0,80}(is|was|是|就是).{0,40}(the )?(final )?(primary )?root cause"
          - "pending compaction.{0,60}(根因|主因|最终根因)"
          - "(root cause|主因|最终根因).{0,60}pending compaction"
      semantic:
        id: 3
        title: 误诊排除
        description: |
          判断回答是否把 pending compaction 这种可能的表层现象错误地抬升成最终根因，
          而没有继续追到 flow control / backpressure 这条更深的 TiKV 侧路径。
    - id: recommend_flow_control_followup
      mode: blended
      weight: 2
      required: false
      description: Recommends follow-up that targets the flow-control or backpressure path.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - flow control
          - backpressure
          - write stall
          - admission control
          - throttling
          - 限流
          - 背压
      semantic:
        id: 4
        title: 建议对齐
        description: |
          判断回答是否给出与 flow control / backpressure / stall 路径对齐的后续建议，
          而不是主要建议去调 CPU 或泛化地做无关优化。
  evidence_routing:
    weight: 0
    checks:
    - id: analysis_patch_valid_when_present
      weight: 0
      required: true
      description: Analysis patch is only required to be valid when it 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
