Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(signals): let scout model-selection entries name their model (#99484)

posthog[bot]388c749a0adc
diff --git a/products/signals/backend/scout_harness/AGENTS.md b/products/signals/backend/scout_harness/AGENTS.md
index 79ac2b51635c..457bc6ab6aa4 100644
--- a/products/signals/backend/scout_harness/AGENTS.md
+++ b/products/signals/backend/scout_harness/AGENTS.md
@@ -119,6 +119,7 @@ In production it is driven by `SignalsScoutCoordinatorWorkflow` (periodic tick e
together they pin down which instructions the run was given, which is the thing an eval or A/B has to hold constant. The last four are composition forks the build alone doesn't capture, since the same prompt build renders different sections depending on channel, skill origin, whether a read-only GitHub token could be minted, and whether the team's knowledge base looks maintained (flag + upkeep, per `business_knowledge.is_maintained_for_team`).
Each is unrecoverable after the fact (the prompt has no version history, a skill's `allowed_tools` can be edited, a seeded canonical row flips to `custom` the moment a team edits it taking every past run's origin with it, and the flag / source state behind the last two can change between runs), which is why they are stamped rather than resolved at read time.
`model` / `runtime_adapter` / `reasoning_effort` appear only when something overrode the agent-server default — a `SignalScoutConfig.model` pin (honored while the `scouts-model-config` dogfood flag is on for the team, and the top layer of `model_selection.resolve_scout_model`), the `scouts-model-selection` gate, or a runtime pin — so their absence is meaningful. `service_tier` (the OpenAI queue a Codex run asked for: `flex`, `priority`, or `default`) follows the same rule and travels with the model it was configured beside: the selected slice's own object form, or the pipeline pin's when the pin's model runs, never inherited across models, and dropped on a claude runtime. That is what lets one slice trial flex against the remainder's standard queue on the same model.
+ An entry that names its `model` in the object form makes its key a label for the arm rather than the model id, so one model can also carry several explicit arms (`sol-flex` and `sol` both resolving to `gpt-5.6-sol`) that duplicate JSON keys could not express; the stamp always carries the resolved model id, never the label.
All five are attached to both lifecycle events via `_attach_run_shape_props`, since that is where the A/B readout happens, and `github_guidance` and `business_knowledge_maintained` are resolved in `arun_signals_scout` rather than inside `_spawn_and_run` so the failure and cancellation paths can report them too.
New runner-known run dimensions belong here, not grown as ad-hoc columns.
`run_note` is the one key that is neither a dimension nor runner-resolved: the one-off steering a person typed on the `configs/<id>/run/` trigger, kept verbatim because it is the only record of why a manual run behaved differently from the scheduled ones around it. It is prose, not a value to group by.
diff --git a/products/signals/backend/scout_harness/model_selection.py b/products/signals/backend/scout_harness/model_selection.py
index 3995ca099734..0a3861ac11c4 100644
--- a/products/signals/backend/scout_harness/model_selection.py
+++ b/products/signals/backend/scout_harness/model_selection.py
@@ -37,10 +37,17 @@ distinct_id) is the single source of truth; a team with no entry runs entirely o
`{"fraction": 0.2, "runtime_adapter": "codex", "reasoning_effort": "high", "service_tier": "flex"}`
to pin its runtime (and optionally the reasoning effort and the OpenAI service tier) explicitly;
with the bare-number form the runtime is inferred from the id (`claude-*` → `claude`, everything
- else → `codex`) and the effort and tier are left unset (agent-server default). A tier on a slice
- is what makes a same-model A/B on queueing possible: one explicit `gpt-5.6-terra` slice pinned to
- `flex` against the unallocated remainder falling through to the `signals-pipeline-models` pin for
- the same model on the standard queue.
+ else → `codex`) and the effort and tier are left unset (agent-server default). The object form may
+ also name its `model`, and then the key is a label for the arm instead of the model id. That is
+ how one model carries several arms, since duplicate JSON keys collapse into one entry:
+
+ "sol-flex": {"model": "gpt-5.6-sol", "fraction": 0.05, "service_tier": "flex"},
+ "sol": {"model": "gpt-5.6-sol", "fraction": 0.05}
+
+ A tier on a slice is what makes a same-model A/B on queueing possible: two labelled slices of one
+ model on different queues, as above, or a single `gpt-5.6-terra` slice pinned to `flex` against the
+ unallocated remainder falling through to the `signals-pipeline-models` pin for the same model on
+ the standard queue.
- The reserved `"default"` key inside a scout's map names the model the *remaining* (unallocated)
runs use instead of the agent-server default — its value is a model-id string, not a fraction.
@@ -105,8 +112,10 @@ WILDCARD = "*"
DEFAULT_MODEL_KEY = "default"
# Keys recognized in the object form of a model entry (the alternative to a bare fraction):
-# `{"fraction": <0..1>, "runtime_adapter": "claude"|"codex", "reasoning_effort": "high",
-# "service_tier": "flex"}`.
+# `{"model": "gpt-5.6-sol", "fraction": <0..1>, "runtime_adapter": "claude"|"codex",
+# "reasoning_effort": "high", "service_tier": "flex"}`. With `model` set the entry's key is only a
+# label for the arm, which is how one model holds several arms.
+MODEL_KEY = "model"
FRACTION_KEY = "fraction"
RUNTIME_ADAPTER_KEY = "runtime_adapter"
REASONING_EFFORT_KEY = "reasoning_effort"
@@ -139,7 +148,8 @@ _KNOWN_SERVICE_TIERS = KNOWN_SERVICE_TIERS
class ScoutModel:
"""The agent-model override resolved for one scout run.
- `model` is the model id; `None` keeps the agent-server default (and `runtime_adapter` /
+ `model` is the model id: the entry's own `model` when it named one, else its key, and never the
+ label. `None` keeps the agent-server default (and `runtime_adapter` /
`reasoning_effort` are then also `None`). When a model is chosen, `runtime_adapter` names the
agent runtime that can serve it — it must travel with the model because the agent server derives
the LLM provider from the runtime, and a model id handed over with no runtime can't be routed
@@ -275,11 +285,13 @@ def _team_scouts(payload: object, team_id: int, canonical_team_id: int) -> dict:
class _ModelSpec:
"""One parsed model entry: its fraction plus whichever pins the object form carried.
- `fraction` is `None` for a malformed weight so the caller drops the entry. The pins are `None`
- when absent or unrecognized, never a value the agent server can't honor.
+ `fraction` is `None` for a malformed weight so the caller drops the entry. `model` is the model
+ the entry named, which makes its key a label; `None` means the key is itself the model id. The
+ pins are `None` when absent or unrecognized, never a value the agent server can't honor.
"""
fraction: float | None
+ model: str | None = None
runtime_adapter: str | None = None
reasoning_effort: str | None = None
service_tier: str | None = None
@@ -295,17 +307,26 @@ def _parse_model_spec(spec: object) -> _ModelSpec:
"""The fraction and pins from one model entry's value.
A model entry's value is either a bare number (its fraction; runtime inferred from the id,
- effort and tier unset) or an object `{"fraction": <0..1>, "runtime_adapter": "claude"|"codex",
- "reasoning_effort": "high", "service_tier": "flex"}` that pins the runtime (and optionally the
- effort and the OpenAI queue) explicitly. A malformed fraction (not a positive number, or a bool)
- yields `fraction=None` so the caller drops the entry rather than failing the run. A pin that
- isn't one of the known values (non-string, typo, unsupported) is ignored (treated as unset), so
- a payload typo can't route the run onto a runtime, effort, or queue the agent server can't honor.
+ effort and tier unset) or an object `{"model": "gpt-5.6-sol", "fraction": <0..1>,
+ "runtime_adapter": "claude"|"codex", "reasoning_effort": "high", "service_tier": "flex"}` that
+ names the model (making the key a label) and pins the runtime (and optionally the effort and the
+ OpenAI queue) explicitly. A malformed fraction (not a positive number, or a bool) yields
+ `fraction=None` so the caller drops the entry rather than failing the run. A pin that isn't one
+ of the known values (non-string, typo, unsupported) is ignored (treated as unset), so a payload
+ typo can't route the run onto a runtime, effort, or queue the agent server can't honor.
+
+ A malformed `model` drops the entry instead of being ignored, because an entry that names its
+ model is read as a label: nothing in the key can stand in for the missing id, and routing the run
+ onto the label would hand the agent server a model that doesn't exist.
"""
if not isinstance(spec, dict):
return _ModelSpec(fraction=_parse_fraction(spec))
+ model = spec.get(MODEL_KEY)
+ if MODEL_KEY in spec and not (isinstance(model, str) and model):
+ return _ModelSpec(fraction=None)
return _ModelSpec(
fraction=_parse_fraction(spec.get(FRACTION_KEY)),
+ model=model if isinstance(model, str) else None,
runtime_adapter=_known_str(spec.get(RUNTIME_ADAPTER_KEY), _KNOWN_RUNTIME_ADAPTERS),
reasoning_effort=_known_str(spec.get(REASONING_EFFORT_KEY), _KNOWN_REASONING_EFFORTS),
service_tier=_known_str(spec.get(SERVICE_TIER_KEY), _KNOWN_SERVICE_TIERS),
@@ -323,11 +344,14 @@ def _scout_config(scouts: dict, skill_name: str) -> tuple[dict[str, _ModelSpec],
Looks up `scouts[skill_name]`, falling back to the `"*"` scout wildcard. The reserved `"default"`
string key is pulled out as `default_model` (the model for the unallocated remainder; `None` =
- agent-server default); every other entry is a `model_id -> fraction | {fraction, runtime_adapter,
- reasoning_effort, service_tier}` weight, parsed into a `_ModelSpec`. Unpinned runtimes are
- inferred from the id at resolve time; unpinned efforts and tiers stay unset. Defensive — a
- missing/non-object scout entry, or a malformed weight (not a positive number, or a bool) is
- dropped rather than failing the run, so a typo can't crash a scout or route it unintended.
+ agent-server default); every other entry is a `model_id -> fraction | {model, fraction,
+ runtime_adapter, reasoning_effort, service_tier}` weight, parsed into a `_ModelSpec`. The specs
+ stay keyed by the payload's own key, which is the model id unless the entry named a `model` and
+ the key is therefore a label, and that key is what keeps two arms of one model apart. Unpinned
+ runtimes are inferred from the resolved model id at resolve time; unpinned efforts and tiers stay
+ unset. Defensive — a missing/non-object scout entry, or a malformed weight (not a positive
+ number, or a bool) is dropped rather than failing the run, so a typo can't crash a scout or route
+ it unintended.
"""
raw = scouts.get(skill_name)
if not isinstance(raw, dict):
@@ -339,15 +363,15 @@ def _scout_config(scouts: dict, skill_name: str) -> tuple[dict[str, _ModelSpec],
default_model = default_value if isinstance(default_value, str) and default_value else None
specs: dict[str, _ModelSpec] = {}
- for model_id, spec in raw.items():
- if model_id == DEFAULT_MODEL_KEY:
+ for key, spec in raw.items():
+ if key == DEFAULT_MODEL_KEY:
continue
- if not isinstance(model_id, str) or not model_id:
+ if not isinstance(key, str) or not key:
continue
parsed = _parse_model_spec(spec)
if parsed.fraction is None:
continue
- specs[model_id] = parsed
+ specs[key] = parsed
return specs, default_model
@@ -367,21 +391,23 @@ def _select_model(
) -> tuple[str | None, _ModelSpec | None]:
"""Pick a model for this run from the scout's distribution, deterministically on `run_id`.
- Walks the models in sorted-id order accumulating their fractions; the run's bucket falls into
- exactly one model's slice, or past them all into the remainder → `default_model`. Sorted order
+ Walks the entries in sorted-key order accumulating their fractions; the run's bucket falls into
+ exactly one entry's slice, or past them all into the remainder → `default_model`. Sorted order
makes the assignment stable across runs/processes. If the fractions sum to ≥ 1 the remainder is
- empty and `default_model` simply never runs. Returns the selected slice's spec alongside the
- model, and `None` for the remainder: which branch picked the model is decided here, not
- recovered from the model id, so a remainder that names the same model as a weighted slice
+ empty and `default_model` simply never runs. Each entry resolves to the model it named, falling
+ back to its key, so two labelled entries for one model are two slices that both land on it.
+ Returns the selected slice's spec alongside the model, and `None` for the remainder: which branch
+ picked the model is decided here, not recovered from the model id, so a remainder that names the
+ same model as a weighted slice
(`{"gpt-5.6-terra": {"fraction": 0.05, "service_tier": "flex"}, "default": "gpt-5.6-terra"}`)
stays the pin-free control instead of inheriting the slice's tier.
"""
cumulative = 0.0
- for model_id in sorted(specs):
- spec = specs[model_id]
+ for key in sorted(specs):
+ spec = specs[key]
cumulative += spec.fraction if spec.fraction is not None else 0.0
if _bucket(run_id) < cumulative:
- return model_id, spec
+ return spec.model or key, spec
return default_model, None
diff --git a/products/signals/backend/test/test_scout_model_selection.py b/products/signals/backend/test/test_scout_model_selection.py
index c86efc4d05d4..83a1ef1eb31d 100644
--- a/products/signals/backend/test/test_scout_model_selection.py
+++ b/products/signals/backend/test/test_scout_model_selection.py
@@ -41,6 +41,18 @@ def _scouts(scouts: dict, team_id: int = _TEAM_ID) -> dict:
return {"teams": {str(team_id): {"scouts": scouts}}}
+def _tier_counts(payload: object, model: str, n: int = 400) -> dict[str | None, int]:
+ # Tiers across many run ids, with model and runtime held fixed: a same-model queue trial's arms
+ # must differ by tier alone.
+ counts: dict[str | None, int] = {}
+ for i in range(n):
+ resolved = _resolve_full(run_id=f"run-{i}", payload=payload)
+ assert resolved.model == model
+ assert resolved.runtime_adapter == "codex"
+ counts[resolved.service_tier] = counts.get(resolved.service_tier, 0) + 1
+ return counts
+
+
def _share(payload: object, skill: str = _SKILL, n: int = 400) -> dict[str | None, int]:
# Empirical model split across many run ids — buckets are uniform, so shares track the config.
counts: dict[str | None, int] = {}
@@ -148,21 +160,46 @@ class TestResolveScoutModel:
}
}
)
- tiers: dict[str | None, int] = {}
- for i in range(400):
- resolved = _resolve_full(run_id=f"run-{i}", payload=payload)
- assert resolved.model == GLM_MODEL
- assert resolved.runtime_adapter == "codex"
- tiers[resolved.service_tier] = tiers.get(resolved.service_tier, 0) + 1
+ tiers = _tier_counts(payload, GLM_MODEL)
assert set(tiers) == {"flex", None}
assert 5 <= tiers["flex"] <= 45 # ~5% of 400, loose enough not to flake
- def test_object_form_drops_malformed_fraction(self) -> None:
- # A pinned runtime can't rescue a malformed fraction — the entry is dropped, agent default kept.
- resolved = _resolve_full(
- payload=_scouts({_SKILL: {GLM_MODEL: {"fraction": "lots", "runtime_adapter": "codex"}}})
+ @parameterized.expand(
+ [
+ # A bad `model` drops the entry rather than falling back to the key the way a bad pin
+ # falls back to inference: with `model` set the key is a label, not a model id to route to.
+ ("fraction", {"fraction": "lots", "runtime_adapter": "codex"}),
+ ("model_empty", {"model": "", "fraction": 1}),
+ ("model_non_string", {"model": 5, "fraction": 1}),
+ ("model_null", {"model": None, "fraction": 1}),
+ ("model_list", {"model": [_GPT], "fraction": 1}),
+ ]
+ )
+ def test_object_form_drops_malformed_entry(self, _name: str, spec: dict) -> None:
+ assert _resolve_full(payload=_scouts({_SKILL: {GLM_MODEL: spec}})) == ScoutModel(
+ model=None, runtime_adapter=None
)
- assert resolved == ScoutModel(model=None, runtime_adapter=None)
+
+ def test_labelled_entry_resolves_to_the_model_it_names(self) -> None:
+ # The key is only a label, so the stamp and the runtime both come from `model`. Inferring the
+ # runtime off this label would say `claude` for a GPT arm and route it to the wrong provider.
+ resolved = _resolve_full(payload=_scouts({_SKILL: {"claude-sounding-label": {"model": _GPT, "fraction": 1}}}))
+ assert resolved == ScoutModel(model=_GPT, runtime_adapter="codex")
+
+ def test_two_labelled_arms_of_one_model_are_separate_slices(self) -> None:
+ # Keyed by model id these two entries would collapse into one, and the flex-vs-standard read
+ # would compare a model against itself on a single queue.
+ payload = _scouts(
+ {
+ _SKILL: {
+ "sol-flex": {"model": _GPT, "fraction": 0.5, "service_tier": "flex"},
+ "sol": {"model": _GPT, "fraction": 0.5},
+ }
+ }
+ )
+ tiers = _tier_counts(payload, _GPT)
+ assert set(tiers) == {"flex", None}
+ assert 150 <= tiers["flex"] <= 250 # ~half of 400, loose enough not to flake
def test_named_default_remainder_infers_its_runtime(self) -> None:
# The remainder model (named `default`) also gets a runtime inferred from its id. With no