Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions loopx/capabilities/manager_context/roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def _return_transaction(host, path, phase, request):
observed[field] = {key: observed[field][key] for key in keys if key in observed[field]}
result = effect_runtime_result("manager.return_delivery.transact", {
"schema_version": RETURN_DELIVERY_TRANSACTION,
"runtime_root": str(root.resolve()), "request_id": path.parent.name,
"runtime_root": str(root), "request_id": path.parent.name,
"result_key": path.stem, "phase": phase, "now": host["clock"]().isoformat(),
"exact": exact, "facts": observed, **payload,
}, retry_safe=False)
Expand Down Expand Up @@ -709,7 +709,7 @@ def _pending_return_paths(host, paths):
candidates = [{"request_id": path.parent.name, "result_key": path.stem} for path in batch]
selected = effect_runtime_result("manager.return_delivery.transact", {
"schema_version": RETURN_DELIVERY_TRANSACTION, "phase": "scan",
"runtime_root": str(root.resolve()), "now": scan_at.isoformat(), "exact": exact,
"runtime_root": str(root), "now": scan_at.isoformat(), "exact": exact,
"candidates": candidates,
})
if not isinstance(selected, dict) or selected.get("schema_version") != RETURN_DELIVERY_TRANSACTION:
Expand All @@ -726,6 +726,9 @@ def drain(root, registry, store, external_sender, *, now=None, cancelled=lambda:
if cancelled():
return 0

# Derive source paths and the typed transaction's root from one directory.
root = root.resolve()

def clock() -> datetime:
return datetime.now(timezone.utc) if now is None else now

Expand Down
10 changes: 8 additions & 2 deletions tests/test_manager_context_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def returned_history(flow):


@pytest.fixture
def returned_file_history(flow):
def returned_file_history(flow, request):
import os

if os.open not in os.supports_dir_fd or not hasattr(os, "O_NOFOLLOW"):
Expand All @@ -1252,12 +1252,18 @@ def __call__(self, *_):
return {"ok": True, "reply_verified": True}

sender = Sender()
assert drain(root, registry, store, sender) == 1
delivery_root = root
if getattr(request, "param", False):
delivery_root = root.with_name(f"{root.name}-alias")
delivery_root.symlink_to(root.resolve(), target_is_directory=True)
assert drain(delivery_root, registry, store, sender) == 1
assert sender.calls == 1
message = next(row for row in store.messages(session["session_id"]) if row.get("origin") == "manager_followup")
assert not message.get("attachments"), "Reproduce an existing delivered answer whose transcript lost its files"
return root, registry, store, session, turn, receipt, message, sources, sender


@pytest.mark.parametrize("returned_file_history", [False, True], indirect=True, ids=["direct", "runtime-alias"])
def test_existing_return_files_project_without_resending_or_rewriting(returned_file_history):
from loopx.capabilities.manager_context.roundtrip import read_chat_return_file

Expand Down
Loading