diff --git a/src/openenv/core/harness/capture/validate.py b/src/openenv/core/harness/capture/validate.py index 6569300e32..f3df4e2b02 100644 --- a/src/openenv/core/harness/capture/validate.py +++ b/src/openenv/core/harness/capture/validate.py @@ -408,7 +408,17 @@ def check_upstream_response(payload: dict[str, Any]) -> Report: "logprob_misalign", f"{len(content)} logprobs vs {len(choice['token_ids'])} token ids", ) - token = (content[0] or {}).get("token", "") + if any( + not isinstance(entry, dict) or entry.get("logprob") is None + for entry in content + ): + report.add( + FATAL, + "missing_sampled_logprob", + "At least one logprobs.content entry lacks a sampled token logprob.", + ) + return report + token = content[0].get("token", "") if not str(token).startswith("token_id:"): # This says more than it looks like it says, and the mild reading of it is what makes the # failure silent. diff --git a/tests/envs/test_harbor_capture_level.py b/tests/envs/test_harbor_capture_level.py index 763ff7a4f0..ddfd4fe56f 100644 --- a/tests/envs/test_harbor_capture_level.py +++ b/tests/envs/test_harbor_capture_level.py @@ -106,6 +106,20 @@ def test_a_full_capture_engine_is_trainable(monkeypatch): assert report.param_fixes == [] +@pytest.mark.parametrize( + "logprob_entry", [{"logprob": None}, {}], ids=["null", "absent"] +) +def test_a_missing_sampled_logprob_prevents_training(monkeypatch, logprob_entry): + payload = reply(prompt_ids=[1, 2], token_ids=[7, 8], logprobs=[-0.1, -0.2]) + payload["choices"][0]["logprobs"]["content"][1] = logprob_entry.copy() + + report, _ = probe(monkeypatch, [payload]) + + assert report.reachable and not report.trainable + assert report.rollout_type == "eval" + assert any("missing_sampled_logprob" in finding for finding in report.findings) + + def test_token_ids_returned_as_null_land_on_the_logprobs_level(monkeypatch): """The HF router's shape: it accepts `return_token_ids` and answers `token_ids: null`. The level must come from what came back, not from the request having been accepted."""