Skip to content

The agent that grows with you

fix: unlink the dm plaintext file too once a live delivery settled

teknium114bd358f5e92
diff --git a/tests/tools/test_bot_mode_dm.py b/tests/tools/test_bot_mode_dm.py
index ebbcb70cfe4..755ea800a63 100644
--- a/tests/tools/test_bot_mode_dm.py
+++ b/tests/tools/test_bot_mode_dm.py
@@ -961,14 +961,18 @@ def test_cleanup_sweeps_stale_live_intents_and_keeps_fresh_ones(tmp_path, monkey
def test_settled_live_wait_unlinks_the_intent_but_a_pending_one_keeps_it(tmp_path, monkeypatch, capsys):
from tools import bot_live_delivery as live
+ dm_file = tmp_path / "dm-x.txt"
+ dm_file.write_text("secret plaintext", encoding="utf-8")
intent = tmp_path / "dm-x.txt.live.json"
intent.write_text("{}", encoding="utf-8")
monkeypatch.setattr(bot_mode_dm, "_LIVE_WAIT_SECONDS", 0)
monkeypatch.setattr(live, "read_delivery_result", lambda home, did: {"status": "queued"})
- assert bot_mode_dm._wait_live_dm(str(tmp_path), "d1", intent_path=intent) == 0
+ assert bot_mode_dm._wait_live_dm(str(tmp_path), "d1", dm_file=dm_file) == 0
assert intent.exists(), "a pending delivery may still be retried from the same intent"
+ assert dm_file.exists()
monkeypatch.setattr(live, "read_delivery_result", lambda home, did: {"status": "settled", "reply": "ok"})
- assert bot_mode_dm._wait_live_dm(str(tmp_path), "d1", intent_path=intent) == 0
+ assert bot_mode_dm._wait_live_dm(str(tmp_path), "d1", dm_file=dm_file) == 0
assert not intent.exists()
+ assert not dm_file.exists(), "the dm .txt holds the same plaintext as the settled intent"
diff --git a/tools/bot_mode_dm.py b/tools/bot_mode_dm.py
index 993b2b2c75f..a1f8dee179b 100644
--- a/tools/bot_mode_dm.py
+++ b/tools/bot_mode_dm.py
@@ -458,7 +458,7 @@ def _admit_live_dm(profile_home: Path | None, dm_file: str, author: Optional[dic
return record
-def _wait_live_dm(home: str, delivery_id: str, *, intent_path: "str | os.PathLike | None" = None) -> int:
+def _wait_live_dm(home: str, delivery_id: str, *, dm_file: "str | os.PathLike | None" = None) -> int:
from tools.bot_live_delivery import read_delivery_result
deadline = time.monotonic() + _LIVE_WAIT_SECONDS
@@ -472,10 +472,12 @@ def _wait_live_dm(home: str, delivery_id: str, *, intent_path: "str | os.PathLik
payload.update(status=status, delivery_id=delivery_id)
if status in ("queued", "claimed", "ambiguous"):
payload["detail"] = "Delivery remains pending or its outcome is unknown. Do not resend; receipt is retained."
- elif status == "settled" and intent_path is not None:
+ elif status == "settled" and dm_file is not None:
# The intent carries the message plaintext so a retry can replay the SAME delivery id;
- # once the owner settled it nothing retries, so it goes the way the dm file does.
- _unlink_dm_file(str(intent_path))
+ # once the owner settled it nothing retries, so it goes along with the dm file (same
+ # plaintext) — the live branch returns before _run_delivery's own unlink.
+ _unlink_dm_file(str(dm_file) + ".live.json")
+ _unlink_dm_file(str(dm_file))
print(json.dumps(payload))
return 0 if status in ("settled", "queued", "claimed") else 1
@@ -516,7 +518,7 @@ def _run_delivery(argv: list[str], dm_file: str, *, stdin_file: bool,
"evidence_file": dm_file}))
return 1
if record is not None:
- return _wait_live_dm(record["profile_home"], record["delivery_id"], intent_path=dm_file + ".live.json")
+ return _wait_live_dm(record["profile_home"], record["delivery_id"], dm_file=dm_file)
try:
from tools.bot_relay import delivery_env