From c84fcdcdd554be06bfe26cc435b32e128fbd0c8b Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Thu, 29 Oct 2026 01:39:10 +0100 Subject: [PATCH] e2e: long_session.py refuses an empty corpus, records the corpus digest and fails when the last turn is shorter than 200k tokens The owner's cleanup removed the source directory of the 245k session; the run then streamed 73-306 token prompts and looked healthy. Exit 2: no usable file. Exit 3: final-turn input_tokens < --min-final-tokens (default 200000, 0 disables). corpus.sha256 (file list with per-file digests, char count) is written next to long-session.json. Co-Authored-By: Claude Sonnet 5.5 --- scripts/e2e/long_session.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/e2e/long_session.py b/scripts/e2e/long_session.py index c47debf2..0ecee338 100644 --- a/scripts/e2e/long_session.py +++ b/scripts/e2e/long_session.py @@ -110,11 +110,27 @@ def main(): ap.add_argument("--turns", type=int, default=5) ap.add_argument("--target-tokens", type=int, default=215000) ap.add_argument("--max-output", type=int, default=700) + ap.add_argument("--min-final-tokens", type=int, default=200000, help="exit 3 when the last turn's prompt is shorter (0: no check)") ap.add_argument("--context", type=int, default=262144, help="the engine's context; the last turn is cut to fit under it") a = ap.parse_args() base, model, key = os.environ["E2E_BASE_URL"], os.environ["E2E_MODEL"], os.environ["E2E_API_KEY"] out_dir = os.environ.get("E2E_OUT_DIR", ".") files = collect(a.src) + # Guard (STRA-245): a source directory that vanished or holds no usable file made a "245k" session of a few hundred tokens and the run looked fine. + if not files: + print("long_session: --src %s yields no .rs file larger than 1500 bytes; refusing to run an empty session" % a.src, file=sys.stderr) + return 2 + corpus = hashlib.sha256() + total_chars = 0 + for path in files: + with open(path, "rb") as f: + data = f.read() + corpus.update(os.path.relpath(path, a.src).replace("\\", "/").encode() + b"\x00" + hashlib.sha256(data).digest()) + total_chars += len(data) + digest = corpus.hexdigest() + print("long_session: corpus %s: %d files, %d chars, sha256 %s" % (a.src, len(files), total_chars, digest), file=sys.stderr, flush=True) + with open(os.path.join(out_dir, "corpus.sha256"), "w") as f: + f.write("src=%s files=%d chars=%d sha256=%s\n" % (a.src, len(files), total_chars, digest)) items, results, pos = [], [], 0 chars_per_token = 3.3 per_turn = a.target_tokens // a.turns @@ -137,7 +153,13 @@ def main(): items.append({"role": "assistant", "content": [{"type": "output_text", "text": reply}]}) with open(os.path.join(out_dir, "long-session.json"), "w") as f: json.dump(results, f, indent=1) - return 0 if all("error" not in r for r in results) else 1 + if any("error" in r for r in results): + return 1 + final = (results[-1].get("input_tokens") or 0) if results else 0 + if final < a.min_final_tokens: + print("long_session: the final turn had %d input tokens, fewer than --min-final-tokens %d: this is not the long session it is meant to be (short corpus?)" % (final, a.min_final_tokens), file=sys.stderr) + return 3 + return 0 if __name__ == "__main__":