# TopSQL Digest Handoff

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "topsql-digest-handoff-2026-08-13",
  "problems": [
    {
      "problemId": "topsql-sql-digest-not-normalized-to-safe-prefix",
      "summary": "Wetech TopSQL returns workload identity in sql_digest, but the strict handoff only recognizes digest and therefore drops the safe Digest prefix before Scenario diagnosis.",
      "status": "optimized_verified",
      "applicability": "Wetech and Manus TopSQL compact rows that expose sql_digest while raw SQL and complete opaque identifiers remain outside the strict Scenario handoff.",
      "issueKeys": ["APID-29274"],
      "sourceRefs": [
        "https://tidb.atlassian.net/browse/APID-29274#problem:topsql-sql-digest-not-normalized-to-safe-prefix"
      ],
      "signalTextIncludesAny": [
        "topsql sql_digest missing from handoff",
        "provider found digest but scenario only sees statement type and object",
        "workload identity lost before scenario diagnosis"
      ],
      "observedThrough": "2026-08-13",
      "effectiveAt": "2026-08-13T14:53:00Z",
      "verifiedAt": "2026-08-13T15:16:00Z",
      "attemptedAction": "Accept provider sql_digest as the existing workload Digest owner and reduce it to the same 12-character safe digest_prefix already used for digest, without exposing raw SQL, full Digest, or plan text.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/APID-29274?focusedCommentId=23351216"
    }
  ]
}
-->

- Optimization ID: `topsql-digest-handoff-2026-08-13`
- Owner: OP Provider Executor compact handoff
- Source reference: `APID-29274` read-only TopSQL acquisition
- Implementation status: deployed to staging in image `917145b45f408a2a89a1c4c5ac301eb9e0d785df`
- Effective status: `optimized_verified`

## Bounded problem

APID-29274 read-only run `3bb42238-d987-4593-8353-8de70676cfbd`
successfully queried TopSQL and materialized 21 rows with `sql_digest`, SQL
text, CPU, execution rate, duration, and scan fields in the provider compact
artifact. The strict Scenario handoff correctly removed raw SQL and complete
Digest values, but it only derived `digest_prefix` from a field named
`digest`. Wetech TopSQL uses `sql_digest`, so the downstream Scenario
Diagnostic Agent received only statement type and table objects.

This is a handoff normalization defect. Provider planning and execution were
complete, and the fix does not change TopSQL selection, ranking, or diagnosis.

## Candidate change

- Treat `sql_digest` as the same Provider-owned workload identifier already
  represented by `digest`.
- Emit only the existing 12-character `digest_prefix` safe fact.
- Continue excluding raw SQL, full Digest, plan text, and arbitrary Provider
  strings from the Scenario handoff.

## Verification evidence

The local OP evidence regression now requires
`sql_digest=0123456789abcdef` to become
`digest_prefix=0123456789ab` while proving that raw SQL, the full Digest, and
plan text remain absent. The complete local suite passes.

Post-deployment write run `5b552e11-7ad7-4ce7-949e-8e6b5f4d6431` completed
TopSQL acquisition and passed bounded 12-character `digest_prefix` facts such
as `e1b696a5155d` and `85047cee0e6d` into the strict Scenario handoff. Full
Digest values and raw SQL remained absent. The run persisted as DB run
`150033`, was judged `ai_better`, and refreshed private comment `23351216`.

## Unresolved gaps

- The historical-window candidates are not the later DELETE found by Support.
  No aligned plan or scan evidence makes a query ready for tuning.

## Next validation action

Monitor other TopSQL handoffs for safe-prefix preservation. Keep query identity
as a candidate rather than a root cause unless aligned plan or scan evidence
establishes the mechanism.
