schema_version: 1
case_id: system-unavailability-during-incident-window
ground_truth:
  root_cause: Multiple coprocessor workers disappeared, leaving one remaining worker overloaded and repeatedly restarting, which cascaded into cluster-wide request backlog and outage-level latency
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_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
        - logs
        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
        - logs
  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
        - logs
        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
        - logs
  critical_evidence:
    weight: 30
    checks:
    - id: capacity_loss_signal_present
      weight: 8
      description: Evidence shows a major drop in available coprocessor worker capacity during the incident.
      match: all_of
      rules:
      - source: artifact_json
        artifacts:
        - component_health
        matcher: json_values_contains_any
        path: component_health.component_count.component
        keywords:
        - coprocessor-worker
      - source: artifact_json
        artifacts:
        - component_health
        matcher: json_numeric_any_lt
        path: component_health.component_count.changes
        threshold: 0
    - id: restart_or_oom_signal_present
      weight: 8
      description: Evidence shows the remaining worker entered restart or memory-failure behavior.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - component_health
        matcher: json_list_nonempty
        path: component_health.restarts
      - source: logs
        matcher: keyword_any
        keywords:
        - OOM
        - out of memory
        - restart
        - coprocessor
    - id: coprocessor_cascade_signal_present
      weight: 9
      description: Evidence links the worker failure to latency explosion and QPS collapse.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - timeout
        - backlog
        - unavailable
      - source: artifact_json
        artifacts:
        - summary_json
        matcher: json_text_contains_any
        keywords:
        - qps collapse
        - request backlog
        - outage
        - latency spike
  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 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 references 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_worker_capacity_collapse_as_primary_path
      mode: blended
      weight: 3
      required: true
      description: Identifies coprocessor worker capacity collapse rather than a pure query-side explanation.
      deterministic:
        match: all_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - coprocessor worker
          - worker capacity
          - worker offline
          - worker disappeared
          - coprocessor capacity
          - coprocessor worker count
      semantic:
        id: 1
        title: 主路径判断
        description: |
          判断回答是否把主路径识别为 coprocessor worker capacity collapse，
          而不是 query-only 或 generic slow-SQL explanation。
    - id: identify_restart_loop_as_key_amplifier
      mode: blended
      weight: 3
      required: false
      description: Identifies restart or OOM looping on the remaining worker as the main amplifier.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - OOM
          - restart loop
          - repeated restart
          - crash loop
          - memory spike
          - overload on the remaining worker
          - 单个剩余 worker
          - 重启循环
      semantic:
        id: 2
        title: 放大链路解释
        description: |
          判断回答是否识别剩余 worker 上的 OOM、restart loop
          或 overload 作为 outage 的关键 amplifier。
    - id: reject_query_only_primary_root_cause
      mode: blended
      scoring_mode: penalty
      weight: 3
      required: false
      description: Does not stop at a query-only or generic slow-SQL root cause.
      deterministic:
        match: all_of
        rules:
        - source: output_fact
          matcher: bool_false
          path: query_only_primary_root_cause_asserted
      semantic:
        id: 3
        title: query-only 误诊排除
        description: |
          判断回答是否避免把问题解释成 query-only、generic slow SQL
          或 missing-index style root cause。
    - id: reconstruct_capacity_to_outage_chain
      mode: blended
      weight: 4
      required: false
      description: Reconstructs the cascade from worker loss to outage symptoms.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - qps collapse
          - request backlog
          - coprocessor latency
          - grpc blocking
          - cluster outage
          - QPS 下跌
          - 请求堆积
      semantic:
        id: 4
        title: 容量到故障链路
        description: |
          判断回答是否把 worker loss、capacity collapse 与
          QPS drop、request backlog、latency/outage 症状串成完整链路。
    - id: recommend_capacity_protection
      mode: blended
      weight: 4
      required: false
      description: Recommends capacity-protection actions such as minimum replicas or better scaling guardrails.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - minReplicas
          - minimum replicas
          - HPA
          - autoscaling
          - worker count alert
          - 最小副本
          - 扩缩容
      semantic:
        id: 5
        title: 容量保护建议
        description: |
          判断回答是否给出 min replicas、autoscaling guardrail
          或 worker-capacity protection 这类对齐 remediation。
    - id: recommend_worker_health_followup
      mode: blended
      weight: 4
      required: false
      description: Recommends follow-up on the initial worker disappearance cause.
      deterministic:
        match: any_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - node eviction
          - worker disappearance
          - initial trigger
          - HPA decision
          - 节点驱逐
      semantic:
        id: 6
        title: 初始触发跟进
        description: |
          判断回答是否指出需要继续追 worker disappearance 的 initial trigger，
          例如 node eviction 或 HPA decision。
