The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: retain immutable Bot relay reply receipts on exact retry
Teknium391517b74b3a
diff --git a/tests/tools/test_bot_reply_receipt.py b/tests/tools/test_bot_reply_receipt.pynew file mode 100644index 00000000000..36e37f2270f--- /dev/null+++ b/tests/tools/test_bot_reply_receipt.py@@ -0,0 +1,15 @@+"""A relay reply is an immutable delivery receipt, not a last-writer-wins file."""+import json+import pytest+from tools.bot_relay import write_reply+++def test_relay_reply_retry_cannot_replace_a_settled_delivery(tmp_path):+ key = 'd' * 32+ path = write_reply(tmp_path, key, reply='original')+ before = path.read_bytes()+ assert write_reply(tmp_path, key, reply='original') == path+ assert path.read_bytes() == before+ with pytest.raises(ValueError, match='different'):+ write_reply(tmp_path, key, reply='replacement')+ assert json.loads(path.read_text())['reply'] == 'original'diff --git a/tools/bot_relay.py b/tools/bot_relay.pyindex 08b45fef256..a089707b608 100644--- a/tools/bot_relay.py+++ b/tools/bot_relay.py@@ -280,9 +280,16 @@ def write_reply(root: Path | str, envelope_id: str, *, reply: str = "", error: sfrom tools.bot_failure_reasons import classify_agent_errorcode = classify_agent_error(err)+ from tools.bot_live_delivery import _locked, _read, _writepath = base / REPLIES_DIR / f"{safe}.json"- _atomic_write_json(path, {"id": safe, "at": int(time.time()), "reply": str(reply or ""), "error": err, "reason": code},- prefix=".rep-")+ outcome = {"reply": str(reply or ""), "error": err, "reason": code}+ with _locked(root):+ existing = _read(path)+ if existing is not None:+ if any(existing.get(key) != value for key, value in outcome.items()):+ raise ValueError("delivery already has a different reply")+ return path+ _write(path, {"id": safe, "at": int(time.time()), **outcome})return path