Skip to content

ADR-0036: The model sees the ScaledObject of a KEDA incident

  • Status: Accepted
  • Date: 2026-11-14

Context

The lab eval of 2026-11-10 (10 runs per commit, #499) missed the outcome of both KEDA scenarios in some runs (#640). In broken-keda-trigger one run proposed AdjustKedaMaxReplicas although its own summary said the trigger's Prometheus address does not resolve, so the pull request could not fix the fault. In keda-at-ceiling three runs of one commit ended MissingData with "the current ScaledObject spec value is not available to set previousValue exactly".

Both have one cause: the context builder did not read ScaledObjects. The model saw the Incident's summary and nothing of the object it was asked to change: not its maxReplicaCount, not its conditions. The policy check refuses a raise on a ScaledObject that is not ready (the KedaReady rule, kedaready.Readiness), so the broken trigger never became a merged change, but the analyzer only learned that after the model had proposed it.

ADR-0026 added a block the model sees, built from typed policy fields and never quotable. A ScaledObject is different: its condition messages are free text from the cluster, and the model must be able to quote them as evidence. That needs its own decision.

Decision

The ScaledObject of a KEDA incident: one get before the model call gives a snapshot; code decides readiness with the policy's rule and takes the previous maxReplicaCount from it; the model sees an allow-listed status block and a metrics block (HPA owner check from the cache, then the HPA current and target metrics), and the catalog without AdjustKedaMaxReplicas plus one fixed sentence when the ScaledObject is not ready; a not-ready analysis ends ScalerNotReady unless the result proposes another action, a ready one gets its previous value from the snapshot; the executor's gate is unchanged

  1. The model sees the ScaledObject. When the Incident's subject is a keda.sh/v1alpha1 ScaledObject, the object status section shows it, with provenance keda scaledobject, marked as untrusted cluster data like the other sections. It is quotable.
  2. One read, before the model call: the context builder gets that one object by name from the API server and checks its UID, once per analysis, and the analysis keeps that snapshot to the end. The KEDA module's role already grants the get; there is no lookup by scale target, no read of the HPA, no list for this and no new RBAC. Since the amendment of 2026-11-16 the metrics block reads the HPA that status.hpaName names from the analyzer's cache, for the owner check only; none of its fields is shown. A refused or failed read leaves no snapshot: the block says "could not fetch" and the section is a failed source (an escalation signal, as for any failed read of the subject). A failed read is never "not found". An object under another UID is the subject gone.
  3. The block shows an allow-list of fields: the namespace and name, minReplicaCount and maxReplicaCount, the scale target's kind and name, the type of each trigger, the metric names KEDA reports in its status, and the conditions Ready, Active, Fallback and Paused with their status, reason and message. Never a trigger's metadata (serverAddress, the query text), its authentication reference, the annotations or the labels. Every string goes through the redactor first and then the builder's existing rule: a value over 1 KiB after redaction is left out whole, never cut. Numbers are written by code and are not quotable. KEDA v2.21 keeps no current or desired replica counts in the ScaledObject's status, so the HPA's current and desired replicas would need the HPA's own fields, which this decision does not show. The HPA's replica counts reach the model only as the Incident's symptom carries them (maxReplicas and currentReplicas in the ceiling case). Its metric values reach the model only through the kube-state-metrics series of two approved metric templates (hpa_metric_current, hpa_metric_target), selected by the name in status.hpaName: the metrics block shows that name inside the series labels, and the HPA's current and target metric values (amendment of 2026-11-15). The templates are asked only when that HPA passes the owner check of the amendment of 2026-11-16; no field of the HPA object is shown.
  4. The baseline is decided in code. For AdjustKedaMaxReplicas the analysis loop does what it does for a memory limit (#494), from the snapshot. The model still states previousValue, as a check that it reasoned about the right change. If the direction it claims (its previous value to its desired value) differs from the real one (the snapshot to the desired value), or its two values are equal, the analysis ends DirectionReversed; a desired value equal to the snapshot is NoChange; no snapshot, or a maxReplicaCount that is missing or not a whole number from 1 up, is PreviousValueUnknown. Otherwise the plan carries the snapshot's value. Decreases are allowed here: the policy bounds them. The result schema is unchanged, and the executor's baseline check against Git still decides.
  5. Readiness is decided before the model call, with kedaready.Readiness on the snapshot, the function the policy check uses, so the analyzer and the policy cannot disagree. Only the state NotReady counts. A ScaledObject KEDA has not reported on yet (Pending) is one the policy waits for, so the action stays offered, and so it does without a snapshot (decision 4 then hands a proposal off). When the ScaledObject is not ready:
  6. the catalog in the system prompt is the closed catalog without AdjustKedaMaxReplicas, and one fixed sentence after the context blocks says the ScaledObject is not ready and a change of its maxReplicaCount is not offered;
  7. the model is still called, for the diagnosis;
  8. a valid result that ends without a proposal (no proposal, or the model's missing data) or that proposes AdjustKedaMaxReplicas anyway ends with the reason ScalerNotReady, decided in code (decided 2026-11-14). The model's missing data stays in the outcome for the log and the record, and the diagnosis is kept. MissingData stays the model's own statement for an analysis where the action was offered;
  9. a result that proposes another action of the catalog is handled as before, and an invalid result or a failed model call keeps its own reason: ScalerNotReady never hides an error.

The policy gate is unchanged. 6. Accepted risk: a condition message is text an attacker may control. KEDA v2.21 writes a fixed message for TriggerError (pkg/scaling/executor/scale_scaledobjects.go), but it copies the error of a failed check of the ScaledObject into the Ready message (ScaledObjectCheckFailed, controllers/keda/scaledobject_controller.go) and a scaler's error into a KEDAScalerFailed Event (pkg/scaling/scale_handler.go), and a scaler error can carry a response from a metrics endpoint, a query or an address. The model may quote it as evidence, and it may try to steer the model. What it can win is capped by three things that do not read it: the policy bounds, the readiness gate (in the analyzer and again in the executor) and the review of the pull request. 7. No new prompt rule beyond the fixed sentence of decision 5. The recorded eval needs none; the real-model eval after this change decides whether one is needed.

The analysis, once the context is built:

sequenceDiagram
    participant B as Context builder
    participant API as API server
    participant L as Analysis loop
    participant M as Model
    B->>API: get ScaledObject (name, UID)
    API-->>B: object, or an error
    B-->>L: blocks + snapshot (or none)
    L->>L: kedaready.Readiness(snapshot)
    L->>M: system prompt (catalog, maybe without AdjustKedaMaxReplicas) + context (+ fixed sentence)
    M-->>L: result
    alt not ready, no proposal or AdjustKedaMaxReplicas
        L->>L: ScalerNotReady
    else AdjustKedaMaxReplicas, ready or pending
        L->>L: previous value from the snapshot, or DirectionReversed, NoChange, PreviousValueUnknown
    end

Consequences

The two misses of #640 lose their cause. keda-at-ceiling no longer depends on the model knowing maxReplicaCount: the plan carries the snapshot's value, and a model that writes a stale value in the right direction still gets a valid plan. broken-keda-trigger can no longer end in a proposal of AdjustKedaMaxReplicas, because the action is not offered and a reply proposing it is dropped by code; it ends ScalerNotReady whatever its model replies, except when the result is invalid, the model call fails or the result proposes another action: those keep their own end. ScalerNotReady is the reason the incident's condition and kubectl shadewright explain show to the person who takes it over. Its expected outcome in the recorded eval changes from a model refusal (NoProposal or MissingData) to ScalerNotReady; no other scenario changes.

The analyzer makes one more read per KEDA analysis. A ScaledObject the analyzer may not read (the module's role not bound) now escalates the analysis as a failed source, where before the block said the kind was not read. When that read fails the action is still offered, a proposal of it ends PreviousValueUnknown, and the model call is kept for the diagnosis.

The model sees more text an attacker may write. The adversaries considered:

  • A cluster content author (whoever controls a metrics endpoint or a ScaledObject's spec): the condition messages and names are shown, redacted and bounded, inside a delimited block marked as data. They cannot change the catalog, the tools, the schema or the policy block, which are code and typed policy fields; a test plants an injection in a condition message and checks that. The allow-list keeps the trigger's metadata out of the ScaledObject block. Error text in a condition message or an Event can still hold a query or an address with a token (decision 6), and only the redactor protects it.
  • A namespace tenant who can edit the ScaledObject: they can already change maxReplicaCount in Git. Writing a false condition is not possible for them (KEDA writes the status), and annotations, which they could write, are not shown. A pause annotation makes the object not ready, which only withholds the action. Since the amendment of 2026-11-15 they also choose, through the spec (spec.advanced.horizontalPodAutoscalerConfig.name), a status field that is shown: status.hpaName, which names the HPA whose metrics the model sees, and they choose that HPA's metric names; a metric name outside the plain-name pattern leaves its series out.
  • A wrong but trusted model cannot pick the baseline, and it cannot get a raise past a ScaledObject that is not ready. Within the policy bounds it can still propose a step that is too large; the person who merges is the check there, as ADR-0026 says.
  • Restart and race: the snapshot is read once and used for the whole analysis; the executor reads the live object again for its gate, its baseline check and freshness, so a ScaledObject that changes after the analysis is caught there. No decision compares times from two clocks.
  • Cost: one get per KEDA analysis, and a few hundred bytes of context inside the status section's existing bound. Since the amendment of 2026-11-15, also two Prometheus queries per KEDA analysis with a valid HPA name: hpa_metric_current, a range query over the window, and hpa_metric_target, an instant query, inside the metrics block's existing bound. Since the amendment of 2026-11-16, also one get of the HPA from the analyzer's cache before those queries: no API call, as the cache already watches the HPAs of the watched namespaces for the KEDA module's symptom source.

Alternatives considered

  • A prompt rule that a scaling change does not fix a trigger that cannot reach its metrics source (scope of #640). The model would still decide, and a model that ignored the rule would still propose. Readiness is a fact the code can read, so the code decides it.
  • Show the ScaledObject but keep the model's previousValue and its readiness reading. The misses of #640 were the model getting those two facts wrong; giving it the facts helps, deciding them in code removes the miss.
  • Read the HPA as well, for its current and desired replicas. It is a second read and a second object to keep in step with the ScaledObject, for a number the Incident's symptom already carries in the ceiling case (see the amendments of 2026-11-15 and 2026-11-16).
  • Keep MissingData for a not-ready analysis whose model names missing data. The outcome would then depend on how the model words its answer, and the eval could not expect one reason.

Amendments

  • 2026-11-15 (#480): for a KEDA incident the model now also sees the name of the ScaledObject's HPA (status.hpaName) and that HPA's current and target metric values. They are shown in the metrics block as series lines of the two approved templates hpa_metric_current and hpa_metric_target, which read kube-state-metrics through the metrics source, and the name is the horizontalpodautoscaler label of those lines. hpaName is not in the allow-list of the ScaledObject block. This is not the rejected alternative "Read the HPA as well": no API call reads the HPA (since 2026-11-16 the cache does, for the owner check only), there is no new RBAC and no second object to keep in step with the snapshot; the name comes from the ScaledObject already read and only selects series in the target's namespace. The last sentence of decision 3 is brought in line. The name is checked as a DNS-1123 subdomain before it is sent; a missing or invalid one is never queried and the block says so. What is new in the threat: these strings are cluster-influenced. KEDA's documentation says spec.advanced.horizontalPodAutoscalerConfig.name is the name of the HPA KEDA creates (default keda-hpa-{scaled-object-name}), so whoever can edit the ScaledObject chooses the HPA's name, and the metric_name and other label values of the series come from whoever defines the HPA's metrics. They pass the same handling as the labels of every metric template (internal/incidentcontext/metrics.go): every key and value goes through the redactor, a value over 1 KiB after redaction is replaced by a note of its size (it is not cut), control characters and Unicode line separators become spaces, the block is bounded (8 KiB by default), and a query answers at most 50 series (MaxSeries). The series lines are quotable, as for any metric. The query for the HPA templates is built by code from the name and the ScaledObject's own namespace, so a name cannot select series of another namespace. The metric name is the one label of these series that Kubernetes does not hold to a name syntax (it refuses only /, % and the names . and ..; the HPA name is a DNS-1123 subdomain and the target type is value, average or utilization), and the context renders label values as they are, so a metric name such as x,metric_target_type=average} last 1 could pass for the end of a series line and a number written by code. For the two HPA templates only, the Prometheus adapter therefore leaves out a series whose metric name is not 1 to 253 letters, digits, _, -, ., / or : (KEDA's names, such as s0-prometheus, run to tens of characters; 253 is the bound of every other label value), counts it in MetricsResult.LeftOut and keeps no part of it, and the metrics block says in a fixed line how many series were left out because of a label. The rule lives in the adapter next to the other label checks (internal/providers/metrics/prometheus/decode.go): there any other label value that is not a plain name still refuses the whole answer, as before, and the rendering of every other template is unchanged. Whether the HPA named by status.hpaName is the ScaledObject's own is checked since the amendment of 2026-11-16. This does not widen what is allowed, granted or refused. A Proposed ADR may still change, and the dated entry is kept for the record.
  • 2026-11-16 (#480): the HPA named by status.hpaName gives the metric templates only when it is the ScaledObject's own. The context builder gets it, by that name in the ScaledObject's namespace, from the analyzer's cache as an unstructured autoscaling/v2 object, the informer the KEDA module's symptom source already runs; the analyzer's role already grants get, list and watch on HPAs (config/rbac/analyzer/watch/role.yaml), so there is no new RBAC. The HPA passes when its controller owner reference names a keda.sh ScaledObject with the UID of the Incident's subject, and its spec.scaleTargetRef names the ScaledObject's own scale target (kind, API group and name, with KEDA's defaults apps/v1 and Deployment for the ScaledObject's). Otherwise no template is asked and the metrics block says so in fixed text, with no part of the HPA: "the HPA the ScaledObject names was not found" (the cache has no such HPA) or "does not scale its target for it". Neither is an escalation signal. A failed read of the cache is a failed source ("could not fetch", an escalation signal), never "not found". No field of the HPA is shown. This replaces the limit of the entry of 2026-11-15, where the check was rejected because it needs a read of the HPA: the read costs one get from a cache the analyzer already keeps, and no API call. What it does not cover: an owner reference is written by whoever can write the HPA, so a tenant who may write HPAs in the namespace can still give another HPA the ScaledObject's UID and scale target; such an HPA then scales the same workload as KEDA's own. Evaluation gate (ADR-0025): the two amendments change model input. The recorded scenario keda-at-ceiling has the HPA and its series (metrics.yaml, synthetic) and a hand-written reply that quotes the HPA lines, so it proves that the lines reach the context and can be cited, not how a model uses them; the existing cases show no regression. The run with a real model is owed in the lab run of the release that builds this, rows 5 and 8 of the fleet's scenario matrix (keda-at-ceiling), before the release. Decision 2 and the last sentence of decision 3 are brought in line.