# Clinic Activity Limit Contract

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "clinic-activity-limit-contract-2026-08-13",
  "problems": [
    {
      "problemId": "clinic-activity-limit-exceeds-activityhub-contract",
      "summary": "Auto Oncall allowed Clinic activity limit 200 although ActivityHub accepts at most 100, so Clinic surfaced the downstream HTTP 400 as a retryable HTTP 502 and the unchanged request failed three times.",
      "status": "optimized_verified",
      "issueKeys": ["TCID-12986"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/TCID-12986#problem:clinic-activity-limit-contract"],
      "signalTextIncludesAny": ["invalid activity response", "activityhub", "activities limit=200", "clinic_http_502"],
      "observedThrough": "2026-08-13",
      "effectiveAt": "2026-08-13T13:10:15Z",
      "verifiedAt": "2026-08-13T13:18:39Z",
      "attemptedAction": "Align the Evidence Agent contract and deterministic Clinic Provider Executor with ActivityHub maximum limit 100 so an agent-authored limit 200 is normalized before the provider request.",
      "evidenceUrl": "https://github.com/tidbcloud/aisupport/tree/main/auto-oncall-services/docs/opts/2026-08-13-clinic-activity-limit-contract.md"
    }
  ]
}
-->

- Owner: auto-oncall-services Clinic Provider Executor
- Source: TCID-12986 replay `3c5a266b-e0f4-48a5-992f-b46b6e20867a`
- Implementation status: deployed to staging in image `6dbef26ce03dbf813f6801d1b7fc74128dda1975`
- Effectiveness status: optimized_verified for the ActivityHub limit contract

## Bounded problem

The replay requested `/activities?limit=200`. ActivityHub rejected that limit
with HTTP 400, Clinic surfaced an invalid activity response as HTTP 502, and the
Provider Executor retried the unchanged request three times.

## Change

The Clinic activity plan contract now states a maximum of 100. The deterministic
Provider Executor also clamps any larger plan value to 100 before calling Clinic,
so historical or malformed plans cannot reproduce the downstream contract
mismatch.

## Verification

On 2026-08-13, 175/175 focused tests and 804/804 full-suite tests passed. The
focused regression submits a plan with `limit=200`, verifies that the one actual
request uses `limit=100`, and receives an empty complete result without retry.

PR [#890](https://github.com/tidbcloud/aisupport/pull/890) was deployed through
[staging run 31703004214](https://github.com/tidbcloud/aisupport/actions/runs/31703004214)
and [app-delivery #77254](https://github.com/tidbcloud/app-delivery/pull/77254).
The live Pod started at `2026-08-13T13:10:15Z` with the merge-SHA image, Ready,
and zero restarts.

TCID-12986 historical replay `5fd16fb1-d604-4182-a53b-419fbe075daa` completed at
`2026-08-13T13:18:39Z`. Its `cluster-activities` compact report was complete,
returned four activities, was not truncated, and had no recovery. The replay
contained zero HTTP 502 attempts and did not reproduce the original invalid
ActivityHub response. This verifies this bounded contract problem only.

## Unresolved gap and next action

The whole replay remained degraded by separate Statements HTTP 400 and TopSQL
HTTP 500 failures. Do not use this record to suppress those signals or to call
TCID-12986 fully optimized. After those provider failures are resolved, replay
this case again; only a non-degraded result should unlock the two additional
Clinic case replays.
