From fa02436daef6e90d0348a2530ffdbec47a23981b Mon Sep 17 00:00:00 2001 From: openhands Date: Sat, 6 Jun 2026 01:21:51 +0000 Subject: [PATCH 1/2] fix(critics): read instance_id from raw JSON in get_completed_instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit get_completed_instances() was calling EvalOutput.model_validate(data) on every line and silently dropping any line that failed validation. When a resume run loads a partial archive written by an older SDK (e.g. with browser tool/observation events whose pydantic discriminators no longer match current models), every completed row gets dropped — so _get_instances_for_attempt() thinks nothing has been completed and re-runs every selected instance from scratch. This is the root cause of evaluation#515. Read 'instance_id' directly from the parsed JSON dict instead. We do not need a fully-validated EvalOutput to decide whether an instance was already processed; we just need its id. Malformed JSON and rows missing instance_id are still skipped with a warning. get_failed_instances() legitimately needs the full EvalOutput model to hand to critic.evaluate(), so its behaviour is left unchanged — on a stale archive it will simply find zero failed instances, which combined with the now-correct completed set produces an empty retry list (the conservative "trust the prior completion" choice). Regression test asserts a JSONL with a mix of stale-schema rows, fresh rows, blank lines, malformed JSON, and rows missing instance_id is parsed correctly. The new test fails on main and passes with this fix. Co-authored-by: openhands --- benchmarks/utils/critics.py | 30 ++++++++++------ tests/test_iterative_resume.py | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 11 deletions(-) diff --git a/benchmarks/utils/critics.py b/benchmarks/utils/critics.py index fa9f9d923..b53cdd30a 100644 --- a/benchmarks/utils/critics.py +++ b/benchmarks/utils/critics.py @@ -150,11 +150,12 @@ def get_completed_instances(output_file: str) -> Set[EvalInstanceID]: Get all instance IDs present in output file (completed, regardless of success/failure). - Args: - output_file: Path to the JSONL output file - - Returns: - Set of instance IDs that were completed (processed) + Reads ``instance_id`` directly from each JSON line WITHOUT validating the + full ``EvalOutput`` model. Resume must recognise prior completion across + schema drift — e.g. archives written with an older SDK whose + tool/observation events no longer match current pydantic models — so a + stale archive still causes completed instances to be skipped instead of + silently being re-run from scratch. """ completed_instances: Set[EvalInstanceID] = set() @@ -164,19 +165,26 @@ def get_completed_instances(output_file: str) -> Set[EvalInstanceID]: try: with open(output_file, "r", encoding="utf-8") as f: for line_num, line in enumerate(f, 1): + stripped = line.strip() + if not stripped: + continue try: - data = json.loads(line.strip()) - output = EvalOutput.model_validate(data) - completed_instances.add(output.instance_id) - + data = json.loads(stripped) except json.JSONDecodeError as e: logger.warning( f"Invalid JSON on line {line_num} in {output_file}: {e}" ) - except Exception as e: + continue + + instance_id = ( + data.get("instance_id") if isinstance(data, dict) else None + ) + if not instance_id: logger.warning( - f"Error processing line {line_num} in {output_file}: {e}" + f"Missing 'instance_id' on line {line_num} in {output_file}" ) + continue + completed_instances.add(instance_id) except Exception as e: logger.warning(f"Error reading output file {output_file}: {e}") diff --git a/tests/test_iterative_resume.py b/tests/test_iterative_resume.py index 108f2dcb4..c8702dedc 100644 --- a/tests/test_iterative_resume.py +++ b/tests/test_iterative_resume.py @@ -443,3 +443,68 @@ def _make_output(instance_id, has_patch): assert result_ids == {"D"}, ( f"Expected to retry only D (failed in attempt 2), but got: {result_ids}" ) + + +def test_get_completed_instances_tolerates_stale_archive_schema(): + """ + Resume must skip instances that were completed by an older SDK whose + EvalOutput schema has since drifted (e.g. browser tool/observation + events whose pydantic discriminators no longer match current models). + + Reading instance_id from raw JSON avoids treating those rows as + "never completed" and re-running them from scratch. Regression test + for evaluation#515. + """ + from benchmarks.utils.critics import get_completed_instances + + with tempfile.TemporaryDirectory() as tmpdir: + path = os.path.join(tmpdir, "output.critic_attempt_1.jsonl") + with open(path, "w") as f: + # 1) Stale row: has instance_id but a history event with a + # discriminator value the current SDK no longer knows about. + # EvalOutput.model_validate would raise on this; raw JSON + # parsing must not. + stale = { + "instance_id": "instance_stale", + "instruction": "old instruction", + "instance": {"x": 1}, + "test_result": {"git_patch": "old patch"}, + "error": None, + "history": [ + { + "kind": "BrowserNavigateTool", + "tool_name": "browser", + "args": {"url": "https://example.com"}, + } + ], + } + f.write(json.dumps(stale) + "\n") + + # 2) Fresh row written via current EvalOutput model. Must also + # still be detected. + fresh = EvalOutput( + instance_id="instance_fresh", + test_result={"git_patch": "p"}, + instruction="i", + error=None, + history=[], + instance={"x": 2}, + ) + f.write(fresh.model_dump_json() + "\n") + + # 3) Blank line: must be tolerated, not counted. + f.write("\n") + + # 4) Malformed JSON: must be skipped with a warning, not raise. + f.write("{not valid json}\n") + + # 5) JSON object missing instance_id: must be skipped. + f.write(json.dumps({"foo": "bar"}) + "\n") + + completed = get_completed_instances(path) + + assert completed == {"instance_stale", "instance_fresh"}, ( + f"Expected both stale-schema and fresh rows to be recognised as " + f"completed, got: {completed}" + ) + From cf3617c9a122e8887f336eee214976287f7c330d Mon Sep 17 00:00:00 2001 From: openhands Date: Sat, 6 Jun 2026 04:48:38 +0000 Subject: [PATCH 2/2] fix: remove trailing blank line in test_iterative_resume.py (ruff format) Co-authored-by: openhands --- tests/test_iterative_resume.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_iterative_resume.py b/tests/test_iterative_resume.py index c8702dedc..d9358fc86 100644 --- a/tests/test_iterative_resume.py +++ b/tests/test_iterative_resume.py @@ -507,4 +507,3 @@ def test_get_completed_instances_tolerates_stale_archive_schema(): f"Expected both stale-schema and fresh rows to be recognised as " f"completed, got: {completed}" ) -