# Shared Evidence Agent query planning

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "shared-evidence-query-planning-2026-09-07",
  "problems": [
    {
      "problemId": "provider-scoped-source-cardinality-guidance",
      "summary": "Wetech Evidence Agent used unfiltered TiDB-to-TiKV histogram topk because shared source-cardinality guidance was scoped to Clinic.",
      "status": "candidate",
      "applicability": "Evidence Agent observability metric planning through Clinic, Wetech or Manus; expensive source series and query-scoped label provenance.",
      "issueKeys": [
        "APID-29470"
      ],
      "sourceRefs": [
        "https://tidb.atlassian.net/browse/APID-29470#problem:provider-scoped-source-cardinality-guidance"
      ],
      "signalTextIncludesAny": [
        "tikv-client-p99-by-store",
        "provider-scoped-source-cardinality-guidance"
      ],
      "observedThrough": "2026-09-07",
      "effectiveAt": null,
      "verifiedAt": null,
      "attemptedAction": "Extract evidence-query-planning Skill and load it with the selected Provider Skill on Agent9 and local-plan paths; publish and pin only to Evidence Agent.",
      "evidenceUrl": "https://tidb.atlassian.net/browse/APID-29470"
    }
  ]
}
-->

Owner: Evidence Agent query planning. Source: user-requested APID-29470 follow-up.

Scope is defined in [the Skill](../../skills/evidence-query-planning/SKILL.md)
and the core contract. This extracts provider-independent metric scan cost,
time scope, selector provenance, and bounded changed-query guidance.
Provider authentication, navigation, execution schemas, diagnosis, and new
executor hard guards are outside this change.

Source evidence: deployed read `eff3e954-b116-4f5a-80ae-b91cde2e087a`,
Wetech v41, `tikv-client-p99-by-store`: unfiltered histogram query timed out
after 30 seconds while other metric requests completed. Timeout alone does
not establish backend overload. Dashboard navigation failures are separate.

Implementation: complete locally; not deployed. Effective status remains candidate.

## Local verification (2026-09-07)

- Skill frontmatter validation passed.
- Build and all 1,113 repository tests passed.
- Production-prompt tests cover Clinic, Wetech, and Manus in both local-plan
  and Agent9 modes, including retention through refinement. Scenario
  Diagnostic prompts do not receive shared query-planning guidance.
- Release API contract tests cover first creation, subsequent publication,
  exact Evidence-only installation, stale diagnosis-installation removal,
  and ambiguous catalog identity rejection before any write.
- Offline real-model validation: `gpt-5.6-sol`, medium reasoning, three fresh
  executions (one per Provider), three independent fixtures each: 9/9 passed.
  Without an endpoint, each omitted the expensive histogram and rejected a
  cross-family CPU-instance guess; with a proven same-family instance, each
  generated the exact filter; cluster-level low-cardinality QPS remained
  unfiltered. The 10-minute incident window was preserved in every result.
  Durations: Wetech 32.050s, Clinic 16.156s, Manus 24.760s.
  These tests supplied both Skills inline to an offline model and tested
  planning decisions only; production prompt wiring is covered separately by
  contract tests. No Provider, Agent9 live installation, or ticket write ran.
- Local artifacts: `/tmp/shared-evidence-query-model/` and
  `/tmp/shared-evidence-query-model.log`; harness:
  `/tmp/simulate-shared-query-skill.mjs`.

These checks do not establish reduced live query latency or resolve the
Dashboard navigation failure. A deployed same-case read is still required.
Next validation: local production-prompt and installation contract tests,
bounded offline real-model query planning, then one post-deployment read
when deployment is requested. No Provider queries or ticket writes are needed
for local validation.
