schema_version: 1
case_id: single-node-cpu-core-scope-compare-in-premium-cluster-during-incident-window
ground_truth:
  root_cause: >-
    Correctly answering this ad-hoc case requires isolating the exact TiKV pod
    `the runtime-selected target TiKV node`, deriving its CPU spec cores from TiKV quota evidence, and
    returning the average and peak CPU cores for the three fixed 30-minute
    windows without mixing in `the runtime-selected target TiKV node0/91/...` or cluster-wide aggregates.
judge:
  semantic_strategy: undecided
  contract:
    checks:
    - id: cluster_scope_match
      required: true
      description: Actual diagnosis cluster scope matches the expected cluster id.
      match: all_of
      rules:
      - source: trace_fact
        matcher: bool_true
        path: cluster_scope_match
  workflow:
    checks:
    - id: final_answer_emitted
      weight: 0
      required: true
      description: Final answer is emitted for the ad-hoc query.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_true
        path: final_answer_emitted
    - id: collect_evidence_not_used
      weight: 0
      required: true
      description: This ad-hoc case must not invoke collect_evidence.py.
      match: all_of
      rules:
      - source: workflow_fact
        matcher: bool_false
        path: collect_evidence_invoked
  execution_contract:
    checks:
    - id: required_workflow_present
      required: true
      description: The minimal ad-hoc workflow is present.
      match: all_of
      rules:
      - source: workflow_check
        matcher: subset_observed
        paths:
        - final_answer_emitted
    - id: collect_evidence_not_used
      required: true
      description: This ad-hoc case must not invoke collect_evidence.py.
      match: all_of
      rules:
      - source: workflow_check
        matcher: subset_observed
        paths:
        - collect_evidence_not_used
    - id: required_report_present
      required: true
      description: Workspace diagnosis report is present.
      match: all_of
      rules:
      - source: artifact_fact
        matcher: subset_observed
        paths:
        - diagnosis_report_present
    - id: query_or_metric_channel_observed
      required: true
      description: At least one query or metric evidence channel is observed.
      match: all_of
      rules:
      - source: channel_fact
        matcher: count_gte
        paths:
        - query_or_metric
        threshold: 1
  evidence_collection:
    weight: 6
    checks:
    - id: required_report_present
      weight: 2
      required: true
      description: Workspace diagnosis report is present and readable.
      match: all_of
      rules:
      - source: artifact_fact
        matcher: subset_observed
        paths:
        - diagnosis_report_present
    - id: query_or_metric_channel_observed
      weight: 2
      required: true
      description: Query or metric evidence is observed for this ad-hoc request.
      match: all_of
      rules:
      - source: channel_fact
        matcher: count_gte
        paths:
        - query_or_metric
        threshold: 1
  critical_evidence:
    weight: 79
    checks:
    - id: cpu_metric_evidence_present
      weight: 5
      required: true
      description: Evidence includes TiKV CPU core and quota metrics for this request.
      match: all_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - process_cpu_seconds_total
      - source: artifact_json
        artifacts:
        - metrics
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - tikv_server_cpu_cores_quota
    - id: cpu_1m_rate_window_evidence_present
      weight: 4
      required: true
      description: Evidence shows the CPU query used the 1-minute rate window rather than a wider window.
      match: all_of
      rules:
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - rate(process_cpu_seconds_total
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - '[1m]'
    - id: output_cluster_id_matches_reference
      weight: 5
      required: true
      description: Output JSON cluster_id matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: cluster_id
        reference_output_id: reference_answer
        reference_path: cluster_id
    - id: output_node_matches_reference
      weight: 8
      required: true
      description: Output JSON node matches the exact runtime reference node.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: node
        reference_output_id: reference_answer
        reference_path: node
    - id: output_cpu_spec_matches_reference
      weight: 12
      required: true
      description: Output JSON cpu_spec_cores matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: cpu_spec_cores
        reference_output_id: reference_answer
        reference_path: cpu_spec_cores
    - id: evidence_sufficient_matches_reference
      weight: 4
      required: true
      description: Output JSON evidence_sufficient matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: evidence_sufficient
        reference_output_id: reference_answer
        reference_path: evidence_sufficient
    - id: windows_identity_matches_reference
      weight: 20
      required: true
      description: Output JSON windows ordering and identity fields match the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_array_matches_reference
        path: windows
        reference_output_id: reference_answer
        reference_path: windows
        key_fields:
        - start
        - end
    - id: windows_numeric_fields_match_reference
      weight: 25
      required: true
      description: Output JSON windows numeric fields match the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_array_matches_reference
        path: windows
        reference_output_id: reference_answer
        reference_path: windows
        key_fields:
        - start
        - end
        numeric_fields:
        - avg_cpu_cores
        - peak_cpu_cores
        threshold: 0.0001
  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
  critical:
  - id: output_node_matches_reference
    description: Output JSON node matches the exact runtime reference node.
  - id: output_cpu_spec_matches_reference
    description: Output JSON cpu_spec_cores matches the runtime reference.
  - id: output_windows_match_reference
    description: Output JSON windows match the runtime reference values and ordering.
  - id: cpu_1m_rate_window_evidence_present
    description: CPU evidence uses the 1-minute rate window, not a wider one.
