schema_version: 1
case_id: insert-latency-degradation-during-incident-window
ground_truth:
  expected_diagnosis_skill_routes: []
  root_cause: DNS resource exhaustion first delayed name resolution and connection establishment. Application-side query kills then exercised an Auto ID service cancellation bug, leaving Auto-ID-related inserts abnormally slow after the DNS event had eased, especially on a newly started TiDB instance. DNS capacity and the Auto ID hotfix are both required; treating the whole window as a single storage slowdown is incorrect.
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
        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
  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
        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
  critical_evidence:
    weight: 30
    checks:
    - id: primary_symptom_evidence_present
      weight: 10
      description: Primary symptom evidence is present in the collected evidence.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - INSERT
        - 10 minutes
        - DNS
        - kill
        - new TiDB
      - source: artifact_json
        artifacts:
        - metrics
        - queries
        - summary_json
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - INSERT
        - 10 minutes
        - DNS
        - kill
        - new TiDB
    - id: root_cause_mechanism_evidence_present
      weight: 10
      description: Root-cause mechanism evidence is present in the collected evidence.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - Auto ID
        - cancellation
        - context cancellation
        - bug
        - query kill
      - source: artifact_json
        artifacts:
        - metrics
        - queries
        - summary_json
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - Auto ID
        - cancellation
        - context cancellation
        - bug
        - query kill
    - id: scope_or_timeline_evidence_present
      weight: 10
      description: Timeline evidence is present in the collected evidence.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - 06:10
        - '13:39'
        - DNS resource
        - continued
        - TiDB-2993
      - source: artifact_json
        artifacts:
        - metrics
        - queries
        - summary_json
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - 06:10
        - '13:39'
        - DNS resource
        - continued
        - TiDB-2993
  evidence_routing:
    weight: 5
    checks:
    - id: specialist_routing_contract
      weight: 3
      required: true
      description: Diagnosis is authored by the analyst with a valid classification and the expected specialist route.
      match: all_of
      rules:
      - source: routing_fact
        matcher: bool_true
        path: diagnosis_analyst_dispatched
      - source: routing_fact
        matcher: bool_true
        path: classification_contract_valid
      - source: routing_fact
        matcher: bool_true
        path: expected_diagnosis_skill_routes_selected
    - 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_patch_present
      - 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_patch_present
      - source: routing_fact
        matcher: bool_true
        path: analysis_query_refs_resolvable
  diagnosis:
    checks:
    - id: identify_primary_failure_mechanism
      mode: blended
      weight: 3
      required: true
      description: Primary failure mechanism is identified and supported.
      deterministic:
        match: all_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - DNS
          - name resolution
        - source: output_text
          matcher: keyword_any
          keywords:
          - kill
          - cancel
        - source: output_text
          matcher: keyword_any
          keywords:
          - Auto ID
          - AutoID
      semantic:
        id: 1
        title: Primary failure mechanism
        description: The answer identifies the two-stage DNS trigger and Auto ID cancellation defect.
    - id: explain_causal_chain
      mode: blended
      weight: 3
      required: true
      description: Causal chain is identified and supported.
      deterministic:
        match: all_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - connection
          - DNS
        - source: output_text
          matcher: keyword_any
          keywords:
          - application
          - kill
          - context cancellation
        - source: output_text
          matcher: keyword_any
          keywords:
          - INSERT
          - continued
          - new TiDB
      semantic:
        id: 2
        title: Causal chain
        description: The answer reconstructs why latency persisted after the initial DNS pressure eased.
    - id: recommend_aligned_remediation
      mode: blended
      weight: 3
      required: true
      description: Aligned remediation is identified and supported.
      deterministic:
        match: all_of
        rules:
        - source: output_text
          matcher: keyword_any
          keywords:
          - DNS
          - capacity
          - resource
        - source: output_text
          matcher: keyword_any
          keywords:
          - Auto ID
          - hotfix
          - upgrade
        - source: output_text
          matcher: keyword_any
          keywords:
          - kill
          - retry
          - application
      semantic:
        id: 3
        title: Aligned remediation
        description: The answer recommends both DNS capacity remediation and the Auto ID fix, with safer cancellation/retry handling.
