schema_version: 1
case_id: panic-in-recoverable-goroutine
ground_truth:
  root_cause: Recoverable goroutine panic caused by query timeout interruption
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: panic_signal_present
      weight: 8
      description: Direct recoverable panic evidence is present within the incident window.
      match: all_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - "panic in the recoverable goroutine"
        - "[executor:3024]"
        - "maximum statement execution time exceeded"
    - id: query_timeout_interrupt_signal_present
      weight: 9
      description: The panic evidence includes the query timeout interruption signal.
      match: all_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - "[executor:3024]Query execution was interrupted"
        - "maximum statement execution time exceeded"
        - "max_execution_time"
    - id: panic_classification_context_present
      weight: 8
      description: Query or metric context is present for classifying the alert impact.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - queries
        matcher: json_text_contains_any
        keywords:
        - max_execution_time
        - executor:3024
        - Query execution was interrupted
      - source: artifact_json
        artifacts:
        - gate_checks
        matcher: json_text_contains_any
        keywords:
        - INFRA CLEAR
        - HOTSPOT
  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_real_panic_event
      mode: blended
      weight: 3
      required: false
      description: Identifies that the recoverable panic alert corresponds to a real panic log.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - "panic in the recoverable goroutine"
          - "recoverable goroutine panic"
          - "[executor:3024]"
          - "executor:3024"
      semantic:
        id: 1
        title: 主路径判断
        description: |
          判断回答是否识别这是一个真实的 recoverable panic event，
          而不是 fake alarm 或无关现象。
    - id: identify_query_timeout_interrupt
      mode: deterministic_only
      weight: 3
      required: true
      description: Classifies the panic as a query timeout interruption.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - "maximum statement execution time exceeded"
          - "max_execution_time"
          - "query timeout"
          - "timeout interruption"
          - "超时中断"
          - "查询超时"
    - id: reject_fake_alarm_or_unrelated_root_cause
      mode: deterministic_only
      scoring_mode: penalty
      weight: 3
      required: false
      description: Does not dismiss the alert as fake or pivot to an unrelated primary root cause.
      deterministic:
        match: all_of
        rules:
        - source: output_fact
          matcher: bool_false
          path: fake_alarm_primary_asserted
        - 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: identify_expected_behavior
      mode: blended
      weight: 3
      required: false
      description: Classifies the timeout-interrupt panic as expected or benign behavior.
      deterministic:
        match: all_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - "expected behavior"
          - "normal behavior"
          - "benign"
          - "not a bug"
          - "预期行为"
          - "正常行为"
          - "不是 bug"
          - "不是bug"
      semantic:
        id: 3
        title: 行为定性
        description: |
          判断回答是否把 timeout-interrupt panic 定性为 expected behavior、
          benign behavior 或 not-a-bug。
    - id: recommend_no_tidb_fix_needed
      mode: blended
      weight: 3
      required: false
      description: Recommends no TiDB fix for the panic itself while allowing query or timeout tuning follow-up.
      deterministic:
        match: all_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - "no fix needed"
          - "no action needed"
          - "no TiDB fix"
          - "does not require a fix"
          - "无需修复"
          - "无需处理"
          - "不需要修复"
      semantic:
        id: 4
        title: 修复建议对齐
        description: |
          判断回答是否明确指出 panic 本身不需要 TiDB fix，
          同时允许后续去做 query 或 timeout tuning。
