# Wetech Refinement Metric Label Scope

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "wetech-refinement-label-scope-2026-08-12",
  "problems": [
    {
      "problemId": "wetech-refinement-guesses-cross-metric-label-selector",
      "summary": "APID-29259 refinement copied an entity value from one metric result into selectors for different metric families, so six otherwise useful mechanism queries failed together instead of returning bounded native-label evidence.",
      "status": "optimized_verified",
      "issueKeys": ["APID-29259"],
      "sourceRefs": [],
      "signalTextIncludesAny": ["grafana_query_range_failed", "cross-metric label", "refinement selector", "APID-29259"],
      "observedThrough": "2026-08-12",
      "effectiveAt": "2026-08-12T08:58:00Z",
      "verifiedAt": "2026-08-12T09:19:28Z",
      "attemptedAction": "Make metric labels query-scoped, allow one verbatim equality selector only within the same metric family, prohibit dynamic PromQL regex construction from prior label values, and require bounded native-label aggregation or top-k for multiple entities and cross-metric refinement; retain TopSQL instanceFromQueryId as the sole deterministic cross-operation dependency.",
      "evidenceUrl": "https://github.com/tidbcloud/aisupport/tree/main/auto-oncall-services/docs/opts/2026-08-12-wetech-refinement-label-scope.md"
    }
  ]
}
-->

- Owner: auto-oncall-services
- Source: APID-29259 replay `669ba399-75a4-4818-bb54-739e5df24efc`
- Status: optimized_verified

The first evidence round returned compact metric series with exact label maps.
Those labels described only their producing PromQL. The refinement treated an
entity-looking value as a label vocabulary shared by other metric families and
issued six exact-filter queries; the provider returned
`grafana_query_range_failed` for all six.

The Evidence Agent contract now keeps metric labels query-scoped. Same-family
queries may reuse one exact key/value present in the prior handoff as a
verbatim equality matcher. It may not dynamically build PromQL regexes from
prior values: a deployed write replay proved that escaping IP punctuation this
way produced three HTTP 400 `unknown escape sequence` parse failures. Multiple
entities and different metric families instead use bounded native grouping or
top-k and correlate the returned series. TopSQL's deterministic
`instanceFromQueryId` remains the only helper-owned cross-operation selector
dependency.

Deployed write replay `75da196b-85b7-4062-a0d2-df6cf594b34f` ran 24 round-2
queries with zero failures. Two completed queries returned valid empty results;
no dynamic-label PromQL parse error remained. The result narrowed the diagnosis
to mixed SQL and transaction load with lock/latch contribution to tail COMMIT
latency while preserving that neither one COMMIT family nor one Digest was a
proven root cause. It evaluated `ai_better`.

The stable Jira internal comment `23323234` was updated in place and read back
with `public=false` and the expected revised body. The overall acquisition
remained degraded only because of a separate first-round metric failure and a
partial handoff marker; neither came from the changed refinement batch.
