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.

Produced files: the record says how many the turn produced; dotfiles keep their names (#274)

github-actions[bot]ab427f2b8f7f
diff --git a/gateway/app.py b/gateway/app.py
index 488e7356..4e1bdd03 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -6888,6 +6888,22 @@ def _is_internal_output(name: str) -> bool:
# ── output (container) file collection: produced-this-turn files → blobs + citations ────
+# How many files the turn produced in all, by session, read once by the turn's changed.json: the
+# response carries at most RESP_MAX_FILES of them and the page says "showing 25 of N" from this.
+_produced_total: dict[str, int] = {}
+
+
+def _produced_rel(path: str) -> str:
+ """A produced path as the workspace names it: without a leading "./". A character strip
+ (`lstrip("./")`) also ate the dot of a dotfile, so `.harness/state.json` read as
+ `harness/state.json`, passed the internal-file check, and a produced `.env` would have been
+ captured as `env` (found by the test that pins this, 2026-09-25)."""
+ path = str(path or "")
+ while path.startswith("./"):
+ path = path[2:]
+ return path
+
+
async def _collect_produced(sid: str, exclude: set[str] | None = None) -> list[dict]:
exclude = exclude or set()
try:
@@ -6897,26 +6913,31 @@ async def _collect_produced(sid: str, exclude: set[str] | None = None) -> list[d
items = (r.json() or {}).get("files") or []
except Exception: # noqa: BLE001
return []
+ _produced_total[sid] = len([it for it in items if (it or {}).get("path")
+ and not _is_internal_output(_produced_rel(it["path"]))])
out: list[dict] = []
# The response carries at most RESP_MAX_FILES of them. Newest first when the runner says when
# each was written (the item's mtime), so a turn that produced a long series (a game's 1,400
# archived frames, hosted 2026-09-25) shows its latest and not its first second; a runner
# without the field keeps its own order. The console says how many there were in all.
items = sorted(items, key=lambda it: float((it or {}).get("mtime") or 0), reverse=True)
- for it in items[:RESP_MAX_FILES]:
+ # The cap counts produced files, so what is never one (an internal name, an input file the
+ # caller attached) is set aside before it: an internal file newer than the rest must not
+ # take a slot from a real one.
+ wanted: list[tuple[str, str]] = []
+ for it in items:
path = (it or {}).get("path")
- if not path:
- continue
- rel = path.lstrip("./")
- if rel in exclude or _is_internal_output(rel):
- continue
+ rel = _produced_rel(path) if path else ""
+ if rel and rel not in exclude and not _is_internal_output(rel):
+ wanted.append((path, rel))
+ for path, rel in wanted[:RESP_MAX_FILES]:
try:
fr = await _sandbox("/file", sid, "GET", params={"path": path})
if fr.status_code >= 400 or not fr.content or len(fr.content) > RESP_MAX_FILE_BYTES:
continue
cfile = _rid("cfile")
media = fr.headers.get("content-type", "application/octet-stream")
- fname = path.lstrip("./")
+ fname = rel
if await _blob_put(f"containers/{sid}/{cfile}", fr.content, kb=RESP_BLOB_KB):
await _blob_put(f"containers/{sid}/{cfile}.meta",
json.dumps({"filename": fname, "media_type": media,
@@ -7407,6 +7428,7 @@ async def _resp_execute(translator: _RespTranslator, *, org: str, member: str, s
try:
await _blob_put(f"sessions/{sid}/changed.json", json.dumps({
"at": time.time(),
+ "produced": _produced_total.pop(sid, len(produced)),
"files": [{"path": f.get("filename"), "file_id": f.get("file_id"),
"bytes": f.get("bytes")} for f in produced if f.get("file_id")],
}).encode(), kb=RESP_BLOB_KB)
@@ -9243,9 +9265,12 @@ async def session_workspace_files(sid: str, request: Request, changed: bool = Fa
if changed:
blob = await _blob_get(f"sessions/{sid}/changed.json", kb=RESP_BLOB_KB)
items = []
+ produced_n = 0
if blob:
try:
- items = (json.loads(blob) or {}).get("files") or []
+ doc = json.loads(blob) or {}
+ items = doc.get("files") or []
+ produced_n = int(doc.get("produced") or 0)
except Exception: # noqa: BLE001
items = []
files = [{"object": "file", "id": it["file_id"], "container_id": sid,
@@ -9255,7 +9280,9 @@ async def session_workspace_files(sid: str, request: Request, changed: bool = Fa
"file_id": it["file_id"], "download_url": _file_url(sid, it["file_id"])}
for it in items if it.get("path") and it.get("file_id")]
files.sort(key=lambda f: f["path"])
- return {"session_id": sid, "changed": True, "count": len(files), "files": files}
+ # `produced` is how many files the turn wrote in all; `count` is how many of them the
+ # response captured (at most RESP_MAX_FILES), which is what this list can name.
+ return {"session_id": sid, "changed": True, "count": len(files), "produced": max(produced_n, len(files)), "files": files}
tf = await _workspace_tar(sid)
if tf is None:
raise HTTPException(404, "no workspace for this session yet — run a task first")
diff --git a/gateway/tests/test_produced_total.py b/gateway/tests/test_produced_total.py
new file mode 100644
index 00000000..7bfaf772
--- /dev/null
+++ b/gateway/tests/test_produced_total.py
@@ -0,0 +1,83 @@
+"""A turn that produced more files than a response carries: the newest lead, the record says how
+many there were in all, and the listing serves that number beside the captured count. Without it a
+run that archived 2,700 frames showed its first 24 in path order (hosted, 2026-09-25) and the
+console's "Showing 25 of N" could only ever read N = 25.
+"""
+import asyncio
+import json
+import os
+import sys
+from pathlib import Path
+
+import pytest
+from fastapi.testclient import TestClient
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+os.environ.setdefault("HR_BACKING", "local")
+import app as gw # noqa: E402
+
+ORG = "local"
+
+
+class _Resp:
+ def __init__(self, status: int, body: bytes, ctype: str = "application/json"):
+ self.status_code, self.content, self.headers = status, body, {"content-type": ctype}
+
+ def json(self):
+ return json.loads(self.content)
+
+
+def test_collection_keeps_the_newest_and_counts_them_all(monkeypatch):
+ sid = "hsessprod" + os.urandom(4).hex()
+ # 30 produced files, listed by the runner in path order, written at increasing times; two
+ # internal names that never count and never show
+ listed = [{"path": f"observations/{i:06d}.jpg", "status": "?", "mtime": 1_700_000_000 + i} for i in range(30)]
+ listed += [{"path": ".harness/state.json", "status": "M", "mtime": 1_800_000_000},
+ {"path": "AGENTS.md", "status": "M", "mtime": 1_800_000_001}]
+ stored = {}
+
+ async def _sandbox(path, s, method, body=None, params=None):
+ if path == "/produced":
+ return _Resp(200, json.dumps({"files": listed}).encode())
+ if path == "/produced/ack":
+ return _Resp(200, b"{}")
+ return _Resp(200, b"bytes", "image/jpeg") # GET /files/<path>
+
+ async def _blob_put(key, data, kb=0):
+ stored[key] = data
+ return True
+ monkeypatch.setattr(gw, "_sandbox", _sandbox)
+ monkeypatch.setattr(gw, "_blob_put", _blob_put)
+ monkeypatch.setattr(gw, "RESP_MAX_FILES", 25)
+ out = asyncio.run(gw._collect_produced(sid))
+ names = [o["filename"] for o in out]
+ assert len(out) == 25 and names[0] == "observations/000029.jpg" and names[-1] == "observations/000005.jpg"
+ assert not any(n.startswith(".harness/") or n == "AGENTS.md" for n in names)
+ assert gw._produced_total[sid] == 30 # what the turn produced, not what the response carries
+
+
+def api(monkeypatch):
+ async def principal(request):
+ return {"org": ORG, "member": "me@local"}
+ monkeypatch.setattr(gw, "_principal", principal)
+ return TestClient(gw.app)
+
+
+def _session(sid: str) -> None:
+ asyncio.run(gw._vertex_upsert(sid, {"tenant": ORG, "status": "done", "member_id": "me@local"}))
+
+
+def test_the_changed_listing_serves_the_turns_total_beside_the_captured_count(api):
+ sid = "hsessprod" + os.urandom(4).hex()
+ _session(sid)
+ files = [{"path": f"observations/{i:06d}.jpg", "file_id": f"cfile{i}", "bytes": 5} for i in range(2)]
+ asyncio.run(gw._blob_put(f"sessions/{sid}/changed.json",
+ json.dumps({"at": 1.0, "produced": 30, "files": files}).encode(), kb=gw.RESP_BLOB_KB))
+ d = api.get(f"/v1/sessions/{sid}/files?changed=true").json()
+ assert d["count"] == 2 and d["produced"] == 30 and len(d["files"]) == 2
+ # a record written before the field existed: the total is at least what was captured
+ asyncio.run(gw._blob_put(f"sessions/{sid}/changed.json",
+ json.dumps({"at": 1.0, "files": files}).encode(), kb=gw.RESP_BLOB_KB))
+ d = api.get(f"/v1/sessions/{sid}/files?changed=true").json()
+ assert d["count"] == 2 and d["produced"] == 2
diff --git a/ui/src/components/ChatAttachments.tsx b/ui/src/components/ChatAttachments.tsx
index 0fc2348e..f574cbcf 100644
--- a/ui/src/components/ChatAttachments.tsx
+++ b/ui/src/components/ChatAttachments.tsx
@@ -53,14 +53,18 @@ export function OutputFiles({ files, onPreview }: {
if (!sid || files.length < LISTED_MAX) { setTotal(null); return; }
let alive = true;
harnessFetch(`/api/harness/v1/sessions/${encodeURIComponent(sid)}/files?changed=true`, { cache: 'no-store' })
- .then((r) => (r.ok ? r.json() : null)).then((d: { count?: number } | null) => { if (alive && d && typeof d.count === 'number') setTotal(d.count); })
+ .then((r) => (r.ok ? r.json() : null)).then((d: { count?: number; produced?: number } | null) => { if (alive && d && typeof (d.produced ?? d.count) === 'number') setTotal(d.produced ?? d.count ?? 0); })
.catch(() => undefined);
return () => { alive = false; };
}, [sid, files.length]);
if (!files.length) return null;
const more = total !== null && total > files.length;
- const zipUrl = `/api/harness/v1/sessions/${encodeURIComponent(files[0].container_id)}`
- + `/files/archive?files=${encodeURIComponent(files.map((f) => f.file_id).join(','))}`;
+ // the turn's captured files by id; when the turn produced more than the response carries, the
+ // whole workspace (every file of every turn), which is the only archive that holds them all
+ const zipUrl = more
+ ? `/api/harness/v1/sessions/${encodeURIComponent(sid)}/files/archive`
+ : `/api/harness/v1/sessions/${encodeURIComponent(sid)}`
+ + `/files/archive?files=${encodeURIComponent(files.map((f) => f.file_id).join(','))}`;
return (
<div className="wbx-files">
{more && <div className="wbx-files-more">Showing {files.length} of the {total.toLocaleString()} files this turn produced.</div>}
@@ -83,7 +87,7 @@ export function OutputFiles({ files, onPreview }: {
{files.length > 1 && (
<button className="wbx-zipall" type="button"
onClick={(e) => { e.stopPropagation(); setZipErr(''); downloadFile(zipUrl, 'outputs.zip').catch((err: unknown) => setZipErr(err instanceof Error ? err.message : 'Could not build the archive.')); }}>
- <IcDl /> Download all ({files.length}) as .zip
+ <IcDl /> {more ? 'Download the whole workspace as .zip' : `Download all (${files.length}) as .zip`}
</button>
)}
{zipErr && <div className="wbx-zipall-err" role="alert">{zipErr}</div>}