# Provider Plan Contract Recovery

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "provider-plan-contract-recovery-2026-08-10",
  "problems": [
    {
      "problemId": "evidence-agent-plan-contract-lost-before-provider-execution",
      "summary": "The role-unification migration starts the provider Evidence Agent with a prompt that omits the runner helper's field-level plan contract, so a structurally invalid plan can terminate the scenario before any provider query and surface only a generic failure.",
      "status": "optimized_verified",
      "issueKeys": ["ST-2865"],
      "sourceRefs": [],
      "signalTextIncludesAny": [
        "clinic_evidence_plan_query_invalid",
        "diagnostic_scenario_failed",
        "provider plan does not match runner-owned context"
      ],
      "observedThrough": "2026-08-10",
      "effectiveAt": "2026-08-10T15:42:45Z",
      "verifiedAt": "2026-08-10T16:28:13Z",
      "attemptedAction": "Put each provider's exact active plan fields in the Evidence Agent prompt, bind Manus to the backend-classified vida or monica target, preserve helper error codes, and allow one same-thread structural correction inside the same evidence round only when no provider result exists.",
      "evidenceUrl": "https://github.com/tidbcloud/aisupport/tree/main/auto-oncall-services/docs/opts/2026-08-10-provider-plan-contract-recovery.md"
    }
  ]
}
-->

- Optimization ID: `provider-plan-contract-recovery-2026-08-10`
- Owner: auto-oncall-services diagnostic runner
- Source reference: staging Clinic replay `ST-2865`, run
  `571f090c-5030-4229-b443-7a3004696208`
- Implementation status: deployed to staging
- Effective status: `optimized_verified`

## Bounded problem

The active Evidence Agent prompt named Clinic operations but did not include
the helper-owned `kind`, `query`, and per-operation field contract that remained
in an inactive older prompt. The Agent therefore produced provider-shaped
`operation` fields, and the runner rejected the plan before Provider Executor
output existed. The process wrapper then collapsed the exact helper stderr into
`diagnostic_scenario_failed` and offered no same-round structural correction.

Manus had the same missing active contract boundary: its helper requires an
exact top-level `target`, but the runner context did not own or validate that
field.

## Implemented change

- Give the active Evidence Agent one field-level plan contract for Clinic,
  Wetech, or Manus and remove the inactive duplicate contract.
- Derive one Manus target only from `manus_target:vida|monica` classification
  evidence, persist it in the runner context, and require the plan to match it.
- Extract stable helper error codes from bounded stdout/stderr JSON or a plain
  error-code line.
- If and only if the helper rejected plan structure before producing a batch,
  let the same Evidence Agent overwrite the plan once in the same evidence
  round. Provider failures and materialized partial batches are not retried by
  this path.

## Verification

- Active prompt tests assert Clinic `kind/query` fields, Wetech
  `operation/params`, and exact Manus `target` plus operation fields.
- Real Clinic, Wetech, and Manus parsers reject their malformed model-shaped
  fixtures with exact stable codes.
- A runner integration test proves one invalid Clinic plan is corrected by the
  same Evidence Agent thread, invokes Provider Executor twice, produces one
  scenario diagnosis, and does not consume a refinement round.
- Staging image `bee55d3737d3f9112f028520aeed658cab2867f8` became Ready at
  `2026-08-10T15:42:45Z`.
- Post-change `ST-2865` run `e24f3e90-5d35-4a79-ae67-c85bd13f0930`
  produced a valid 12-query Clinic plan and batch without the original
  `clinic_evidence_plan_query_invalid` signal.
- Post-change `APID-29174` run `597bab0c-1086-44d5-a4d8-b819c20ab8f9`
  bound both Manus plans to runner-owned target `vida`; the plans passed and
  Provider Executor ran. Manus is outside the currently supported OP scope and
  its customer request allowlist is closed, so its provider outcome is excluded
  from this Clinic-scoped verification.
- Post-capacity-fix `ST-2865` read replay
  `cad4ec49-fc18-40a6-a523-a5bc5eddaf5e` and write run
  `119f68c0-27b6-499a-83a6-892aff718534` both completed Clinic acquisition
  without the original plan-contract failure.
- The write run updated existing Jira internal comment `23432370`; readback
  confirmed `public=false` and the expected refreshed analysis.

## Unresolved gaps

- No unresolved gap remains for the supported Clinic plan-contract problem.
- Manus remains intentionally out of supported OP scope and does not block this
  record.

## Next validation action

Monitor later Clinic runs for a regression of the exact plan-parser signals.
