# Clinic Live Window Canonicalization

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "clinic-live-window-canonicalization-2026-08-07",
  "problems": [
    {
      "problemId": "clinic-live-route-window-rejected-before-provider",
      "summary": "Live Clinic scenario routes can pass open-ended or current/live window text to the deterministic helper, which rejects the request before metrics, TopSQL, or Slow Query reaches Clinic.",
      "status": "optimized_verified",
      "issueKeys": ["TCID-13010", "TCID-13012"],
      "sourceRefs": [
        "https://tidb.atlassian.net/browse/TCID-13010#problem:clinic-live-window-open-ended",
        "https://tidb.atlassian.net/browse/TCID-13012#problem:clinic-current-live-window"
      ],
      "signalTextIncludesAny": [
        "clinic_time_window_invalid",
        "2026-08-06 17:45 UTC+08 onward",
        "current/live"
      ],
      "observedThrough": "2026-08-07",
      "effectiveAt": "2026-08-07T08:35:44.000Z",
      "verifiedAt": "2026-08-07T09:23:59.453Z",
      "attemptedAction": "Canonicalize Clinic live provider windows at the route boundary: bind current/live to the fixed one-hour interval ending at the workspace snapshot, bind an explicit open-ended timestamp to that fixed upper bound, and materialize an incident_window_in_future bounded result without a provider call when the explicit start is later than the frozen snapshot.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/TCID-13012"
    }
  ]
}
-->

- Optimization ID: `clinic-live-window-canonicalization-2026-08-07`
- Owner: auto-oncall-services
- Source references: `TCID-13010` and `TCID-13012`
- Implementation status: deployed to staging in image
  `591c28797673d3bde163e3f28e5d27844bda4bd0`
- Effective status: `optimized_verified`

## Bounded problem

The live scenario router could emit a human-readable open-ended timestamp or
`current/live`. The deterministic Clinic helper accepts only finite absolute
bounds, so it rejected those routes locally before any provider request.

## Implementation

- Keep historical replay windows owned by the existing replay cutoff.
- For live initial analysis, use the workspace snapshot as a fixed upper bound.
- For continuation, use the exact triggering-comment timestamp as the upper
  bound.
- Convert `current/live` to the preceding one-hour interval and convert a
  timezone-qualified open-ended start to that start plus the fixed upper bound.
- If an explicit incident start is later than the frozen snapshot, preserve it
  as `incident_window_in_future`, make no Clinic request, and materialize a
  bounded partial result for the final diagnosis.
- Keep the Clinic helper strict: it accepts the runner-owned `live:absolute`
  contract but does not infer or widen a window itself.

## Verification status

Contract tests cover the two source window shapes: `current/live` reaches the
Clinic helper with finite start/end parameters, while the future TCID-13010
window produces a bounded partial result with zero provider calls.

Staging deployment completed on 2026-08-07 at `08:35:44Z`. The rendered Pod
used image `591c28797673d3bde163e3f28e5d27844bda4bd0`, was Ready with zero
restarts, and the automatic job table had no queued, running, or retryable
jobs before or after validation.

Post-deployment write replays passed the bounded window criterion:

- `TCID-13010` run `54a9a5d2-fb98-4533-9961-06c1a2e4403b` used the backend
  historical absolute interval `1786008903..1786012503`. Three Clinic batches
  completed without a window or provider failure. DB run `120060`, Feishu
  Base, and existing private Jira comment `23454336` were updated.
- `TCID-13012` run `6d3b11e1-68d5-455f-b888-38bf494ad463` used the backend
  historical absolute interval `1786013506..1786017106`. Four Clinic batches
  completed or returned bounded empty results without a window or provider
  failure. DB run `120061`, Feishu Base, and existing private Jira comment
  `23456233` were updated.
- Jira readback found both exact comment IDs with `public=false`; no duplicate
  customer-visible comment was created.

Historical replay deliberately uses the cutoff-owned absolute envelope rather
than re-emitting the original live route text. The deployed contract tests are
therefore the direct proof for `current/live` and future/open-ended live route
canonicalization, while the two source-case replays prove that the corrected
runtime completes the Clinic path and refreshes the case artifacts.

## Unresolved gaps

A malformed explicit timestamp intentionally remains a route failure rather
than silently querying an unrelated current window. The replay results remain
`human_required` for their case-specific evidence and production-action
boundaries; this is separate from the fixed Clinic window-routing failure.

## Next validation action

Monitor later live Clinic cases for a regression of `clinic_time_window_invalid`
or any attempt to pass `current/live` directly to the helper. Treat such newer
evidence as a regression of this verified problem.
