# Managed Provider same-Turn correction

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "managed-provider-same-turn-correction-2026-09-03",
  "problems": [
    {
      "problemId": "wetech-actionable-argument-error-stops-acquisition",
      "summary": "The Wetech Evidence Agent stopped after one actionable Managed Tool argument rejection because only Clinic received the same-Turn correction rule, and Wetech correction attempts were not grouped by stable queryId during materialization.",
      "status": "candidate",
      "applicability": "Agent9-backed Wetech OP evidence acquisition where a primary Managed Tool call returns a caller-correctable validation error.",
      "issueKeys": ["APID-29338"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/APID-29338#problem:wetech-actionable-argument-error-stops-acquisition"],
      "signalTextIncludesAny": [
        "provider_validation_failed",
        "invalid unit",
        "evidence_acquisition_failed"
      ],
      "observedThrough": "2026-09-03",
      "effectiveAt": null,
      "verifiedAt": null,
      "attemptedAction": "Give Clinic and Wetech the same current-Turn correction contract, require a stable Wetech queryId, emit a safe request digest, merge attempts by queryId, and reserve adaptive refinement for a distinct new diagnostic question.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/APID-29338"
    },
    {
      "problemId": "wetech-grafana-4xx-detail-stops-query-repair",
      "summary": "The Wetech Managed Tool collapsed Grafana and Prometheus HTTP 4xx responses to a generic query failure, so the Evidence Agent could not see the safe rejection detail or correct the same PromQL objective in its current Turn.",
      "status": "candidate",
      "applicability": "Agent9-backed Wetech metric acquisition where Grafana or Prometheus rejects an otherwise authorized query with HTTP 4xx.",
      "issueKeys": ["APID-29285"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/APID-29285#problem:wetech-grafana-4xx-detail-stops-query-repair"],
      "signalTextIncludesAny": [
        "grafana_query_failed",
        "HTTP 422",
        "provider_validation_failed"
      ],
      "observedThrough": "2026-09-03",
      "effectiveAt": null,
      "verifiedAt": null,
      "attemptedAction": "Preserve the credential-redacted Grafana or Prometheus rejection as detail_error together with its class, HTTP status, error type, response digest, and same-Turn correction instruction; do not replace provider request semantics with a helper-authored summary.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/APID-29285"
    },
    {
      "problemId": "managed-tool-model-visible-result-divergence",
      "summary": "Clinic, Manus, and Wetech stored compact structured results in operation details but exposed inconsistent prose or partial JSON through the model-visible text channel, so the Evidence Agent could miss successful evidence fields or complete rejection details during its current Turn.",
      "status": "candidate",
      "applicability": "Agent9-backed Clinic, Manus, or Wetech evidence acquisition where the Evidence Agent must inspect a Managed Tool result in its current Turn.",
      "issueKeys": ["APID-29285"],
      "sourceRefs": ["https://tidb.atlassian.net/browse/APID-29285#problem:managed-tool-model-visible-result-divergence"],
      "signalTextIncludesAny": [
        "detailErrorPresent",
        "correctedPointCount",
        "read-only evidence is unavailable"
      ],
      "observedThrough": "2026-09-03",
      "effectiveAt": null,
      "verifiedAt": null,
      "attemptedAction": "Use one result envelope across Clinic, Manus, and Wetech: text is the exact JSON serialization of details for success, failure, and batch results, and safe failure detail is carried as detail_error without a second helper-authored summary.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/APID-29285"
    }
  ]
}
-->

## Problem

The Agent9 Evidence Agent received each Managed Tool's JSON Schema, but the
explicit same-Turn correction instructions were emitted only for Clinic.
Wetech therefore could stop after an actionable local argument rejection, and
its materializer treated a changed correction with the same objective as a
second independent query instead of replacing the failed outcome.

This also blurred two different operations: correcting a caller-owned Provider
request in the current acquisition round, and requesting a later adaptive
Scenario refinement for a newly discovered diagnostic question.

## Owning stage

- Evidence Agent owns the changed caller-side request in its current Turn.
- Managed Wetech owns runtime validation and returns safe correction metadata.
- Provider materialization owns grouping attempts by stable `queryId` and
  retaining only the final outcome in the child handoff.
- Scenario Diagnostic Agent may request a later refinement only for one newly
  discovered load-bearing diagnostic question.

## Change

- Give Clinic and Wetech the same provider-neutral same-Turn correction rule,
  while preserving their batch and one-operation transport shapes.
- Require Wetech `queryId` in the Agent-visible Tool Schema and document `unit`
  as a short plain string label.
- Add a stable request digest to Wetech success and actionable validation
  results so unchanged attempts can be identified without exposing arguments.
- Group Wetech calls with the same `queryId`, preserve bounded attempt metadata,
  and materialize only the final result for that objective.
- Exclude argument/query repair and unchanged retry from Scenario refinement;
  an adaptive round now requires a distinct new diagnostic question derived
  from materialized evidence.
- Stop the current Evidence Agent Turn after one shared authentication,
  session-bootstrap, readiness, authorization, or browser/runtime failure;
  these failures are not query correction and must not trigger repeated login
  for later Wetech objectives.
- Derive Wetech's Chrome User-Agent from the running Chromium version so its
  major version remains consistent with browser-generated client hints after
  the Agent9/E2B browser image changes.
- Preserve Grafana and Prometheus HTTP rejection metadata as a structured
  Wetech result. Return the complete credential-redacted provider text as
  `detail_error`, including label-matching and duplicate-series context, rather
  than replacing it with a helper diagnosis. Retain the HTTP status, Prometheus
  error type, response-body digest, and same-Turn correction instruction.
- Project that same structured Wetech failure object into the Managed Tool
  `text` channel. Live v36 operation readback retained `details.detail_error`,
  but the Evidence Agent Turn received only the old generic text, so `details`
  alone could not support same-Turn correction.
- Apply the same result transport to Clinic, Manus, and Wetech for success,
  failure, and batch results. `text` is the exact JSON serialization of
  `details`; failures use `detail_error`, while successes expose the complete
  compact evidence object without a helper-authored prose projection.

## Verification

Targeted package, prompt, and materialization tests cover the Tool Schema and a
Wetech `unit` rejection followed by a changed same-Turn success. The resulting
handoff must be complete with one query, no terminal error, and both attempts
retained in the compact report. A local Docker canary against the real `yk`
Grafana also verifies that an execution-time PromQL rejection is returned as
`grafana_http_422` with its provider detail in `detail_error` and actionable
correction metadata, and that a changed call with the same `queryId` returns
real metric data. The failure canary also verifies that parsing the Tool's
model-visible `text` yields the same structured object as `details`. Contract
tests apply that equality to Clinic, Manus, and Wetech success and failure
paths, and live Agent9 canaries verify the model can read both the failed query
detail and corrected successful evidence fields in the same Turn.
