Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

gateway: an archive of a turn's changed files is refused with the names when one cannot be read (#554)

Rudy Mizrahi Celekli0be68810a218
diff --git a/gateway/app.py b/gateway/app.py
index 8fddb2e5..042ca1ce 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -11779,13 +11779,24 @@ async def session_files_archive(sid: str, request: Request, changed: bool = Fals
items = ((json.loads(blob) or {}).get("files") or []) if blob else []
except Exception: # noqa: BLE001
items = []
+ # "All" means all here too: the changed set is a named list of files, so one of
+ # them that cannot be read is refused with the names, not dropped from a zip
+ # handed over as if it held the whole turn's output.
+ gone: list[str] = []
+ asked = 0
for it in items[:200]:
fid, path = it.get("file_id"), it.get("path")
if not (fid and path):
continue
+ asked += 1
got = await _container_file_bytes(sid, fid)
- if got:
- _add_bytes(path, got[0])
+ if got is None:
+ gone.append(path)
+ continue
+ _add_bytes(path, got[0])
+ if gone:
+ raise HTTPException(404, f"{len(gone)} of {asked} files are no longer available: "
+ + ", ".join(gone[:5]) + (", …" if len(gone) > 5 else ""))
else:
tf = await _workspace_tar(sid)
if tf is None:
diff --git a/gateway/tests/test_files_archive.py b/gateway/tests/test_files_archive.py
index 221b3815..caf1075d 100644
--- a/gateway/tests/test_files_archive.py
+++ b/gateway/tests/test_files_archive.py
@@ -1,6 +1,7 @@
"""The archive of a turn's cited files keeps the workspace's folders, keeps two files that share a
basename, and is refused with the names when a cited file is no longer there: "all" means all."""
import io
+import json
import zipfile
from fastapi.testclient import TestClient
@@ -53,3 +54,27 @@ def test_the_single_download_names_the_file_without_its_folder(monkeypatch):
assert r.status_code == 200
assert r.headers["content-disposition"] == (
'attachment; filename="notes.txt"; filename*=UTF-8\'\'notes.txt')
+
+
+def _wire_changed(monkeypatch, tmp_path, files: dict[str, bytes | None]):
+ _wire(monkeypatch, tmp_path, files)
+
+ async def blob_get(key, kb=None):
+ return json.dumps(
+ {"files": [{"file_id": gw._wf_id(p), "path": p} for p in files]}).encode()
+ monkeypatch.setattr(gw, "_blob_get", blob_get)
+
+
+def test_an_unreadable_changed_file_refuses_the_archive_by_name(monkeypatch, tmp_path):
+ _wire_changed(monkeypatch, tmp_path, {"report.pdf": b"ok", "output/gone.json": None})
+ r = TestClient(gw.app).get("/v1/sessions/s1/files/archive?changed=true")
+ assert r.status_code == 404
+ assert "1 of 2 files" in r.text and "output/gone.json" in r.text
+
+
+def test_a_readable_changed_set_still_archives_every_file(monkeypatch, tmp_path):
+ _wire_changed(monkeypatch, tmp_path, {"report.pdf": b"ok", "output/notes.txt": b"n"})
+ r = TestClient(gw.app).get("/v1/sessions/s1/files/archive?changed=true")
+ assert r.status_code == 200
+ assert sorted(zipfile.ZipFile(io.BytesIO(r.content)).namelist()) == [
+ "output/notes.txt", "report.pdf"]