schema_version: 1
case_id: component-restart-during-incident-window
ground_truth:
  root_cause: TiDB v8.5.2 known bug GitHub
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.
      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: restart_signal_present
      weight: 8
      description: Direct restart evidence is present within the incident window.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - component_health
        matcher: json_list_nonempty
        path: component_health.restarts
      - source: artifact_json
        artifacts:
        - process_restart_metrics
        - kube_restart_metrics
        matcher: numeric_series_any_gt
        path: data.result
        threshold: 0
      - source: logs
        matcher: keyword_any
        keywords:
        - "Welcome to TiDB."
    - id: panic_signal_present
      weight: 9
      description: Direct panic evidence is present within the incident window.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - "panic:"
        - "memory.(*Tracker).Consume"
        - "tracker accounting panic"
    - id: query_interruption_signal_present
      weight: 8
      description: Direct query interruption evidence is present within the incident window.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - "kill query"
        - "query execution was interrupted"
        - "query is killed"
        - "sqlkiller.go"
  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_known_bug_restart_chain
        mode: blended
        weight: 3
        required: true
        description: Identifies the known-bug single-instance restart chain rather than a generic restart explanation.
        deterministic:
          match: all_of
          rules:
          - source: output_fact
            matcher: any_true
            paths:
            - diagnosis_single_instance_panic_restart_asserted
            - diagnosis_memory_tracker_panic_asserted
        semantic:
          id: 1
          title: 主路径判断
          description: |
            判断回答是否将本次事件的主路径识别为 TiDB v8.5.2 已知 bug 导致的
            single-instance restart chain，而不是 generic restart、missing index
            或其它泛化解释。
      - id: identify_kill_query_cleanup_chain
        mode: blended
        weight: 3
        required: false
        description: Identifies KILL QUERY / query interruption as trigger and explains the cleanup chain toward panic or restart.
        deterministic:
          match: all_of
          rules:
          - source: output_fact
            matcher: bool_true
            path: diagnosis_kill_query_chain_asserted
        semantic:
          id: 2
          title: 因果链完整性
          description: |
            判断回答是否说明 KILL QUERY / query interruption 是触发因素而不是主根因，
            并进一步解释 rollback 或 idle transaction cleanup 到 panic/restart 的链路。
      - id: reject_missing_index_root_cause
        mode: deterministic_only
        scoring_mode: penalty
        weight: 3
        required: false
        description: Does not misdiagnose the case as a missing-index or full-scan primary root cause.
        deterministic:
          match: all_of
          rules:
          - source: output_fact
            matcher: bool_false
            path: missing_index_primary_root_cause_asserted
          - source: output_fact
            matcher: bool_false
            path: claims_panic_not_confirmable
      - id: mention_github_issue_id
        mode: deterministic_only
        weight: 3
        required: false
        description: Explicitly cites issue 63956 as the known bug identifier.
        deterministic:
          match: all_of
          rules:
          - source: output_text
            matcher: keyword_any
            keywords:
            - "63956"
            - "GitHub #63956"
            - "issue #63956"
      - id: recommend_fixed_version_upgrade
        mode: blended
        weight: 3
        required: false
        description: Recommends upgrading to a release containing the fix and explains the version relationship.
        deterministic:
          match: all_of
          rules:
          - source: output_fact
            matcher: bool_true
            path: mentions_v8_5_3_or_fixed_release
        semantic:
          id: 4
          title: 修复建议对齐
          description: |
            判断回答是否给出了与 ground truth 一致的 remediation，例如升级到包含修复的版本，
            而不是把建索引或泛化调参当成主修复方案。
  critical:
  - id: identify_single_instance_panic_restart
    description: Identifies a TiDB panic event and/or single-instance restart rather than a cluster-wide slowdown.
  - id: identify_kill_query_chain
    description: Identifies KILL QUERY / query interruption as part of the root-cause chain.
  - id: reject_missing_index_root_cause
    description: Does not misdiagnose the case as a missing-index or full-scan primary root cause.
  - id: identify_known_bug_63956
    description: Identifies TiDB v8.5.2 known bug GitHub
  - id: identify_kill_query_idle_txn_chain
    description: Explains the KILL QUERY plus idle transaction rollback cleanup trigger chain.
  - id: identify_version_without_fix
    description: States that v8.5.2 predates or does not include the fix.
  - id: recommend_fixed_version_upgrade
    description: Recommends upgrading to v8.5.3 or another version containing the fix.
