schema_version: 1
case_id: compaction-signals-on-db-tikv-9-in-saas01-during-latest-window
ground_truth:
  root_cause: Correctly evaluating compaction pressure for this case requires exact single-node TiKV metric scope for db-tikv-9 rather than cluster-wide aggregation or over-broad regex matching.
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: 5
    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: 3
      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: pending_compaction_metric_present
      weight: 4
      required: true
      description: Evidence includes TiKV pending compaction byte metrics.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_text_contains_any
        keywords:
        - tikv_engine_pending_compaction_bytes
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - tikv_engine_pending_compaction_bytes
    - id: l0_files_metric_present
      weight: 4
      required: true
      description: Evidence includes TiKV L0 SST file count metrics.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_text_contains_any
        keywords:
        - tikv_engine_num_files_at_level
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - tikv_engine_num_files_at_level
    - id: target_node_evidence_present
      weight: 4
      required: true
      description: Evidence references the target TiKV node identity.
      match: any_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_text_contains_any
        keywords:
        - db-tikv-9
      - source: artifact_json
        artifacts:
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - db-tikv-9
    - id: metric_series_nonempty
      weight: 4
      required: true
      description: Metric evidence includes at least one non-empty time-series payload instead of an all-empty metrics bundle.
      match: all_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_values_nonempty
        path: metrics.chart_data.series.values
    - id: broad_instance_regex_absent
      weight: 6
      required: true
      description: Evidence must not use a broad instance regex that can pull db-tikv-90/91/92 into db-tikv-9 analysis.
      match: all_of
      rules:
      - source: artifact_json
        artifacts:
        - metrics
        matcher: json_values_not_contains_any
        path: metrics.promql
        keywords:
        - instance=~"db-tikv-9.*"
    - id: output_cluster_id_matches_reference
      weight: 6
      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_tikv_node_matches_reference
      weight: 6
      required: true
      description: Output JSON tikv_node matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: tikv_node
        reference_output_id: reference_answer
        reference_path: tikv_node
    - id: output_window_start_matches_reference
      weight: 5
      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: 5
      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: 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: write_cf_pending_compaction_matches_reference
      weight: 8
      required: true
      description: Output JSON write_cf pending compaction bytes match the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: signals.write_cf_pending_compaction_bytes_max
        reference_output_id: reference_answer
        reference_path: signals.write_cf_pending_compaction_bytes_max
    - id: lock_cf_pending_compaction_matches_reference
      weight: 8
      required: true
      description: Output JSON lock_cf pending compaction bytes match the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: signals.lock_cf_pending_compaction_bytes_max
        reference_output_id: reference_answer
        reference_path: signals.lock_cf_pending_compaction_bytes_max
    - id: write_cf_l0_files_matches_reference
      weight: 8
      required: true
      description: Output JSON write_cf L0 file count matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: signals.write_cf_l0_files_max
        reference_output_id: reference_answer
        reference_path: signals.write_cf_l0_files_max
    - id: lock_cf_l0_files_matches_reference
      weight: 8
      required: true
      description: Output JSON lock_cf L0 file count matches the runtime reference.
      match: all_of
      rules:
      - source: output_json
        matcher: json_path_equals_reference
        path: signals.lock_cf_l0_files_max
        reference_output_id: reference_answer
        reference_path: signals.lock_cf_l0_files_max
  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_cluster_id_matches_reference
    description: Output JSON cluster_id matches the runtime reference.
  - id: output_tikv_node_matches_reference
    description: Output JSON tikv_node matches the runtime reference.
  - id: output_window_matches_reference
    description: Output JSON window.start and window.end match the runtime reference.
  - id: output_evidence_sufficient_matches_reference
    description: Output JSON evidence_sufficient matches the runtime reference.
  - id: output_signals_match_reference
    description: Output JSON signals match the runtime reference.
