Skip to content

The agent that grows with you

fix: keep a retried Bot DM intent ambiguous on a pre-dial death

Teknium455ce747d9ef
diff --git a/tests/tools/test_bot_live_owner_delivery.py b/tests/tools/test_bot_live_owner_delivery.py
index 1191f386e01..cb8e25e2bcd 100644
--- a/tests/tools/test_bot_live_owner_delivery.py
+++ b/tests/tools/test_bot_live_owner_delivery.py
@@ -368,3 +368,23 @@ def test_pre_dial_failure_is_a_definite_no_send_not_ambiguous(tmp_path, monkeypa
dm_file = Path(dm_files[0])
assert not dm_file.exists() # nothing was admitted: no evidence to retain
assert not Path(str(dm_file) + ".live.json").exists() # the pinned intent can never settle
+
+
+def test_pre_dial_failure_on_a_retried_intent_stays_ambiguous(tmp_path, monkeypatch):
+ """An intent pinned by an earlier attempt may already be admitted: a later pre-dial death
+ proves nothing about that attempt, so the outcome stays unknown and the evidence is kept."""
+ from tools import bot_live_delivery as live
+ from tools import bot_mode_dm
+
+ def refused(home, params):
+ raise live.PreDialError("dial refused before the RPC went out")
+
+ dm_file = bot_mode_dm._write_dm_file("hello")
+ intent = Path(bot_mode_dm._live_intent_file(dm_file))
+ intent.write_text(json.dumps(dict(owner=_owner(tmp_path), message="hello",
+ delivery_id=bot_mode_dm._dm_delivery_id(dm_file))), encoding="utf-8")
+ monkeypatch.setattr(live, "authority_delivery", refused)
+
+ with pytest.raises(live.PreDialError):
+ bot_mode_dm._admit_live_dm(None, dm_file)
+ assert intent.exists() and Path(dm_file).exists()
diff --git a/tools/bot_mode_dm.py b/tools/bot_mode_dm.py
index 30258e6f131..a8d7e0112ee 100644
--- a/tools/bot_mode_dm.py
+++ b/tools/bot_mode_dm.py
@@ -491,6 +491,7 @@ def _admit_live_dm(profile_home: Path | None, dm_file: str, author: Optional[dic
intent: dict[str, Any]
intent_path = Path(_live_intent_file(dm_file))
+ pinned_now = False
if intent_path.exists():
intent = json.loads(intent_path.read_text(encoding="utf-8-sig"))
else:
@@ -515,6 +516,7 @@ def _admit_live_dm(profile_home: Path | None, dm_file: str, author: Optional[dic
stream.flush()
os.fsync(stream.fileno())
fsync_directory(intent_path.parent)
+ pinned_now = True
home = intent["owner"]["profile_home"]
record = read_delivery_result(home, intent["delivery_id"])
if record is None or intent["owner"].get("canonical"):
@@ -532,9 +534,10 @@ def _admit_live_dm(profile_home: Path | None, dm_file: str, author: Optional[dic
# may have admitted since: only the owner's settle decides, under that same lock.
record = settle_held_delivery(home, intent["owner"], intent["message"], **identity)
except PreDialError as exc:
- # The dial died before bot_relay.deliver reached the socket: nothing was admitted
- # and this intent can never settle, so drop it and report the definite no-send
- # the sender may retry (#139303).
+ if not pinned_now:
+ raise # an earlier attempt under this intent may have admitted: outcome unknown
+ # This call pinned the intent and its first dial died before the RPC went out: nothing
+ # was admitted anywhere, so it is a definite no-send the sender may retry (#139303).
_unlink_dm_file(_live_intent_file(dm_file))
raise LiveTargetUnavailableError(f"live authority dial failed before admission ({exc})") from exc
if _held_disposition(record):