fix(agent): accept only a real bool provider-level answer_in_reasoning

Gate C11 r4 quality: the `flags &= {True, False}` set filter let YAML
`1` count as an opt-in because 1 == True in a set. Keep only bool values
so a stray 1/0 never promotes private reasoning. New parametrize row
(acme-int, value 1) is red without this.
This commit is contained in:
kshitijk4poor
2026-10-06 11:57:52 +05:30
committed by kshitij
parent c4895a27a9
commit a1bccf3344
2 changed files with 4 additions and 2 deletions

View File

@@ -58,8 +58,8 @@ def answer_in_reasoning_capability(agent: Any) -> bool:
entries = list(_entries_for_route(base_url, custom_providers, None))
live = [e for e in entries
if custom_provider_slug(str(e.get("name") or ""), str(e.get("provider_key") or "")) in ids]
flags = {(e.get("capabilities") or {}).get(_ANSWER_IN_REASONING_CAPABILITY) for e in live or entries}
flags &= {True, False}
flags = {v for e in live or entries
if isinstance(v := (e.get("capabilities") or {}).get(_ANSWER_IN_REASONING_CAPABILITY), bool)}
if flags:
return flags == {True}

View File

@@ -34,6 +34,7 @@ _OPTED_IN_PROVIDERS = [
{"name": "acme", "base_url": "https://llm.example.com/v1", "model": "acme/reasoner",
"capabilities": {"answer_in_reasoning": True}},
{"name": "acme-plain", "base_url": "https://llm.example.com/v1"}, # same endpoint, no opt-in
{"name": "acme-int", "base_url": "https://int.example.com/v1", "capabilities": {"answer_in_reasoning": 1}}, # not a bool
]
@@ -191,6 +192,7 @@ def test_length_cut_reasoning_is_not_promoted(tmp_path, monkeypatch):
("custom", "https://llm.example.com/v1", "acme/after-model-switch", "private thoughts that must not be shown", 1),
("custom", "https://fallback.example.com/v1", "acme/reasoner", "the visible answer", 2),
(("custom", "custom:acme-plain"), "https://llm.example.com/v1", "acme/reasoner", "the visible answer", 2),
("custom:acme-int", "https://int.example.com/v1", "acme/reasoner", "the visible answer", 2),
])
def test_reasoning_promotion_requires_a_trusted_route(tmp_path, monkeypatch, provider, base_url, model, final, calls):
"""Private reasoning on an untrusted route retries to the visible answer and never