schema_version: 1
case_id: topsql-links-for-hottest-two-tikv-nodes-during-incident-window
ground_truth:
  root_cause: Correct TopSQL links require first identifying the hottest TiKV nodes within the target cluster and window, then generating per-instance TopSQL URLs for those exact TiKV instances.
judge:
  semantic_strategy: undecided
  contract:
    checks:
    - id: time_window_match
      required: true
      description: Actual diagnosis time window matches the runtime-resolved 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 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: 4
    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: 80
    checks:
    - id: raw_disk_read_metric_present
      weight: 4
      required: true
      description: Evidence includes node-level disk read metric collection.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_text_contains_any
        keywords:
        - node_disk_reads_completed_total
        - rate(node_disk_reads_completed_total
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - node_disk_reads_completed_total
        - rate(node_disk_reads_completed_total
    - id: cluster_scoped_mapping_evidence_present
      weight: 6
      required: true
      description: Evidence shows a cluster-scoped mapping or node-filter strategy for TiKV disk reads.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_text_contains_any
        keywords:
        - kube_pod_info
        - instance=~
        - count by (node)
        - label_replace(
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - kube_pod_info
        - instance=~
        - count by (node)
        - label_replace(
    - id: output_cluster_id_matches_reference
      weight: 4
      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_window_start_matches_reference
      weight: 4
      required: true
      description: Output JSON window.start matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: window.start
        reference_output_id: reference_answer
        reference_path: window.start
    - id: output_window_end_matches_reference
      weight: 4
      required: true
      description: Output JSON window.end matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: window.end
        reference_output_id: reference_answer
        reference_path: window.end
    - id: mapping_strategy_matches_reference
      weight: 4
      required: true
      description: Output JSON mapping_strategy matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: mapping_strategy
        reference_output_id: reference_answer
        reference_path: mapping_strategy
    - 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: topsql_links_present
      weight: 3
      required: true
      description: Output JSON contains a non-empty TopSQL link list.
      match: all_of
      rules:
      - source: output_json
        matcher: json_list_nonempty
        path: topsql_links
    - id: topsql_links_have_two_unique_tikv_nodes
      weight: 4
      required: true
      description: Output JSON contains two unique TiKV node names.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_unique_count_gte
        path: topsql_links.tikv_node
        threshold: 2
    - id: topsql_link_nodes_match_runtime_reference
      weight: 7
      required: true
      description: Output JSON node ordering matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_array_matches_reference
        path: topsql_links
        reference_output_id: reference_answer
        reference_path: topsql_links
        key_fields:
        - tikv_node
    - id: topsql_urls_match_runtime_reference
      weight: 10
      required: true
      description: Output JSON TopSQL URLs match the runtime reference semantics for cluster, window, and instance.
      match: all_of
      rules:
      - source: output_json
        matcher: topsql_url_semantically_matches_reference
        path: topsql_links
        reference_output_id: reference_answer
        reference_path: topsql_links
  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_window_matches_reference
    description: Output JSON window.start and window.end match the runtime reference.
  - id: output_mapping_strategy_matches_reference
    description: Output JSON mapping_strategy matches the runtime reference.
  - id: output_evidence_sufficient_matches_reference
    description: Output JSON evidence_sufficient matches the runtime reference.
  - id: output_topsql_link_nodes_match_reference
    description: Output JSON TopSQL link node ordering matches the runtime reference.
  - id: output_topsql_urls_match_reference
    description: Output JSON TopSQL URLs match the runtime reference semantics.
