# Managed Clinic 5xx Retry

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "managed-clinic-5xx-retry-2026-08-28",
  "problems": [
    {
      "problemId": "managed-clinic-5xx-is-not-retried",
      "summary": "Managed Clinic returned a transient 5xx as the final result without retrying the same read-only request, so one upstream BadGateway could leave load-bearing TiCDC evidence unavailable.",
      "status": "optimized_verified",
      "applicability": "Read-only Managed Clinic requests that receive an HTTP 5xx while the current Provider Executor query still has execution budget.",
      "issueKeys": ["TCID-13093"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/TCID-13093#problem:managed-clinic-5xx-is-not-retried"],
      "signalTextIncludesAny": [
        "clinic_http_502",
        "logs upstream request failed",
        "BadGateway"
      ],
      "observedThrough": "2026-08-28",
      "effectiveAt": "2026-08-28T07:35:58.879Z",
      "verifiedAt": "2026-08-28T07:59:01.294Z",
      "attemptedAction": "Retry the identical Managed Clinic request up to two times after HTTP 5xx responses with bounded 250 ms and 750 ms delays, preserve immediate 4xx rejection, and retain attempt status and request identifiers when retries are exhausted.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/TCID-13093?focusedCommentId=23731608"
    }
  ]
}
-->

- Owner: Managed Clinic Provider Executor
- Source: TCID-13093 replay `4ea32d9c-296a-43f7-9137-b820d15cfab9`
- Implementation status: merged in AOS PR #1142 and published as Managed Clinic v20
- Effective status: `optimized_verified`

## Bounded problem

The Managed Clinic request helper returned the first HTTP 5xx immediately. In
TCID-13093 this made one Loki architecture-marker request fail with HTTP 502,
although another identical read-only attempt could have recovered while the
query budget remained available. Changed Evidence Agent queries are not a
transport retry of the failed request.

## Intended change

The deterministic Managed Clinic request helper retries only HTTP 5xx
responses. It sends the same method, URL, parameters, headers, and body at most
two additional times with short bounded delays. HTTP 4xx responses remain
actionable request rejections and are returned without an unchanged retry.
Exhausted 5xx results retain attempt count, status history, and safe upstream
request identifiers.

## Verification

Local package tests prove that two HTTP 502 responses followed by success use
the third response, while an HTTP 400 is returned after one attempt. Managed
Clinic v20 package digest
`fc188d5d361ad04c1de212a32da8d39bc81cb4d9ae913a16db29c02479e0262e`
was loaded by Agent9 and installed on the Auto Oncall Evidence Agent at
installation revision 11 with its existing Auth binding preserved.

TCID-13093 read replay `fa11a1de-6a75-4b07-98ba-1634673f24e5` completed with
Clinic acquisition `complete`, capability verified, and three successful
Managed Tool Operations whose audited package digest was the v20 digest. The
Provider did not return a 5xx during this replay, so live same-request recovery
was not exercised; that branch remains covered by the deterministic 502 test.

Write replay `3cedd529-be50-44e0-a92a-2492b65a7821` persisted run DB id
`150148`, evaluation, and Jira internal comment `23731608`. A Jira API readback
confirmed `public=false`; its plain-text body matched the generated paired body
after Jira's expected removal of Markdown code backticks.

## Next validation action

Monitor provider HTTP attempt events for a naturally occurring 5xx recovery.
Treat a later exhausted three-attempt sequence as unavailable evidence and a
new runtime signal; do not reinterpret it as an empty result.
