# Continuation Analysis Dispatch Unification

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "continuation-analysis-dispatch-2026-08-13",
  "problems": [
    {
      "problemId": "continuation-bypasses-diagnostic-router-and-reuses-wrong-thread-role",
      "summary": "APID-29340 continuation bypassed the Scenario Router pipeline, reused the persisted Router thread as a legacy Primary Analysis thread, and supplied an unqualified Wetech targetReference that was rejected before any provider query.",
      "status": "optimized_verified",
      "applicability": "Live explicit continuations whose current classified objective either requires a read-only diagnostic provider or changes between Primary Analysis and Scenario Router ownership.",
      "issueKeys": ["APID-29340"],
      "sourceRefs": [
        "https://tidb.atlassian.net/browse/APID-29340#problem:continuation-diagnostic-dispatch"
      ],
      "signalTextIncludesAny": [
        "op_batch_target_invalid",
        "explicit continuation on one legacy resumed turn",
        "targetReference is SaaS01"
      ],
      "observedThrough": "2026-08-13",
      "effectiveAt": "2026-08-13T11:52:34Z",
      "verifiedAt": "2026-08-13T12:56:08Z",
      "attemptedAction": "Dispatch initial and continuation turns by the same current classification and direct-artifact decision, resume only a persisted thread with the matching Primary Analysis or Scenario Router role, and keep continuation-specific trigger, cutoff, gate-bypass, publication, idempotency, and reporting behavior outside that shared analysis core.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/APID-29340?focusedCommentId=23553646"
    }
  ]
}
-->

- Optimization ID: `continuation-analysis-dispatch-2026-08-13`
- Owner: live analysis dispatcher and conversation thread persistence
- Source reference: `APID-29340`
- Implementation status: deployed and verified in staging
- Effective status: `optimized_verified`

## Bounded problem

Explicit continuation previously bypassed the diagnostic Scenario Router path
solely because its input mode was `continuation`. APID-29340 therefore resumed a
persisted Scenario Router thread as the legacy Primary Analysis Agent and called
the Wetech helper with `SaaS01` instead of the runner-owned canonical
`wetech:asia-prod:SaaS01` target. Both batches stopped before a provider query.

The same input-mode split can also resume a diagnostic Router thread as Primary
Analysis when a later continuation is a direct answer. Agent role and provider
routing must follow the current classified objective, not the trigger kind.

## Implemented change

- Use one analysis dispatcher for live initial and continuation runs.
- Keep direct answers in Primary Analysis and provider-backed diagnostics in the
  Scenario Router pipeline.
- Persist the owning thread role and resume only an exact role match.
- Re-evaluate the direct-artifact gate at the continuation cutoff instead of
  unconditionally disabling it.
- Preserve continuation-only trigger validation, Jira cutoff, autonomous-gate
  bypass, internal-comment idempotency, publication denial, and report exclusion.

## Verification evidence

- `npm run typecheck` and the focused runner suite passed. The focused suite
  includes APID-29340 Wetech continuation dispatch, both directions of
  thread-role mismatch, direct-answer same-role resume, bounded Wetech
  readiness failure, and long provider transport-error normalization.
- `npm test` passed all 801 tests on 2026-08-13.
- Read-only APID-29340 continuation run
  `31cfa429-5c76-4849-b89f-418f8f8bb92a` selected the Scenario Router, fixed
  `SaaS01` to region `asia-prod`, executed three Wetech scenarios, and produced
  16 provider query events. Eleven metric queries succeeded or returned a
  valid empty result, and no `op_batch_target_invalid` occurred. Five Dashboard
  operations failed only because the local test harness omitted the separately
  configured Dashboard credentials, so this is degraded evidence rather than
  full provider verification.
- Read-only ST-2891 direct-answer replay
  `9460da96-3117-4a3f-a59d-399440409aa1` completed without a provider call.
- Read-only ST-2863 Clinic evidence-assisted replay
  `b17b19c5-6a32-46cc-9956-510b3e1eb2d5` reached Clinic and completed the
  response with degraded evidence from existing Clinic query-contract errors.
- The pre-deployment real-ticket checks were read-only. They did not write a
  Jira comment, database evaluation, or Feishu notification.
- Source PR [#885](https://github.com/tidbcloud/aisupport/pull/885) and
  app-delivery PR [#77248](https://github.com/tidbcloud/app-delivery/pull/77248)
  merged. Staging rolled out image `db070e77c93d81f4eb149d4f96c4c7ef92631d9f`
  at 2026-08-13T11:52:34Z; the new Pod was Ready with zero restarts, both
  health endpoints returned HTTP 200, and the role columns existed in the live
  TLS database.
- Deployed read-only APID-29340 continuation replay
  `d3f8293d-3d13-49d7-8bce-47a4bd09aadd` started a fresh Scenario Router for
  the historical untyped thread, resolved `wetech:asia-prod:SaaS01`, completed
  30 of 30 Wetech provider query events without `op_batch_target_invalid`, and
  generated a complete response. Its evidence remained degraded only for
  `child_evidence_partial` and `adaptive_batch_artifact_missing`.
- Deployed read-only ST-2891 direct-answer replay
  `2f2c05d5-7cf6-4e9d-bc59-daf8749562fd` completed with provider `none` and
  zero provider queries. Deployed read-only ST-2863 Clinic replay
  `961deee7-5e7c-42f1-b4fb-7fd42af096a1` completed Final Response after 22
  provider query events, with 18 successes and four existing Clinic/query
  transport failures.
- The three deployed replay run IDs were absent from `auto_oncall_runs`, the
  APID-29340 conversation and Jira latest internal comment were unchanged, and
  no queued, running, or retryable jobs remained.
- Authorized one-time write recovery used the verified deployed replay draft
  from `d3f8293d-3d13-49d7-8bce-47a4bd09aadd` and the continuation mapping
  `auto-live:v1:APID-29340:continuation:23553585`. It updated Jira internal
  comment `23553646` in place on 2026-08-13, then read back that exact ID with
  `public=false` and exact expected ADF. Comment count remained 10 before and
  after, the owner job stayed continuation job `150105`, no replay run or new
  job was persisted, and no queued, running, or retryable job was introduced.

## Unresolved gaps

The Wetech replay retained `child_evidence_partial` and
`adaptive_batch_artifact_missing` even though every materialized provider query
succeeded. Those completeness signals are outside this dispatch and target-
qualification problem and remain eligible as a separate bounded problem.

## Next validation action

Track the remaining partial/refinement completeness codes as a separate bounded
problem without reopening this verified continuation-dispatch problem.
