# Diagnostic Agent Role Unification

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "diagnostic-agent-role-unification-2026-08-10",
  "problems": [
    {
      "problemId": "provider-specific-agent-ownership-divergence",
      "summary": "Clinic and Manus provider paths could combine evidence acquisition and scenario diagnosis in one agent flow while Wetech used a separate plan-only acquisition path, making role ownership and refinement behavior provider-dependent.",
      "status": "optimized_unverified",
      "issueKeys": [
        "APID-29232",
        "ST-2865"
      ],
      "sourceRefs": [],
      "signalTextIncludesAny": [
        "evidence acquisition agent",
        "scenario parent",
        "provider-specific diagnosis flow",
        "evidence agent performed diagnosis"
      ],
      "observedThrough": "2026-08-10",
      "effectiveAt": "2026-08-10T13:31:37Z",
      "verifiedAt": null,
      "attemptedAction": "Use one Scenario Router to Evidence Agent to runner-owned Provider Executor to Scenario Diagnostic Agent to Final Synthesis Agent flow for Clinic, Wetech, and Manus, leaving only provider query-interface differences.",
      "evidenceUrl": "https://github.com/tidbcloud/aisupport/tree/main/auto-oncall-services/docs/opts/2026-08-10-diagnostic-agent-role-unification.md"
    }
  ]
}
-->

- Optimization ID: `diagnostic-agent-role-unification-2026-08-10`
- Owner: auto-oncall-services diagnostic runner
- Source reference: operator architecture review on 2026-08-10
- Implementation status: merged and deployed to staging
- Effective status: `optimized_unverified`

## Bounded problem

Runtime terminology and ownership had diverged. Wetech used a plan-only agent
followed by runner execution and a separate diagnostic turn, while Clinic and
Manus still had a scenario agent orchestrate provider evidence inside its own
flow. That made provider choice alter agent responsibilities and encouraged
incorrect reasoning about which stage owned diagnosis.

This record owns only diagnostic role and provider-orchestration consistency.
It does not change provider authorization, target selection, supported query
operations, causal admission rules, Jira publication, or Focus lifecycle.

## Candidate change

- Standardize the runtime roles as Scenario Router, Evidence Agent,
  runner-owned Provider Executor, Scenario Diagnostic Agent, and Final
  Synthesis Agent.
- Apply the same sequence to Clinic, Wetech, and Manus.
- Keep provider differences limited to exact target/auth contract, query plan
  and result schema, supported operations, helper, and serial or concurrent
  execution.
- Scope OP serialization to runner-owned readiness and Provider Executor calls;
  do not serialize Evidence Agent planning or Scenario Diagnostic Agent
  reasoning merely because the provider transport is stateful.
- Reuse one Evidence Agent thread for refinements within a scenario and start a
  fresh offline Scenario Diagnostic Agent after each materialized round.
- Retain old `child-evidence-handoff` wire identifiers only for compatibility,
  not as agent-role names.

## Verification evidence

Focused TypeScript tests cover all three providers, plan-only Evidence Agent
behavior, runner-owned execution, separate Scenario Diagnostic Agent turns,
same-thread evidence refinement, fresh diagnostic turns, and final tool-free
synthesis. The complete suite passed with 709 tests on the release branch.

- Source PR: `tidbcloud/aisupport#732`, merged as `9763e77e`.
- Staging image PR: `tidbcloud/app-delivery#76716`. The exact release image was
  deployed and was later superseded by descendant image `2ff0796c`, which
  contains `9763e77e`; the live Pod became Ready at `2026-08-10T13:31:37Z`.
- Wetech replay `APID-29232`, run
  `2e6f9473-1b48-460e-b513-2250fa075597`: the trace used one Router, one
  Evidence Agent thread across three rounds, a runner-owned Wetech auth and
  batch executor, a fresh Scenario Diagnostic Agent per round, and tool-free
  final synthesis. Evidence acquisition completed with provider capability
  verified. The scenario converged by ruling out material Region/Leader
  distribution imbalance as the cause of the CPU spread.
- Clinic replay `ST-2865`, run
  `571f090c-5030-4229-b443-7a3004696208`: Router and plan-only Evidence Agent
  ownership matched the new flow, but runner validation rejected the generated
  12-query plan with `clinic_evidence_plan_query_invalid` before Provider
  Executor output was materialized. The final result correctly remained
  `human_required`, but Clinic runtime equivalence was not verified.
- Both replays used `mode=read`. Neither run ID exists in
  `auto_oncall_runs`; Jira, database, evaluation, and Feishu publication were
  not requested.

## Prior-change audit

- PR #721 (`a9bab52c`) correctly separated Wetech planning from scenario
  diagnosis and reused its evidence thread, but used inconsistent
  acquisition/parent terminology and did not apply the same runner-owned
  orchestration to Clinic and Manus. This is the concrete earlier gap corrected
  here.
- PR #723 (`5ac06093`) scoped browser temporary files to the current run. That
  filesystem isolation remains valid independently of agent-role naming.
- PR #724 (`4bdff00b`) moved Wetech auth/readiness to deterministic runner code,
  and PR #725 (`3995421b`) moved Wetech batch execution outside the agent
  sandbox. Both changes match the now-explicit Provider Executor boundary.
- PR #729 (`d0427d09`) fixed canonical Wetech target alias validation. It is a
  target handoff fix and does not depend on which agent owns diagnosis.

The audit found no evidence that the incorrect verbal role description made
the auth, temporary-file, provider-execution, or alias fixes invalid. The
material design defect was provider-specific orchestration and ambiguous role
names, not those operational boundaries.

## Unresolved gaps

- Wetech runtime ownership is verified by one staging replay, but Clinic is
  blocked by a generated field-level plan-contract mismatch (`kind`/`query` and
  operation parameters); its query IDs were valid. Manus has not
  been replayed. Equivalent behavior across all three providers is therefore
  not verified.
- The Wetech case needed three evidence rounds. Rounds reused the same Evidence
  Agent thread as designed, but cumulative Evidence Agent input grew from
  80,499 to 136,129 to 216,754 tokens. This is observed cost evidence, not part
  of the role-unification acceptance result.
- No Jira internal comment has been refreshed by this change.

## Next validation action

Resolve the Clinic field-level plan-contract mismatch as the separate bounded
provider-plan-contract recovery problem, then replay one Clinic and one Manus
case. Keep this record
`optimized_unverified` until those provider paths pass and any applicable Jira
internal-comment refresh is separately authorized and verified.
