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.

fix(signals): scout-model gate wins over the fleet-wide runtime pin (#72537)

Andrew Maguire59665a450476
diff --git a/products/signals/backend/scout_harness/model_selection.py b/products/signals/backend/scout_harness/model_selection.py
index f0ed41a74fe4..b7a4214a1707 100644
--- a/products/signals/backend/scout_harness/model_selection.py
+++ b/products/signals/backend/scout_harness/model_selection.py
@@ -34,8 +34,10 @@ distinct_id) is the single source of truth; a team with no entry runs entirely o
that scout's runs (0..1) it serves. `signals-scout-team-self-driving` above runs 20% on glm-5.2,
20% on gpt-5.5, and the remaining 60% on the agent-server default. `"*"` is the fallback
distribution for scouts not listed explicitly. A model's value may instead be an object
- `{"fraction": 0.2, "runtime_adapter": "codex"}` to pin its runtime explicitly; with the bare-number
- form the runtime is inferred from the id (`claude-*` → `claude`, everything else → `codex`).
+ `{"fraction": 0.2, "runtime_adapter": "codex", "reasoning_effort": "high"}` to pin its runtime
+ (and optionally the reasoning effort) explicitly; with the bare-number form the runtime is
+ inferred from the id (`claude-*` → `claude`, everything else → `codex`) and the effort is left
+ unset (agent-server default).
- 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.
@@ -83,9 +85,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"}`.
+# `{"fraction": <0..1>, "runtime_adapter": "claude"|"codex", "reasoning_effort": "high"}`.
FRACTION_KEY = "fraction"
RUNTIME_ADAPTER_KEY = "runtime_adapter"
+REASONING_EFFORT_KEY = "reasoning_effort"
# The two agent runtimes the agent server exposes. A model id alone can't be routed — the server
# derives its provider (Anthropic / OpenAI) from the runtime — so every routed model also carries a
@@ -99,20 +102,28 @@ RUNTIME_ADAPTER_CODEX = "codex"
# be able to break.
_KNOWN_RUNTIME_ADAPTERS = frozenset({RUNTIME_ADAPTER_CLAUDE, RUNTIME_ADAPTER_CODEX})
+# The reasoning efforts a payload may pin, mirroring the tasks `ReasoningEffort` enum. Same
+# defensive posture as `_KNOWN_RUNTIME_ADAPTERS`: an unknown value is dropped (effort unset,
+# agent-server default) rather than threaded into the run state where it could fail the run.
+_KNOWN_REASONING_EFFORTS = frozenset({"low", "medium", "high", "xhigh", "max"})
+
@dataclass(frozen=True)
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` is 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 (it silently falls back to
- the server default, which is the bug this resolution exists to avoid).
+ `model` is the model id; `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
+ (it silently falls back to the server default, which is the bug this resolution exists to
+ avoid). `reasoning_effort` is the optional per-model effort pin from the payload's object form;
+ `None` keeps the agent-server default effort.
"""
model: str | None
runtime_adapter: str | None
+ reasoning_effort: str | None = None
def _infer_runtime_adapter(model_id: str) -> str:
@@ -172,38 +183,43 @@ def _team_scouts(payload: object, team_id: int, canonical_team_id: int) -> dict:
return scouts if isinstance(scouts, dict) else {}
-def _parse_model_spec(spec: object) -> tuple[float | None, str | None]:
- """A `(fraction, runtime_adapter)` from one model entry's value.
+def _parse_model_spec(spec: object) -> tuple[float | None, str | None, str | None]:
+ """A `(fraction, runtime_adapter, reasoning_effort)` from one model entry's value.
- A model entry's value is either a bare number (its fraction; runtime inferred from the id) or an
- object `{"fraction": <0..1>, "runtime_adapter": "claude"|"codex"}` that pins the runtime
- explicitly. Returns `(None, ...)` for a malformed fraction (not a positive number, or a bool) so
- the caller drops the entry rather than failing the run. A `runtime_adapter` that isn't one of the
- known runtimes (non-string, typo, unsupported) is ignored (treated as unset → inferred from the
- id), so a payload typo can't route the run onto a runtime the agent server can't honor.
+ A model entry's value is either a bare number (its fraction; runtime inferred from the id,
+ effort unset) or an object `{"fraction": <0..1>, "runtime_adapter": "claude"|"codex",
+ "reasoning_effort": "high"}` that pins the runtime (and optionally the effort) explicitly.
+ Returns `(None, ...)` for a malformed fraction (not a positive number, or a bool) so the caller
+ drops the entry rather than failing the run. A `runtime_adapter` or `reasoning_effort` 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 or effort the agent server can't honor.
"""
if isinstance(spec, dict):
weight = spec.get(FRACTION_KEY)
adapter_value = spec.get(RUNTIME_ADAPTER_KEY)
+ effort_value = spec.get(REASONING_EFFORT_KEY)
# `isinstance` first: an unhashable value (JSON array/object) would raise from the set
# membership test, and that escapes `_read_payload`'s guard and would fail the run.
adapter = adapter_value if isinstance(adapter_value, str) and adapter_value in _KNOWN_RUNTIME_ADAPTERS else None
+ effort = effort_value if isinstance(effort_value, str) and effort_value in _KNOWN_REASONING_EFFORTS else None
else:
weight = spec
adapter = None
+ effort = None
if not isinstance(weight, int | float) or isinstance(weight, bool) or weight <= 0:
- return None, adapter
- return min(1.0, float(weight)), adapter
+ return None, adapter, effort
+ return min(1.0, float(weight)), adapter, effort
-def _scout_config(scouts: dict, skill_name: str) -> tuple[dict[str, float], dict[str, str], str | None]:
- """The `(distribution, adapters, default_model)` for one scout from a team's scout map.
+def _scout_config(scouts: dict, skill_name: str) -> tuple[dict[str, float], dict[str, str], dict[str, str], str | None]:
+ """The `(distribution, adapters, efforts, default_model)` for one scout from a team's scout map.
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}`
- weight. `adapters` carries only the model ids whose runtime was pinned explicitly in the payload;
- the rest are inferred from the id at resolve time. Defensive — a missing/non-object scout entry,
+ agent-server default); every other entry is a `model_id -> fraction | {fraction, runtime_adapter,
+ reasoning_effort}` weight. `adapters` and `efforts` carry only the model ids whose runtime /
+ effort was pinned explicitly in the payload; unpinned runtimes are inferred from the id at
+ resolve time and unpinned efforts 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.
"""
@@ -211,25 +227,28 @@ def _scout_config(scouts: dict, skill_name: str) -> tuple[dict[str, float], dict
if not isinstance(raw, dict):
raw = scouts.get(WILDCARD)
if not isinstance(raw, dict):
- return {}, {}, None
+ return {}, {}, {}, None
default_value = raw.get(DEFAULT_MODEL_KEY)
default_model = default_value if isinstance(default_value, str) and default_value else None
distribution: dict[str, float] = {}
adapters: dict[str, str] = {}
+ efforts: dict[str, str] = {}
for model_id, spec in raw.items():
if model_id == DEFAULT_MODEL_KEY:
continue
if not isinstance(model_id, str) or not model_id:
continue
- fraction, adapter = _parse_model_spec(spec)
+ fraction, adapter, effort = _parse_model_spec(spec)
if fraction is None:
continue
distribution[model_id] = fraction
if adapter is not None:
adapters[model_id] = adapter
- return distribution, adapters, default_model
+ if effort is not None:
+ efforts[model_id] = effort
+ return distribution, adapters, efforts, default_model
def _bucket(run_id: str) -> float:
@@ -271,8 +290,12 @@ def resolve_scout_model(team: Team, skill_name: str, run_id: str) -> ScoutModel:
"""
payload = _read_payload()
scouts = _team_scouts(payload, team.id, team.parent_team_id or team.id)
- distribution, adapters, default_model = _scout_config(scouts, skill_name)
+ distribution, adapters, efforts, default_model = _scout_config(scouts, skill_name)
model = _select_model(run_id, distribution, default_model)
if model is None:
return ScoutModel(model=None, runtime_adapter=None)
- return ScoutModel(model=model, runtime_adapter=adapters.get(model) or _infer_runtime_adapter(model))
+ return ScoutModel(
+ model=model,
+ runtime_adapter=adapters.get(model) or _infer_runtime_adapter(model),
+ reasoning_effort=efforts.get(model),
+ )
diff --git a/products/signals/backend/scout_harness/runner.py b/products/signals/backend/scout_harness/runner.py
index 2c0206ba5e93..3547af3b486e 100644
--- a/products/signals/backend/scout_harness/runner.py
+++ b/products/signals/backend/scout_harness/runner.py
@@ -224,18 +224,25 @@ async def arun_signals_scout(
team, skill.name, str(run_id)
)
- # A runtime pin takes precedence over the scout-model gate and replaces it wholesale —
- # runtime/model/effort move as a set so a Codex runtime never pairs with a glm model.
- # Model-only payload entries are deliberately ignored for scout: the gate supplies
+ # The scout-model gate is the per-scout, per-run experiment layer; the `signals-pipeline-models`
+ # runtime pin is the default layer beneath it. When the gate resolves a model for this run it
+ # wins (its unallocated remainder resolves None and falls through to the pin), so a fleet-wide
+ # pin can't silently swallow a configured model trial. Either way the whole
+ # runtime/model/effort triple is taken from one source — a Codex runtime never pairs with a
+ # model it can't serve. Model-only pin entries are still ignored for scout: a pin supplies
# model+runtime as a pair, and overriding one without the other would mis-route.
agent_runtime = await database_sync_to_async(resolve_agent_runtime, thread_sensitive=False)(team_id, STEP_SCOUT)
- if agent_runtime.runtime_adapter:
- runtime_adapter: str | None = agent_runtime.runtime_adapter
+ if scout_model.model:
+ runtime_adapter: str | None = scout_model.runtime_adapter
+ model: str | None = scout_model.model
+ reasoning_effort: str | None = scout_model.reasoning_effort
+ elif agent_runtime.runtime_adapter:
+ runtime_adapter = agent_runtime.runtime_adapter
model = agent_runtime.model
- reasoning_effort: str | None = agent_runtime.reasoning_effort
+ reasoning_effort = agent_runtime.reasoning_effort
else:
- runtime_adapter = scout_model.runtime_adapter
- model = scout_model.model
+ runtime_adapter = None
+ model = None
reasoning_effort = None
try:
last_message, task_run_id = await _spawn_and_run(
diff --git a/products/signals/backend/test/test_scout_harness.py b/products/signals/backend/test/test_scout_harness.py
index 96ff323f40e5..bd16955514a0 100644
--- a/products/signals/backend/test/test_scout_harness.py
+++ b/products/signals/backend/test/test_scout_harness.py
@@ -721,18 +721,44 @@ async def test_run_tags_session_with_scout_ai_stage(ateam, aerrors_skill):
@pytest.mark.asyncio
@pytest.mark.django_db
@pytest.mark.parametrize(
- "resolved, expected_model, expected_runtime_adapter",
+ "resolved, pin, expected_model, expected_runtime_adapter, expected_reasoning_effort",
[
- (ScoutModel(model="@cf/zai-org/glm-5.2", runtime_adapter="codex"), "@cf/zai-org/glm-5.2", "codex"),
- (ScoutModel(model=None, runtime_adapter=None), None, None),
+ # Gate resolved, no pin: the gate's triple reaches the sandbox as-is — the runtime (and
+ # optional effort) travel with the model so the agent server can route it.
+ (
+ ScoutModel(model="@cf/zai-org/glm-5.2", runtime_adapter="codex", reasoning_effort="high"),
+ AgentRuntime(),
+ "@cf/zai-org/glm-5.2",
+ "codex",
+ "high",
+ ),
+ # Gate resolved AND a fleet-wide pin present: the gate wins — a pin silently swallowing a
+ # configured model trial is the production bug this ordering exists to prevent.
+ (
+ ScoutModel(model="@cf/zai-org/glm-5.2", runtime_adapter="codex"),
+ AgentRuntime(runtime_adapter="codex", model="gpt-5.5", reasoning_effort="high"),
+ "@cf/zai-org/glm-5.2",
+ "codex",
+ None,
+ ),
+ # Gate unallocated remainder: falls through to the pin's whole triple (the fleet default).
+ (
+ ScoutModel(model=None, runtime_adapter=None),
+ AgentRuntime(runtime_adapter="codex", model="gpt-5.5", reasoning_effort="high"),
+ "gpt-5.5",
+ "codex",
+ "high",
+ ),
+ # Neither configured: agent-server default.
+ (ScoutModel(model=None, runtime_adapter=None), AgentRuntime(), None, None, None),
],
)
async def test_run_pins_sandbox_to_resolved_scout_model(
- ateam, aerrors_skill, resolved, expected_model, expected_runtime_adapter
+ ateam, aerrors_skill, resolved, pin, expected_model, expected_runtime_adapter, expected_reasoning_effort
):
- # The `scouts-model-selection` gate resolves an agent-model override (glm-5.2 on the codex
- # runtime) or the agent-server default (None/None); the runner must hand both straight to the
- # sandbox via the context — the runtime travels with the model so the agent server can route it.
+ # The `scouts-model-selection` gate is the per-run experiment layer and wins when it resolves a
+ # model; the `signals-pipeline-models` pin is the default layer beneath it. Either way one
+ # source supplies the whole runtime/model/effort triple.
session, result = await database_sync_to_async(_make_fake_session, thread_sensitive=False)(ateam)
captured: dict = {}
@@ -748,10 +774,9 @@ async def test_run_pins_sandbox_to_resolved_scout_model(
"products.signals.backend.scout_harness.runner.resolve_scout_model",
return_value=resolved,
),
- # No `signals-pipeline-models` runtime pin: the scouts-glm model gate drives the run.
patch(
"products.signals.backend.scout_harness.runner.resolve_agent_runtime",
- return_value=AgentRuntime(),
+ return_value=pin,
),
patch(
"products.signals.backend.scout_harness.runner.get_or_create_signals_sandbox_env",
@@ -766,46 +791,7 @@ async def test_run_pins_sandbox_to_resolved_scout_model(
assert captured["context"].model == expected_model
assert captured["context"].runtime_adapter == expected_runtime_adapter
-
-
-async def test_codex_runtime_pin_overrides_scout_model(ateam, aerrors_skill):
- # A runtime pin replaces the scouts-glm gated model wholesale (runtime/model move as a set).
- session, result = await database_sync_to_async(_make_fake_session, thread_sensitive=False)(ateam)
- captured: dict = {}
-
- async def _capture_start(*args, on_task_run_created=None, **kwargs):
- captured.update(kwargs)
- if on_task_run_created is not None:
- await on_task_run_created(session.task_run)
- return session, result
-
- with (
- patch("products.signals.backend.scout_harness.runner.MultiTurnSession.start", new=_capture_start),
- patch(
- "products.signals.backend.scout_harness.runner.resolve_scout_model",
- return_value="@cf/zai-org/glm-5.2",
- ),
- patch(
- "products.signals.backend.scout_harness.runner.resolve_agent_runtime",
- return_value=AgentRuntime(runtime_adapter="codex", model="gpt-5.5", reasoning_effort="high"),
- ),
- patch(
- "products.signals.backend.scout_harness.runner.get_or_create_signals_sandbox_env",
- return_value="env-id",
- ),
- patch(
- "products.signals.backend.scout_harness.runner.resolve_acting_user_id_for_team",
- return_value=42,
- ),
- ):
- await arun_signals_scout(team_id=ateam.id, skill_name="signals-scout-errors")
-
- ctx = captured["context"]
- assert ctx.runtime_adapter == "codex"
- assert ctx.model == "gpt-5.5"
- assert ctx.reasoning_effort == "high"
+ assert captured["context"].reasoning_effort == expected_reasoning_effort
@pytest.mark.asyncio
diff --git a/products/signals/backend/test/test_scout_model_selection.py b/products/signals/backend/test/test_scout_model_selection.py
index 1d216c0bf671..2ec06afadc42 100644
--- a/products/signals/backend/test/test_scout_model_selection.py
+++ b/products/signals/backend/test/test_scout_model_selection.py
@@ -106,6 +106,31 @@ class TestResolveScoutModel:
)
assert resolved == ScoutModel(model=GLM_MODEL, runtime_adapter="codex")
+ def test_object_form_carries_reasoning_effort(self) -> None:
+ # The effort pin must survive resolution — a dropped effort silently runs the trial arm at a
+ # different effort than the baseline arm, skewing the comparison.
+ resolved = _resolve_full(
+ payload=_scouts(
+ {_SKILL: {GLM_MODEL: {"fraction": 1, "runtime_adapter": "codex", "reasoning_effort": "high"}}}
+ )
+ )
+ assert resolved == ScoutModel(model=GLM_MODEL, runtime_adapter="codex", reasoning_effort="high")
+
+ @parameterized.expand(
+ [
+ # A bad effort must not reach the run state — like a bad runtime, it'd fail the run
+ # downstream. Drop it (effort unset) and keep the model + runtime.
+ ("typo", "hgih"),
+ ("non_string", 5),
+ ("list", ["high"]),
+ ]
+ )
+ def test_bad_reasoning_effort_is_dropped_not_fatal(self, _name: str, bad_effort: object) -> None:
+ resolved = _resolve_full(
+ payload=_scouts({_SKILL: {GLM_MODEL: {"fraction": 1, "reasoning_effort": bad_effort}}})
+ )
+ assert resolved == ScoutModel(model=GLM_MODEL, runtime_adapter="codex", reasoning_effort=None)
+
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(