# Clinic metadata preflight query accounting

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "clinic-preflight-query-count-2026-09-07",
  "problems": [
    {
      "problemId": "clinic-preflight-counted-against-diagnostic-batch",
      "summary": "The mandatory Clinic metadata preflight consumes a diagnostic query slot and rejects a valid twelve-query evidence batch before scenario diagnosis.",
      "status": "candidate",
      "applicability": "Agent9 Clinic round-one evidence with a leading metadata-only cluster_detail batch followed by bounded diagnostic queries.",
      "issueKeys": ["TCID-13132"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/TCID-13132#problem:clinic-preflight-counted-against-diagnostic-batch"],
      "signalTextIncludesAny": ["diagnostic_evidence_agent_provider_tool_count_invalid"],
      "observedThrough": "2026-09-07",
      "effectiveAt": null,
      "verifiedAt": null,
      "attemptedAction": "Separate the first Clinic metadata-only preflight batch from the twelve diagnostic-query limit while retaining all results and attempts. Frozen-source regression passes; deployment and full replay remain pending.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/TCID-13132"
    }
  ]
}
-->

Owner: runner materialization in `src/agent9-provider-evidence.ts`.
Base: `3ffce0e58becc94d1af8a1cd00ea5a376d2e4f16`.
Source: operator-requested TCID-13132 follow-up; frozen isolated read run
`02d9f811-e378-4298-b538-79927b0c3c1d`, fingerprint
`b6466ac2b9667b53f36be34d3d0b05997a01d513782e4980d6ff78ebfa6ef0ad`.

That read completed in 740,284 ms with Clinic acquisition complete, but
query-latency and tiflash-io-apply each failed handoff materialization after one
metadata query plus twelve diagnostic queries. Workload-hotspot used one plus
eleven and succeeded. These are scenario failures, not Provider HTTP failures.

Only the first metadata-only Clinic batch in round one is exempt from the
diagnostic-query count. Recognition uses structured operation results, not a
special query ID. All preflight facts, failures, coverage and attempts remain
materialized. Later or mixed metadata batches and refinement rounds retain
the existing limit. No Provider package, prompt, timeout or model budget changes.

Nine new deterministic regressions cover both affected scenarios, multiple
preflight targets, retained metadata failures and corrected-query attempts,
thirteen diagnostic queries, and non-preflight metadata. Together with existing
Managed Provider tests, 23 focused tests passed. Full validation also passed:
1,187 service tests and six isolated-runner script checks (no LLM execution).

Offline comparison applies the unchanged frozen Provider turns to baseline
and fixed materializers. Baseline reproduces the count error for both affected
scenarios; fixed query-latency retains 13 coverage entries and six observations
(44,724 UTF-8 JSON bytes), and fixed tiflash-io-apply retains 13 entries and
three observations (33,800 bytes), both complete with no errors. The
workload-hotspot control is unchanged at 12 entries, five observations and
34,228 bytes. No LLM or Provider is invoked by this validation.

Next: after an authorized deployment, one isolated TCID-13132 read must verify
that these handoffs reach Scenario Diagnostic and that the earlier independent
120-second finalization timeout does not recur. The frozen comparison does not
verify that model stage, the final diagnosis, Jira publication or optimization
status completion. Keep this record at candidate until live verification.
