Skip to content

Fast local LLM inference on plain CPUs. No GPU, 8 GB of RAM. OpenAI-compatible server.

fix(bench): exclude failed replay steps from identity comparisons (#111)

Afloatb97def4c22ac
diff --git a/bench/analyze.py b/bench/analyze.py
index bc696a5..71705ff 100644
--- a/bench/analyze.py
+++ b/bench/analyze.py
@@ -339,7 +339,10 @@ def replay():
r = S[a].get(k)
cells.append(f"{r['prompt_n']} / {r['wall_s']}" if r and r.get("wall_s") else ("died" if r else "–"))
print(f"| {k[1]} | {n} | " + " | ".join(cells) + " |")
- ok = lambda a, k: k in S[a] and S[a][k].get("wall_s")
+ def successful(a, k):
+ r = S[a].get(k)
+ return r is not None and not r.get("error") and r.get("wall_s") is not None
+ ok = lambda a, k: successful(a, k) and S[a][k]["wall_s"] > 0
if "ours" in S:
print()
print("| arm | steps (paired with ours) | sum wall s | s per step | ours, same steps | arm / ours (sum) | per-step ratio, steps ≥ 1: median [min, max] |")
@@ -360,10 +363,13 @@ def replay():
if a.startswith("prev") and x:
flag(f"agent step seconds vs {a} (prev/new)", b, x)
OUT.setdefault("replay", {}).setdefault(b, {})["_tot"] = tot
- full = [k for k in steps if k in S["ours"] and S["ours"][k].get("wall_s")]
- print(f"- ours over all {len(full)} steps: {sum(S['ours'][k]['wall_s'] for k in full):.0f} s, "
- f"{sum(S['ours'][k]['wall_s'] for k in full)/len(full):.0f} s/step; prompt tokens read "
- f"{sum(S['ours'][k]['prompt_n'] or 0 for k in full if k[1] >= 1)} over steps 1–{full[-1][1]}")
+ full = [k for k in steps if successful("ours", k)]
+ if full:
+ print(f"- ours over all {len(full)} steps: {sum(S['ours'][k]['wall_s'] for k in full):.0f} s, "
+ f"{sum(S['ours'][k]['wall_s'] for k in full)/len(full):.0f} s/step; prompt tokens read "
+ f"{sum(S['ours'][k]['prompt_n'] or 0 for k in full if k[1] >= 1)} over steps 1–{full[-1][1]}")
+ else:
+ print("- ours: no successful replay steps.")
acc = [(S["ours"][k].get("draft_n") or 0, S["ours"][k].get("draft_n_accepted") or 0) for k in full]
if sum(d for d, _ in acc):
print(f"- draft acceptance on the replay (ours): {sum(a for _, a in acc) / sum(d for d, _ in acc):.2f}")
@@ -372,7 +378,9 @@ def replay():
base = "ours" if other == "ours_nr" else "ours_ns"
if base not in S:
continue
- ks = [k for k in S[base] if k in S[other]]
+ ks = [k for k in S[base] if successful(base, k) and successful(other, k)]
+ if not ks:
+ continue
same = sum(1 for k in ks if S[base][k]["text"] == S[other][k]["text"] and S[base][k]["tool_calls"] == S[other][k]["tool_calls"])
print(f"- identity {base} (resume) vs {other} (`--no-resume`): **{same}/{len(ks)}** requests byte-identical (content + tool calls)")
OUT.setdefault("ident", {})[f"replay {b} {base} vs {other}"] = (same, len(ks))
diff --git a/bench/test_replay_analysis_failures.py b/bench/test_replay_analysis_failures.py
new file mode 100644
index 0000000..1b92859
--- /dev/null
+++ b/bench/test_replay_analysis_failures.py
@@ -0,0 +1,60 @@
+import contextlib
+import io
+import json
+from pathlib import Path
+import tempfile
+import unittest
+from unittest.mock import patch
+
+import analyze
+
+
+def row(step, text, error=None):
+ return {'step': step, 'session': 1, 'n_prompt': 8, 'prompt_n': None if error else 8,
+ 'wall_s': None if error else 1., 'text': text, 'tool_calls': [], 'error': error}
+
+
+class ReplayAnalysisFailureTest(unittest.TestCase):
+ def analyze(self, ours, no_resume):
+ with tempfile.TemporaryDirectory() as directory:
+ output = Path(directory) / 'e2/replay'
+ output.mkdir(parents=True)
+ for name, rows in [('ours', ours), ('ours_nr', no_resume)]:
+ (output / f'steps_{name}.jsonl').write_text(''.join(json.dumps(r) + '\n' for r in rows))
+ stdout = io.StringIO()
+ with patch.object(analyze, 'RAW', directory), patch.object(analyze, 'OUT', {}), \
+ contextlib.redirect_stdout(stdout):
+ analyze.replay()
+ headline = dict(analyze.OUT)
+ return stdout.getvalue(), headline
+
+ def test_two_failed_requests_are_not_identical_answers(self):
+ failed = row(1, '', 'connection lost')
+ text, headline = self.analyze([row(0, 'A'), failed], [row(0, 'B'), failed])
+ self.assertEqual(headline['ident']['replay e2 ours vs ours_nr'], (0, 1))
+ self.assertIn('**0/1** requests byte-identical', text)
+ self.assertIn('died', text)
+
+ def test_all_failed_run_has_no_identity_claim_and_does_not_crash(self):
+ failed = row(0, '', 'connection lost')
+ text, headline = self.analyze([failed], [failed])
+ self.assertIn('no successful replay steps', text)
+ self.assertNotIn('requests byte-identical', text)
+ self.assertNotIn('ident', headline)
+
+ def test_successful_pairs_keep_original_identity_and_timing(self):
+ text, headline = self.analyze([row(0, 'same'), row(1, 'A')],
+ [row(0, 'same'), row(1, 'B')])
+ self.assertEqual(headline['ident']['replay e2 ours vs ours_nr'], (1, 2))
+ self.assertEqual(headline['replay']['e2']['ours_nr']['steps'], 2)
+ self.assertIn('over all 2 steps', text)
+
+ def test_rounded_zero_duration_still_has_a_valid_answer(self):
+ completed = dict(row(0, 'same'), wall_s=0.)
+ text, headline = self.analyze([completed], [completed])
+ self.assertEqual(headline['ident']['replay e2 ours vs ours_nr'], (1, 1))
+ self.assertIn('over all 1 steps', text)
+
+
+if __name__ == '__main__':
+ unittest.main()