From 5c68a1b1b7ab2fc8117a8916b7dfec464dde1f47 Mon Sep 17 00:00:00 2001 From: Kral Date: Sun, 4 Oct 2026 07:59:28 +0200 Subject: [PATCH] Loop guard: also identical call with identical result 3 times in a row; baseline restarts (run base 20500) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat --- harness/agents.py | 7 +++++-- harness/proxy.py | 7 +++++++ train/README.md | 2 +- train/baseline_chain.sh | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/harness/agents.py b/harness/agents.py index afb7d4c..9d50524 100644 --- a/harness/agents.py +++ b/harness/agents.py @@ -156,8 +156,11 @@ class LlmAgent: err, text = proxy.call(fn["name"], args) messages.append({"role": "tool", "tool_call_id": c.get("id", ""), "content": ("ERROR: " if err else "") + text[:12000]}) - if self.loop_guard and proxy.same_push_streak >= self.loop_guard: - final = f"Stopped: loop (the same source was pushed {proxy.same_push_streak} times in a row)." + streak = max(proxy.same_push_streak, proxy.same_call_streak) + if self.loop_guard and streak >= self.loop_guard: + final = (f"Stopped: loop (the same source was pushed {proxy.same_push_streak} times in a row)." + if proxy.same_push_streak >= self.loop_guard else + f"Stopped: loop (the same call with the same result {proxy.same_call_streak} times in a row).") self.end_reason = "loop" break if self.end_reason == "loop": diff --git a/harness/proxy.py b/harness/proxy.py index 27fc4e4..786b601 100644 --- a/harness/proxy.py +++ b/harness/proxy.py @@ -71,6 +71,8 @@ class ToolProxy: self.activation_errors = [] # unique error messages of failed writes self.same_push_streak = 0 # identical sap_push_source (object + source hash) in a row self._last_push = None + self.same_call_streak = 0 # identical call (tool, arguments and result) in a row, any tool + self._last_call = None self.log = open(log_path, "a") self.adt = None self.fallbacks = [] # writes that needed the ADT activation fallback @@ -171,6 +173,11 @@ class ToolProxy: for m in activation_messages(text, err): if m not in self.activation_errors and len(self.activation_errors) < 30: self.activation_errors.append(m) + if tool in MODEL_TOOLS and not result[1].startswith("Tool "): + ck = (tool, hashlib.md5(json.dumps(args, sort_keys=True).encode()).hexdigest(), + hashlib.md5(result[1].encode()).hexdigest()) + self.same_call_streak = self.same_call_streak + 1 if ck == self._last_call else 1 + self._last_call = ck entry["is_error"], entry["result"] = result[0], result[1][:20000] self.log.write(json.dumps(entry) + "\n") self.log.flush() diff --git a/train/README.md b/train/README.md index ec0d268..7f842a2 100644 --- a/train/README.md +++ b/train/README.md @@ -57,7 +57,7 @@ G0139, G0151, G0157, G0174, G0167, G0185. Use the same list before and after tra | temperature / top_p / top_k / min_p | 0.2 / 0.95 / 20 / 0 | | max_tokens per turn | **16384**, sent in each request by `train/baseline.py` (`MAX_TOKENS`); the server limit stays 32768 | | Tool-call budget per task | 60 calls, 15 activations (T01 too) | -| Loop guard | `loop_guard` 3: the run ends when `sap_push_source` pushes the same source (object + md5) 3 times in a row; final report "Stopped: loop ...", `end_reason` "loop". Scores use the final state, so they do not change. Same after training. T01 of the first run (started before the guard) ran without it | +| Loop guard | `loop_guard` 3: the run ends when `sap_push_source` pushes the same source (object + md5) 3 times in a row, or when any tool is called 3 times in a row with the same arguments and the same result (read loop, e.g. G0105 pulled the same include 18 times); final report "Stopped: loop ...", `end_reason` "loop". Scores use the final state, so they do not change. Same after training. T01 of the first run (started before the guard) ran without it | | Per run record | `end_reason` (report, loop, empty_response, tool_budget, time_budget, model_error, max_turns), `activation_failures`, `activation_error_messages` (unique), also in `baseline.json` | | Empty turn | retried (2 times), then the run stops ("Stopped: empty model response") | | Docker (A4H) | VM memory 36 GB (`MemoryMiB` 36864), container `--memory 32g --memory-swap 32g` (2026-10-04) | diff --git a/train/baseline_chain.sh b/train/baseline_chain.sh index c4318ce..f8b8484 100755 --- a/train/baseline_chain.sh +++ b/train/baseline_chain.sh @@ -4,7 +4,7 @@ cd "$(dirname "$0")/.." log() { echo "$(date '+%F %T') $*"; } log "start baseline, 11 tasks, thinking off, max_tokens 16384, loop guard 3" -python3 train/baseline.py --label baseline --run-base 20400 > runs/stage1/baseline.log 2>&1 & +python3 train/baseline.py --label baseline --run-base 20500 > runs/stage1/baseline.log 2>&1 & BP=$! log "baseline PID $BP" NOTE=0