schema_version: 1
case_id: transaction-outcome-after-node-failure
ground_truth:
  expected_diagnosis_skill_routes:
  - any_of:
    - transaction-oncall-handbook
  root_cause: The case is a transaction-semantics question, not a TiDB bug. Definite prewrite rejection can be retried or reported as failure, but an RPC or connection failure may lose the response after TiKV processed a request. If retries cannot determine the final commit state, TiDB can return an undetermined outcome. Clients must use idempotent operations or query business state instead of assuming every returned error means rollback.
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: 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:
        - region is missing
        - peer is not leader
        - Prewrite
        - RPC
        - node failure
      - source: artifact_json
        artifacts:
        - metrics
        - queries
        - summary_json
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - region is missing
        - peer is not leader
        - Prewrite
        - RPC
        - node failure
    - id: root_cause_mechanism_evidence_present
      weight: 10
      description: Transaction-state evidence is present in the collected evidence.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - Undetermined
        - response lost
        - commit state
        - retry
        - prewrite
      - source: artifact_json
        artifacts:
        - metrics
        - queries
        - summary_json
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - Undetermined
        - response lost
        - commit state
        - retry
        - prewrite
    - id: scope_or_timeline_evidence_present
      weight: 10
      description: Client-contract evidence is present in the collected evidence.
      match: any_of
      rules:
      - source: logs
        matcher: keyword_any
        keywords:
        - idempotent
        - business query
        - application
        - error
        - rollback
      - source: artifact_json
        artifacts:
        - metrics
        - queries
        - summary_json
        - workspace_report
        matcher: json_text_contains_any
        keywords:
        - idempotent
        - business query
        - application
        - error
        - rollback
  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:
          - RPC
          - connection
        - source: output_text
          matcher: keyword_any
          keywords:
          - response
          - lost
        - source: output_text
          matcher: keyword_any
          keywords:
          - Undetermined
          - unknown outcome
      semantic:
        id: 1
        title: Primary failure mechanism
        description: The answer distinguishes an unknown response outcome from a confirmed transaction rollback.
    - 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:
          - Prewrite
          - Commit
        - source: output_text
          matcher: keyword_any
          keywords:
          - processed
          - dropped
          - retry
        - source: output_text
          matcher: keyword_any
          keywords:
          - application
          - error
      semantic:
        id: 2
        title: Causal chain
        description: The answer explains why transport failure can hide whether TiKV processed a phase.
    - 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:
          - idempotent
          - idempotency
        - source: output_text
          matcher: keyword_any
          keywords:
          - business query
          - check state
          - reconcile
        - source: output_text
          matcher: keyword_any
          keywords:
          - retry
      semantic:
        id: 3
        title: Aligned remediation
        description: The answer recommends idempotent retry and business-state verification.
