# Exact Query Plan Evidence Handoff

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "exact-query-plan-evidence-2026-08-18",
  "problems": [
    {
      "problemId": "sql-performance-exact-query-plan-evidence-missing",
      "summary": "SQL performance runs could discover Slow Query rows but did not deterministically bind a supplied Digest or materialize the representative decoded plan, and Clinic plan queries could fail because the Evidence Agent had to hand-author date partitions.",
      "status": "ineffective",
      "applicability": "Provider-backed sql_performance_tuning query-latency or query-execution scenarios with a supplied Digest or an incident-overlapping Slow Query candidate.",
      "issueKeys": ["APID-29340", "APID-29344", "TCID-12989", "TCID-13038"],
      "sourceRefs": [
        "https://tidb.atlassian.net/browse/APID-29340#problem:exact-query-plan-evidence-missing",
        "https://tidb.atlassian.net/browse/APID-29344#problem:exact-query-plan-evidence-missing",
        "https://tidb.atlassian.net/browse/TCID-12989#problem:clinic-query-plan-partition-missing",
        "https://tidb.atlassian.net/browse/TCID-13038#problem:clinic-query-plan-partition-missing"
      ],
      "signalTextIncludesAny": [
        "exact digest was not used for slow query",
        "decoded plan was not materialized",
        "clinic_sql_partition_filter_missing",
        "query identity remained unresolved"
      ],
      "observedThrough": "2026-08-18",
      "effectiveAt": "2026-08-18T02:06:49Z",
      "verifiedAt": "2026-08-18T02:48:05Z",
      "attemptedAction": "Copy the existing customer-evidence Digest into the immutable Provider context, bind a single supplied Digest during runner-owned parameter normalization, request Wetech plan projections for that narrow Digest, and make Clinic Slow Query generate UTC partitions and retrieve one exact decoded-plan profile; both Provider Executors reduce decoded plans to safe operator facts.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/TCID-13038?focusedCommentId=23553739"
    }
  ]
}
-->

- Optimization ID: `exact-query-plan-evidence-2026-08-18`
- Owner: runner-owned Provider context and Provider Executor
- Source references: `APID-29340`, `APID-29344`, `TCID-12989`, `TCID-13038`
- Implementation status: deployed to staging in image `3d785707e86be521b2c2f6168e096b4b2cc916e0`; source-case replay completed
- Effective status: `ineffective`

## Bounded problem

The SQL performance path did not have one deterministic exact-query evidence
packet. A supplied Digest could remain only in Jira/customer evidence while an
OP Slow Query plan used a broad text approximation. Clinic could return Slow
Query candidates, but retrieving `decoded_plan`, statistics, and indexes
required Agent-authored generic SQL; missing literal date partitions caused
the query to fail before evidence reached Scenario diagnosis.

## Change

- Copy the existing runner-extracted SQL Digest list into the immutable Clinic
  or OP query context. This is a transport handoff, not a second identity owner.
- Bind one supplied Digest to query-latency/query-execution Slow Query at the
  Provider Executor boundary.
- For that narrow Wetech request, add available binary-plan projections and
  reduce only decoded JSON/text to safe operator facts. Preserve encoded-only
  or unavailable as an explicit plan gap.
- Let Clinic Slow Query generate UTC partitions, select one overlapping exact
  Digest, and perform one bounded plan-profile lookup.
- Cross the handoff with only structured operator, row-estimate, runtime,
  memory/spill, statistics, index, scan, and wait facts. Raw SQL, raw plan text,
  predicates, and full Digests remain excluded.

## Verification status

Staging deployment was Ready with zero Pod restarts on 2026-08-18. Local
regression coverage verifies exact Digest and plan-projection binding for
Wetech, safe Wetech decoded-plan compaction and handoff, exact Digest binding
for Clinic, helper-owned Data Proxy partitions, one NGM decoded-plan profile,
safe plan compaction, and the resulting Scenario handoff facts.

The four deployed write replays did not verify the bounded source-case
criterion:

- `APID-29340` run `20932265-239a-409c-865e-41271b1ea78b` stopped before
  Provider execution with `diagnostic_wetech_target_missing`.
- `APID-29344` run `6aa66004-e09a-49bf-af92-4f43f1df3a3b` completed Wetech
  acquisition and was judged `ai_better`, but the diagnosis still reported no
  complete representative plan or operator details. Its supplied plan image
  remains outside this action.
- `TCID-12989` run `fed7f789-cfe6-4c33-bbd8-0d60894ef112` obtained Slow Query
  rows but a SQL metadata request failed with
  `clinic_sql_partition_filter_missing`; the run remained degraded and
  `human_required`.
- `TCID-13038` run `69adacb2-2539-4d8c-b1e3-bc6eda333e4b` obtained Slow Query
  rows, but the bounded plan path failed with
  `clinic_slow_query_digest_invalid`; the diagnosis still reported no
  decodable representative plan and the Judge returned `human_better`.

All four runs were persisted as DB runs `150079` through `150082`, updated
their existing Jira internal comments in place, and refreshed the Base rows.
Jira readback confirmed comment IDs `23548869`, `23559192`, `23371042`, and
`23553739` remained `public=false` and contained the replayed bodies.

## Unresolved gaps

- OP plan images supplied only as attachments remain a separate supplied-
  artifact consumption problem.
- Wetech target resolution can stop the run before the exact-query path.
- Clinic metadata SQL still needs runner-owned partition handling independent
  of the Slow Query helper path.
- The exact digest selected from a materialized Slow Query row can still be
  rejected before plan retrieval.

## Next validation action

Do not repeat this same handoff action. Treat target resolution, supplied-plan
artifact consumption, Clinic metadata-SQL partitioning, and Slow Query digest
validation as separate earliest-owner problems before another source replay.
