Skip to content

Commit d89d997

Browse files
committed
fix(eval_optimize_loop): address AI review round 12 — 1 critical + 3 warning + 1 suggestion
Critical: - run_pipeline.py: _sys.stderr -> sys.stderr in _read_critical_case_ids except branch (NameError would crash pipeline on evalset read failure) Warning: - run_pipeline.py: add FileExistsError to lock rebuild except clause to handle race between stale-lock removal and O_EXCL recreation - gate.py: baseline_cost <= 0 now returns explicit skip message instead of silently auto-passing cost gate (fake mode has simulated costs) - baseline.py: remove unused import time Suggestion: - run_pipeline.py: document overfit_detection caveat in fake mode (flat +0.05 delta makes train_improved always true) 99 tests pass, pipeline 6 phases run end-to-end.
1 parent 78b75eb commit d89d997

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

examples/optimization/eval_optimize_loop/run_pipeline.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _read_critical_case_ids(val_path: Path) -> list[str]:
3535
data = json.load(f)
3636
return [c["case_id"] for c in data.get("cases", []) if c.get("critical", False)]
3737
except Exception as e:
38-
print(f"Warning: cannot read critical case ids from {val_path}: {e}", file=_sys.stderr)
38+
print(f"Warning: cannot read critical case ids from {val_path}: {e}", file=sys.stderr)
3939
return [] # empty: skip critical-case gate rather than guess wrong id
4040

4141

@@ -122,7 +122,7 @@ def _pid_alive(pid):
122122
lf.flush()
123123
_os.fsync(lf.fileno())
124124
acquired = True
125-
except (FileNotFoundError, ValueError):
125+
except (FileNotFoundError, ValueError, FileExistsError):
126126
pass
127127

128128
if not acquired:
@@ -174,6 +174,12 @@ def _pid_alive(pid):
174174
# are simulated placeholder values. Gate decisions in fake mode are for
175175
# pipeline demo purposes only and do not reflect real optimization outcomes.
176176
# Real mode would re-evaluate with the optimized agent on the training set.
177+
#
178+
# Overfit detection caveat: candidate_train_scores uses a flat +0.05 delta
179+
# which makes train_improved always true in fake mode. This means
180+
# overfit_detection degenerates to "reject iff val regresses" and is NOT
181+
# a genuine overfit signal. In real mode, train scores come from actual
182+
# re-evaluation with the optimized prompt.
177183
# overfit detection: simulate candidate train scores with +0.05 delta
178184
candidate_train_scores = {
179185
cid: min(1.0, score + 0.05) for cid, score in train_bl.score_map.items()

examples/optimization/eval_optimize_loop/src/baseline.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from __future__ import annotations
1717

1818
import json
19-
import time
2019
from dataclasses import dataclass, field
2120
import hashlib
2221
from pathlib import Path

examples/optimization/eval_optimize_loop/src/gate.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,15 @@ def _check_cost(
196196
) -> GateCheck:
197197
max_ratio = self.rules["cost_within_budget"].get("max_cost_ratio", 1.2)
198198
if baseline_cost <= 0:
199-
passed = True
200-
ratio = 1.0
199+
# Fake mode: costs are simulated placeholders (see run_pipeline.py L173-176).
200+
# Real mode: cost may be 0 if token_tracker is not connected.
201+
# In either case, cost data is absent; skip this gate rather than auto-pass.
202+
return GateCheck(
203+
name="cost_within_budget",
204+
passed=True,
205+
description=f"cost budget skipped (baseline_cost={baseline_cost:.4f} <= 0, tracking inactive)",
206+
detail="cost data unavailable; gate skipped",
207+
)
201208
else:
202209
ratio = candidate_cost / baseline_cost
203210
passed = ratio <= max_ratio

0 commit comments

Comments
 (0)