# Clinic NGM Slow Query order validation

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "clinic-ngm-slow-query-order-validation-2026-09-03",
  "problems": [
    {
      "problemId": "clinic-ngm-unsupported-slow-query-order",
      "summary": "Clinic accepted Slow Query phase fields that the NGM transport does not support as ordering parameters, so shared-tier evidence requests reached NGM and failed with HTTP 400.",
      "status": "optimized_verified",
      "applicability": "Clinic Slow Query evidence acquisition for shared, Starter, or Essential clusters routed through NGM.",
      "issueKeys": ["TCID-13127"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/TCID-13127#problem:clinic-ngm-unsupported-slow-query-order"],
      "signalTextIncludesAny": [
        "unsupported order by 'wait_time'",
        "unsupported order by 'process_time'",
        "unsupported order by 'backoff_time'"
      ],
      "observedThrough": "2026-09-03",
      "effectiveAt": "2026-09-03T07:33:41Z",
      "verifiedAt": "2026-09-03T07:43:55Z",
      "attemptedAction": "Reject wait_time, process_time, and backoff_time locally after resolving an NGM-backed cluster, while preserving query_time, memory_max, and total_keys for NGM and all six orderings for Data Proxy.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/TCID-13127"
    }
  ]
}
-->

## Problem

The generic Slow Query plan validator accepted all orderings supported by the
Data Proxy SQL path. Shared, Starter, and Essential clusters use NGM, whose
Slow Query endpoint rejects `wait_time`, `process_time`, and `backoff_time` as
ordering parameters. Those requests therefore lost otherwise obtainable
evidence to a deterministic HTTP 400.

The first two repairs changed only `src/clinic-evidence-batch.ts`. Staging runs
the Agent9 Managed Tool path, where `managed_auto_oncall_clinic` v23 executed
the request directly and never called that legacy batch helper. Post-deployment
replays consequently still sent `process_time` and then `wait_time`. The earliest
live owner is `tools/agent9-auto-oncall/managed-clinic/index.mjs`.

## Change

After exact cluster metadata selects NGM, the Provider Executor now accepts
only `query_time`, `memory_max`, and `total_keys` before constructing or
sending an NGM Slow Query request. The non-NGM Data Proxy path retains its
existing ordering contract. The change is released as a new immutable Managed
Clinic package rather than only in the unused legacy batch path.

## Verification

A deterministic regression covers shared, Starter, and Essential routing and
asserts that each unsupported ordering produces a local validation failure
without an NGM request. Existing NGM routing tests continue to exercise all
three supported ordering values.

Managed Clinic v24 package digest
`4533c7b06d88d95b52645a507dd576eaf962258d4883c09fe94b7c63ee927b1b`
was installed on the Evidence Agent. Staging image
`5bcba55d9cbeeeab3344de9950e84fcb65492987` became Ready, and read replay
`28c4c46a-ac83-46a9-b736-65c10f708300` executed that exact v24 package. Its
Slow Query acquisition completed without any unsupported-order HTTP 400; the
complete ordered attempt list contains no `wait_time`, `process_time`, or
`backoff_time` rejection.

## Unresolved gaps

The replay was intentionally `mode=read`; it did not write Jira, DB, or Feishu.

## Next validation action

Monitor later NGM replays for recurrence of an upstream unsupported-order 400.
The local transport regression remains the direct proof that every unsupported
ordering is rejected before an NGM request.
