# Evidence Semantic Query Repair

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "evidence-semantic-query-repair-2026-08-12",
  "problems": [
    {
      "problemId": "evidence-semantic-query-failure-bypasses-agent-repair",
      "summary": "An executed query semantic failure such as APID-29259's Prometheus HTTP 422 remained in the handoff instead of returning to the same Evidence Agent for a changed bounded plan.",
      "status": "optimized_unverified",
      "issueKeys": ["APID-29259"],
      "sourceRefs": [],
      "signalTextIncludesAny": ["HTTP 422", "too many samples", "semantic query repair", "APID-29259"],
      "observedThrough": "2026-08-12",
      "effectiveAt": "2026-08-12T12:08:09Z",
      "verifiedAt": null,
      "attemptedAction": "Return executed-query failures to the same Evidence Agent thread for up to four changed repairs per query in the current acquisition round, while allowing the Agent to stop for non-load-bearing or unrepairable objectives.",
      "evidenceUrl": "https://github.com/tidbcloud/aisupport/tree/main/auto-oncall-services/docs/opts/2026-08-12-evidence-semantic-query-repair.md"
    },
    {
      "problemId": "successful-empty-query-marks-evidence-partial",
      "summary": "Successful provider queries with zero matching rows were preserved as gaps but also incorrectly marked query coverage and the scenario handoff partial.",
      "status": "optimized_unverified",
      "issueKeys": ["APID-29259"],
      "sourceRefs": [],
      "signalTextIncludesAny": ["empty result", "partial handoff", "successful empty", "APID-29259"],
      "observedThrough": "2026-08-12",
      "effectiveAt": "2026-08-12T12:08:09Z",
      "verifiedAt": null,
      "attemptedAction": "Treat a successful empty query as complete acquisition while retaining an explicit gap; reserve partial for failed or incomplete acquisition.",
      "evidenceUrl": "https://github.com/tidbcloud/aisupport/tree/main/auto-oncall-services/docs/opts/2026-08-12-evidence-semantic-query-repair.md"
    }
  ]
}
-->

- Owner: auto-oncall-services
- Source: APID-29259 replay `75da196b-85b7-4062-a0d2-df6cf594b34f`
- Status: optimized_unverified

The previous execution path handed semantic provider failures directly to the
Scenario Diagnostic Agent. Repairing query mechanics then consumed diagnostic
refinement or left a recoverable failure unresolved. The same Evidence Agent
now owns changed-plan repair before scenario diagnosis, with four attempts per
query and an explicit stop decision for noncritical or unsupported objectives.

Successful empty results continue to be visible as evidence gaps, but no longer
make query coverage or the handoff partial. Runtime `degraded` aggregation is
unchanged and still reflects any genuine partial scenario.

Staging read replay `da6748cd-d8a9-4899-acc0-005c364dfce5` reproduced the
Prometheus HTTP 422 for `tikv-grpc-p99-latency`. Before any Scenario Diagnostic
Agent turn for that scenario, the same Evidence Agent thread rewrote the
histogram percentile into a lower-cardinality `_sum/_count` mean grouped by
request type. Repair attempt 1 returned HTTP 200 with 1,445 points across 16
series, and the cumulative query coverage replaced the failed objective with
`complete` and removed its error.

That replay also finished all three scenario handoffs as `complete`, with zero
errors. Successful empty queries remained as 3, 2, and 4 explicit gaps without
making any handoff partial. The final execution status was `complete`, provider
capability was verified, failure codes were empty, and the comparison verdict
was `ai_better`.

A subsequent `mode=write` replay
`1824a3f4-00bc-4b0c-9eee-c46d7fbd1f39` did not finish Router reconciliation
before the 900-second HTTP request limit, so Jira comment refresh is not
verified. Keep both problems `optimized_unverified` until the existing internal
comment is refreshed and read back; do not treat the successful read replay as
publication proof.
