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.

browser: the reaper's idle clock counts the person's takeover, so a human browsing is not stopped under them (#548)

Rudy Mizrahi Celeklicf720be35ff7
diff --git a/gateway/browser_plane.py b/gateway/browser_plane.py
index 69ee56cb..ad340500 100644
--- a/gateway/browser_plane.py
+++ b/gateway/browser_plane.py
@@ -272,10 +272,23 @@ def minutes(rec: dict) -> int:
def expired(rec: dict, now: float | None = None) -> str | None:
+ """Why this browser should be stopped, or None. Idle means nobody has touched it: the agent's
+ last tool call (`last_used`) AND the person's last takeover (`control_at`, written by the
+ console's live view), whichever is later. Only the agent's clock was read before, so a person
+ who took the browser over and browsed for IDLE_S without the agent calling had their live
+ session stopped under them — which is what the "stopped while the person had it" answer was
+ there for as a race, not as the ordinary end of a takeover. A record with no takeover has no
+ `control_at` and reads exactly as it did. The session cap is deliberate and still fires on
+ `created` alone, whoever is driving."""
now = now or time.time()
if now - float(rec.get("created") or now) > SESSION_CAP_MIN * 60:
return "session_cap"
- if now - float(rec.get("last_used") or now) > IDLE_S:
+ # While the person holds the browser it is never idle: their browsing happens in the vendor's live
+ # view, which this process never sees, so neither clock moves while they use it. The session cap
+ # above still ends it, and handing it back starts the agent's idle clock from the takeover's time.
+ if str(rec.get("control") or "") == "user":
+ return None
+ if now - max(float(rec.get("last_used") or now), float(rec.get("control_at") or 0)) > IDLE_S:
return "idle"
return None
diff --git a/gateway/tests/test_browser.py b/gateway/tests/test_browser.py
index 3d421f0c..5d1666fb 100644
--- a/gateway/tests/test_browser.py
+++ b/gateway/tests/test_browser.py
@@ -883,6 +883,45 @@ def test_the_person_takes_the_browser_over_and_the_agent_waits(client, world):
+def test_a_takeover_keeps_the_browser_alive_but_not_past_the_session_cap(client, world):
+ """The reaper's idle clock counts the person's takeover, not only the agent's calls. A person
+ who takes the browser over from the console's live view and browses without the agent calling
+ kept the agent's `last_used` from moving, so the reaper stopped their live session under them
+ at IDLE_S. The takeover is handed over through the real route, which is what writes
+ `control_at`. Still reaped when BOTH clocks are old, and the session cap still fires whatever
+ either clock says."""
+ reg, ven, _ = world
+ reg.record = _record()
+ hid = _harness(client)
+ _include(client, hid)
+ sid = _session_of(hid)
+ tok = gw._mint_hosted_cred(hid, sid, _key(hid))
+ assert _call(client, tok, "navigate", url="example.com")["isError"] is False
+ assert client.post(f"/v1/sessions/{sid}/browser/control", json={"control": "user"},
+ headers=HEADERS).json()["control"] == "user"
+ rec = asyncio.run(browser_plane.registry.get(sid))
+ assert float(rec["control_at"]) > 0, "the route writes the person's clock"
+ # the agent has not called for longer than the idle bound, but the person has the browser
+ rec["last_used"] -= browser_plane.IDLE_S + 1
+ assert asyncio.run(browser_plane.expired_sessions()) == []
+ # the person browsing moves neither clock (their browsing is in the vendor's live view): while they
+ # hold it, it is not idle however old both clocks are
+ rec["control_at"] -= browser_plane.IDLE_S + 1
+ assert asyncio.run(browser_plane.expired_sessions()) == []
+ # handed back to the agent with both clocks old: idle, as before
+ assert client.post(f"/v1/sessions/{sid}/browser/control", json={"control": "agent"},
+ headers=HEADERS).json()["control"] == "agent"
+ rec = asyncio.run(browser_plane.registry.get(sid))
+ rec["last_used"] = rec["control_at"] = time.time() - browser_plane.IDLE_S - 1
+ assert [(x["sid"], why) for x, why in asyncio.run(browser_plane.expired_sessions())] == [(sid, "idle")]
+ rec["control"] = "user"
+ # the cap is on the session's whole length and fires however fresh either clock is, held or not
+ rec["last_used"] = rec["control_at"] = time.time()
+ assert asyncio.run(browser_plane.expired_sessions()) == []
+ rec["created"] -= browser_plane.SESSION_CAP_MIN * 60 + 1
+ assert [why for _, why in asyncio.run(browser_plane.expired_sessions())] == ["session_cap"]
+
+
def test_a_harness_with_the_browser_tells_its_agent_to_use_it():
"""The agent's doc gets a Browser section when the harness includes the plugin, after its own
instructions, and nothing when it does not (Codex opened a page with curl while the card