Skip to content

Commit 0246cae

Browse files
committed
fix(eval): ignore non-positive recorded attempt numbers
A corrupt-but-valid-JSON cell.json marker (attempt -1 or 0) would lower the high-water mark and produce attempt-000, violating the 1-based numbering contract. Only positive integers count.
1 parent a7f4b84 commit 0246cae

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/brigade/model_trials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def _attempt_number(cell_dir: Path) -> int:
342342
)
343343
recorded = _load_json(cell_dir / "cell.json") or {}
344344
prior = recorded.get("attempt")
345-
if isinstance(prior, int) and not isinstance(prior, bool):
345+
if isinstance(prior, int) and not isinstance(prior, bool) and prior > 0:
346346
numbers.append(prior)
347347
return max(numbers, default=0) + 1
348348

tests/test_model_trials.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ def test_attempt_number_counts_running_marker_without_attempt_dir(tmp_path):
9797
assert model_trials._attempt_number(tmp_path) == 2
9898

9999

100+
def test_attempt_number_ignores_nonpositive_recorded_attempt(tmp_path):
101+
# Corrupt-but-valid-JSON markers must not produce attempt-000.
102+
(tmp_path / "cell.json").write_text(json.dumps({"state": "running", "attempt": -1}))
103+
assert model_trials._attempt_number(tmp_path) == 1
104+
(tmp_path / "cell.json").write_text(json.dumps({"state": "running", "attempt": 0}))
105+
assert model_trials._attempt_number(tmp_path) == 1
106+
107+
100108
def test_expand_cells_is_stable_and_conditions_change_identity():
101109
first = model_trials.expand_cells(_manifest(), _roster())
102110
second = model_trials.expand_cells(_manifest(), _roster())

0 commit comments

Comments
 (0)