fix: replay canonical relay envelopes until terminal reply acknowledgement
This commit is contained in:
@@ -108,7 +108,7 @@ def test_resolve_ambiguous_handle_across_connections(root):
|
||||
# ── outbox / replies ─────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def test_enqueue_claim_is_atomic_and_single_shot(root):
|
||||
def test_enqueue_claim_replays_exact_identity_until_reply(root):
|
||||
bot_relay.write_remote_roster(root, _rows())
|
||||
roster = bot_relay.read_remote_roster(root)
|
||||
target = bot_relay.resolve_remote_target("researcher", roster)
|
||||
@@ -120,7 +120,9 @@ def test_enqueue_claim_is_atomic_and_single_shot(root):
|
||||
assert [e["id"] for e in claimed] == [env["id"]]
|
||||
assert claimed[0]["target_connection"] == "ssh-vps"
|
||||
assert claimed[0]["message"] == "hi"
|
||||
# second drain: nothing (no double delivery)
|
||||
# Reconnect replays the same admission identity, never a fresh turn.
|
||||
assert bot_relay.claim_pending_envelopes(root) == claimed
|
||||
bot_relay.write_reply(root, env['id'], reply='done')
|
||||
assert bot_relay.claim_pending_envelopes(root) == []
|
||||
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ def enqueue_envelope(root: Path | str, *, target: dict, message: str, sender_pro
|
||||
"Try again once that machine reconnects to the Desktop.")
|
||||
base = _ensure_dirs(root)
|
||||
envelope = {
|
||||
"id": uuid.uuid4().hex, "created_at": int(time.time()),
|
||||
"id": uuid.uuid4().hex, "created_at": int(time.time()), "canonical_delivery_v1": True,
|
||||
"from_profile": sender_profile, "from_handle": sender_handle,
|
||||
"target_connection": target["connection_id"], "target_profile": target["profile"],
|
||||
"target_handle": target["handle"], "message": message,
|
||||
@@ -265,6 +265,13 @@ def claim_pending_envelopes(root: Path | str) -> list[dict]:
|
||||
with contextlib.suppress(OSError, ValueError):
|
||||
os.replace(path, claimed) # atomic claim
|
||||
out.append(json.loads(claimed.read_text(encoding="utf-8")))
|
||||
seen = {row['id'] for row in out}
|
||||
for path in sorted((base / CLAIMED_DIR).glob('*.json')):
|
||||
with contextlib.suppress(OSError, ValueError):
|
||||
envelope = json.loads(path.read_text(encoding='utf-8'))
|
||||
if (envelope.get('canonical_delivery_v1') is True and envelope['id'] not in seen
|
||||
and not (base / REPLIES_DIR / path.name).exists()):
|
||||
out.append(envelope)
|
||||
return out
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user