Skip to content

Commit d2839b8

Browse files
Andrey Golovanovclaude
andcommitted
Handle backend errors gracefully, fix MSD volume/demand field
- Generation loop catches RuntimeError/OSError from backend (timeout, connection refused) and treats as iteration error instead of crashing - MSD compute_alpha_star reads 'volume' field (ngraph's key) with 'demand' as fallback for backward compatibility - MSD accepts 'msd' as step name in addition to 'msd_baseline' Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5c3a1cd commit d2839b8

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

metrics/msd.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ def to_jsonable(self) -> dict:
2222

2323

2424
def compute_alpha_star(results: dict) -> AlphaResult:
25-
msd = results.get("steps", {}).get("msd_baseline", {}).get("data", {}) or {}
25+
steps = results.get("steps", {})
26+
# Accept common MSD step names
27+
msd_step = steps.get("msd_baseline") or steps.get("msd") or {}
28+
msd = msd_step.get("data", {}) or {}
2629
alpha = msd.get("alpha_star", None)
2730
base_total = np.nan
2831
try:
2932
base_demands = msd.get("base_demands", [])
30-
base_total = float(sum([float(x.get("demand", 0.0)) for x in base_demands]))
33+
base_total = float(
34+
sum(float(x.get("volume", x.get("demand", 0.0))) for x in base_demands)
35+
)
3136
except Exception:
3237
base_total = np.nan
3338

netlab/autoresearch/generation_loop.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,16 @@ def run_generation_loop(
339339
validation_errors=validation_errors,
340340
)
341341

342-
response = backend.generate(prompt, system=_get_generation_system_prompt())
342+
try:
343+
response = backend.generate(
344+
prompt, system=_get_generation_system_prompt()
345+
)
346+
except (RuntimeError, OSError) as exc:
347+
last_inspect = InspectResult(
348+
success=False,
349+
errors=[f"LLM backend error: {exc}"],
350+
)
351+
continue
343352

344353
# Extract YAML from response
345354
yaml_text = _extract_yaml(response)

tests/autoresearch/test_infrastructure.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,13 @@ def test_metadata_lacks_baseline_flag(self, square_mesh_results: dict) -> None:
105105
assert "baseline" not in tm_meta or tm_meta.get("baseline") is not True
106106

107107
def test_compute_alpha_star_works(self, square_mesh_results: dict) -> None:
108-
"""compute_alpha_star extracts alpha_star but gets base_total_demand=0 due to key mismatch."""
108+
"""compute_alpha_star extracts alpha_star and base_total_demand."""
109109
from metrics.msd import compute_alpha_star
110110

111111
alpha = compute_alpha_star(square_mesh_results)
112112
assert alpha.alpha_star == 1.0
113-
# base_total_demand is 0.0 because compute_alpha_star looks for 'demand' key
114-
# but current ngraph uses 'volume'
115-
assert alpha.base_total_demand == 0.0
113+
# base_total_demand reads 'volume' field (ngraph's key) with 'demand' as fallback
114+
assert alpha.base_total_demand == 12.0
116115

117116

118117
class TestSampleTemplate:

0 commit comments

Comments
 (0)