# Clinic Log Identity And Detail Acquisition

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "clinic-log-identity-details-2026-09-01",
  "problems": [
    {
      "problemId": "clinic-log-identity-and-detail-gap",
      "summary": "Clinic log planning could misclassify an opaque numeric connection identifier as a SQL Digest or Statements key, while successful log queries returned counts without the bounded event details needed to diagnose cancellation delivery and completion.",
      "status": "optimized_verified",
      "applicability": "Clinic-backed diagnostics that use ticket-supplied connection, processlist, session, SQL ID, SQL Digest, or plan Digest values to search TiDB component logs.",
      "issueKeys": ["TCID-13107"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/TCID-13107#problem:clinic-log-identity-and-detail-gap"],
      "signalTextIncludesAny": [
        "SQL ID",
        "conn=",
        "kill initiated",
        "kill finished",
        "context canceled"
      ],
      "observedThrough": "2026-09-01",
      "effectiveAt": "2026-09-01T02:40:53Z",
      "verifiedAt": "2026-09-01T03:04:28.409Z",
      "attemptedAction": "Give the Clinic Evidence Agent an explicit connection-versus-Digest identity contract, let each logs_range plan choose summary or safe event detail, and make both Provider Executors return bounded typed event patterns without raw log, SQL, full Digest, or connection identifier disclosure.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/TCID-13107?focusedCommentId=23763151"
    }
  ]
}
-->

- Owner: Clinic Evidence Agent query planning and Clinic Provider Executor
- Source: TCID-13107 feedback task `e97dcc0e3bd6027a`
- Implementation status: merged in PR #1178; Managed Clinic v23 published in
  PR #1180 and installed on the Evidence Agent; exact source SHA deployed to
  staging through app-delivery PRs #78769 and #78770
- Effective status: `optimized_verified`

## Bounded problem

The ticket supplied a numeric value labelled as a SQL ID. TiDB server logs
recorded that value as a connection identifier, but the Evidence plan pursued
Digest and Statements mappings instead of first performing a bounded exact
literal log lookup. The generic log compactor then retained only counts and
timestamps, so even a matching query could not pass the safe cancellation
lifecycle to the Scenario Diagnostic Agent.

## Intended change

Put identifier-shape and LogQL planning knowledge in the Clinic Provider skill.
Keep arbitrary ticket identifiers opaque and search them as exact literals
before assigning connection or Digest semantics. Add an explicit per-query log
detail level. Summary mode retains counts; event mode returns only allowlisted,
typed, grouped TiDB lifecycle facts and safe numeric fields. Raw log messages,
SQL, full Digests, connection IDs, addresses, and other arbitrary strings do
not cross the Provider Executor boundary.

## Verification

On 2026-09-01, the generated Managed Clinic v23 package, TypeScript build, and
focused Clinic/Agent9/diagnostic contract tests passed. The complete repository
suite then passed with 1027 tests and zero failures. Tests prove exact-literal
connection lookup guidance, Digest-shape guidance, summary-versus-event
selection, chronological typed event materialization through both execution
paths, explicit empty-log gaps, duration-unit normalization, and exclusion of
raw identifiers, SQL, Digests, and field-contained false event markers.

PR #1178 merged the implementation. PR #1180 published immutable Managed
Clinic v23 with package digest
`6ddddb1171235b49b986045d9ce9252d03a6dc53e8a6f544f41e55406ae2a89b`
and bundle digest
`8698c3f9734ae4d7cce19727f6ef1ee774f60b18e3b6912a8709a5d3e027ca51`.
The unified staging release installed v23 on the Evidence Agent and deployed
source SHA `781355f543dfd4b5e56b703b8c6dc1e927244b8e`. The active staging Pod became
Ready at `2026-09-01T02:40:53Z` with zero restarts; `/healthz` and `/readyz`
both returned HTTP 200.

One bounded `mode=read` replay of TCID-13107 completed with HTTP 200 in
557.737546 seconds as run `c3fab34d-fc58-425a-8773-05f62a3f7b23`. Managed
Clinic v23 completed 14 of 14 primary objectives across two evidence rounds
with zero Provider errors. The opaque numeric SQL ID was resolved through the
exact connection-lifecycle log path, and `detailLevel=events` materialized
bounded `remote_connection_kill_received`, `kill_initiated`, and
`expensive_query_progress` facts. The replay established identity attribution,
showed that seven kill requests reached TiDB while lifecycle records continued,
and preserved the remaining uncertainty between a delayed cancellation
checkpoint and transaction cleanup. The historical Clinic HTTP 400 did not
recur. Read mode requested no Jira, database, evaluation-persistence, or Feishu
publication side effects.

After explicit write authorization, the already verified replay ADF was written
directly to the existing stable Jira internal comment `23763151`; analysis was
not rerun. The write used Jira Platform `PUT` and returned HTTP 200. Jira
Platform and JSM readback of that exact comment both returned HTTP 200, JSM
retained `public=false`, and the normalized readback body digest was
`44b835c481e1d059211ef5dc49054e2a5daecf0bd4b2a2c42c5bc472bcfd2453`.
The canonical DB mapping remained unique and unchanged at
`auto-live:v1:TCID-13107:initial -> 23763151`. No new comment, analysis run,
evaluation row, or Base history was created by this direct recovery.

## Next validation action

Monitor later Clinic-backed connection-cancellation cases for recurrence of
identifier misclassification or missing lifecycle detail. Treat a different
causal or mitigation gap in TCID-13107 as a separate problem signal.
