# Managed Clinic TopSQL capability gap

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "managed-clinic-topsql-capability-gap-2026-09-03",
  "problems": [
    {
      "problemId": "managed-clinic-topsql-unconfigured-repair-loop",
      "summary": "Managed Clinic classified an unconfigured TopSQL data source as a repairable request rejection, so the Evidence Agent repeatedly rewrote a query that could not enable the missing capability.",
      "status": "optimized_verified",
      "applicability": "Agent9 Managed Clinic TopSQL operations whose exact provider response is HTTP 400 FailedPrecondition because the data source is not configured.",
      "issueKeys": ["TCID-13127"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/TCID-13127#problem:managed-clinic-topsql-unconfigured-repair-loop"],
      "signalTextIncludesAny": ["FailedPrecondition", "data source is not configured", "clinic_topsql_datasource_not_configured"],
      "observedThrough": "2026-09-03",
      "effectiveAt": "2026-09-03T07:33:41Z",
      "verifiedAt": "2026-09-03T07:43:55Z",
      "attemptedAction": "Map only the exact Managed Clinic TopSQL unconfigured-data-source response to clinic_topsql_datasource_not_configured with repair.eligible=false while preserving ordinary request repair for other Clinic 4xx responses.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/TCID-13127"
    }
  ]
}
-->

## Problem

The earlier deterministic Clinic batch helper already recognized this Provider
capability response, but staging now executes TopSQL through the Agent9 Managed
Clinic Tool. Its generic HTTP boundary marked every 4xx as `correct_request`.
The exact TCID-13127 run therefore produced the same `FailedPrecondition` result
for the initial plan and two correction attempts.

## Change

The TopSQL operation alone translates Clinic HTTP 400 with upstream code
`FailedPrecondition` and an unconfigured-data-source message to
`clinic_topsql_datasource_not_configured`. It preserves safe upstream request
metadata and the response digest, but sets `repair.eligible=false`. Generic SQL,
Statements, other operations, and other Clinic 4xx responses are unchanged.

## Verification

A deterministic Managed Tool regression asserts the exact canonical error,
capability classification, preserved request ID, and non-repairable contract.

Managed Clinic v24 package digest
`4533c7b06d88d95b52645a507dd576eaf962258d4883c09fe94b7c63ee927b1b`
was installed on the Evidence Agent and executed by staging read replay
`28c4c46a-ac83-46a9-b736-65c10f708300`. The complete ordered attempt list has
exactly one TopSQL attempt. It returned
`clinic_topsql_datasource_not_configured`, HTTP 400,
`upstreamErrorCode=FailedPrecondition`, and `repairEligible=false`; there is no
later TopSQL correction attempt.

## Unresolved gaps

The upstream TopSQL source remains unavailable until the cluster capability is
configured. This repair only prevents meaningless query correction.
The replay was intentionally `mode=read`; it did not write Jira, DB, or Feishu.

## Next validation action

Monitor later replays for a second TopSQL attempt after
`clinic_topsql_datasource_not_configured`; any such correction is a regression.
