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.

fast-agent waits for its stream as long as the relay waits upstream (#602)

github-actions[bot]fca0987ca181
diff --git a/runner/server.py b/runner/server.py
index 3e76c797..71b0fb15 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -13377,6 +13377,13 @@ _FA_UNKNOWN_LIMITS = {"context_window": 2_000_000, "max_output_tokens": 128_000}
# One file, rewritten every turn: a resumed session names the same `generic.<id>`, so it reads this
# turn's file, never a stale one.
_FA_OVERLAY_FILE = "harness-turn.yaml"
+# How long fast-agent waits for its stream to start and between its events. Its own default is 150 s
+# (300 s at a high reasoning effort), shorter than the relay's wait upstream: a gemini-4-argon turn with
+# a long conversation of images failed after 291 s on fast-agent's own "OpenAI stream did not start
+# within 150.0 seconds" while the provider was still working (hosted, 2026-10-27). The relay's wait
+# decides, and fast-agent's is a little longer, so the relay's answer, which says what happened, is the
+# one that arrives.
+_FA_STREAM_WAIT_S = HR_RELAY_UPSTREAM_TIMEOUT_S + 30
def _fast_agent_known(model: str) -> dict | None | bool:
@@ -13398,15 +13405,15 @@ def _fast_agent_known(model: str) -> dict | None | bool:
def _fast_agent_overlay(home: pathlib.Path, model: str, vision: bool) -> bool:
- """Declare what this turn's model reads to fast-agent, where its own table says otherwise.
+ """This turn's model as fast-agent should take it: a model overlay named exactly as the runner's
+ `--model` (`generic.<id>`) in `<home>/model-overlays/`. fast-agent resolves the name to the overlay
+ and the id it sends upstream is unchanged (measured on 0.10.47). It always carries the stream wait
+ (_FA_STREAM_WAIT_S), and what the model reads where fast-agent's own table says otherwise.
The gateway knows whether the model's channel takes images (`vision`, from _TEXT_ONLY_INPUT);
fast-agent decides from its own table whether to offer attach_media and whether to keep an image in
- a message. Where the two disagree, a model overlay named exactly as the runner's `--model`
- (`generic.<id>`) in `<home>/model-overlays/` carries the gateway's answer: fast-agent resolves the
- name to the overlay and the id it sends upstream is unchanged (measured on 0.10.47). An id it
- knows keeps its own limits and every other type it reads; an id it does not know gets
- _FA_UNKNOWN_LIMITS. Where they agree, no overlay is written and an earlier one is removed.
+ a message. Where the two disagree the overlay carries the gateway's answer. An id it knows keeps
+ its own limits and every other type it reads; an id it does not know gets _FA_UNKNOWN_LIMITS.
Returns True when the overlay carries those made-up limits, so the route drops the cap."""
path = home / "model-overlays" / _FA_OVERLAY_FILE
known = _fast_agent_known(model)
@@ -13417,16 +13424,16 @@ def _fast_agent_overlay(home: pathlib.Path, model: str, vision: bool) -> bool:
else:
# a channel that refuses images: text alone, as _fast_agent_drop_media leaves the history
want = ["text/plain"]
- if known is False or want == takes:
- path.unlink(missing_ok=True)
- return False
+ reads = known is not False and want != takes
doc = {"name": f"generic.{model}", "provider": "generic", "model": model,
- "metadata": {"tokenizes": want, **({} if known else _FA_UNKNOWN_LIMITS)}}
+ "defaults": {"streaming_timeout": _FA_STREAM_WAIT_S}}
+ if reads:
+ doc["metadata"] = {"tokenizes": want, **({} if known else _FA_UNKNOWN_LIMITS)}
path.parent.mkdir(parents=True, exist_ok=True)
tmp = path.with_suffix(".yaml.hr-tmp")
tmp.write_text(json.dumps(doc), encoding="utf-8") # JSON is YAML; fast-agent reads it with yaml
os.replace(tmp, path)
- return not known
+ return reads and not known
def _fast_agent_config(cwd: str, tools_disabled: list[str] | None,
@@ -13531,8 +13538,9 @@ def _build_fast_agent(provider: str, auth: Auth, model: str, prompt: str, cwd: s
home = _fast_agent_home(cwd)
home.mkdir(parents=True, exist_ok=True)
if auth.api_key:
- # what the model reads, declared where fast-agent's own table disagrees (_fast_agent_overlay);
- # only through the relay, which takes back the cap made-up limits would add
+ # the stream wait, and what the model reads where fast-agent's own table disagrees
+ # (_fast_agent_overlay); only through the relay, whose wait it is and which takes back the
+ # cap made-up limits would add
made_up = _fast_agent_overlay(home, model, vision)
relay_base, relay_tok = _hermes_relay_route(
auth.base_url, auth.api_key, chat_cache=True,
diff --git a/runner/tests/test_fast_agent_overlay.py b/runner/tests/test_fast_agent_overlay.py
index fe3bf311..312c3a20 100644
--- a/runner/tests/test_fast_agent_overlay.py
+++ b/runner/tests/test_fast_agent_overlay.py
@@ -3,8 +3,10 @@
MEASURED on fast-agent 0.10.47 (2026-10-27): an id its table does not have is text only to it, so
attach_media is not offered and images are filtered out of the messages; claude-opus-5.5 was one of 65
such ids. A model overlay named `generic.<id>` in the home's model-overlays/ is what `--model
-generic.<id>` resolves to, with the id sent upstream unchanged. These tests pin the decision and what
-reaches the relay; fast-agent's own view is stubbed (its python is not on a test machine)."""
+generic.<id>` resolves to, with the id sent upstream unchanged. Every turn's overlay also carries
+fast-agent's stream wait (its own 150 s cut a long gemini-4-argon turn, hosted 2026-10-27). These tests pin
+the decision and what reaches the relay; fast-agent's own view is stubbed (its python is not on a test
+machine)."""
import json
import pathlib
import subprocess
@@ -60,7 +62,16 @@ def test_an_id_it_does_not_know_reads_images_when_its_channel_does(view):
def test_an_id_it_knows_with_images_is_left_to_its_own_table(view):
view["gpt-5.4"] = {"tokenizes": GPT}
_, flags, doc, _ = _turn("gpt-5.4", vision=True)
- assert doc is None and "max_tokens" not in flags["drop_fields"]
+ assert "metadata" not in doc and "max_tokens" not in flags["drop_fields"]
+
+
+def test_every_turn_waits_for_its_stream_as_long_as_the_relay_does(view):
+ view["gpt-5.4"] = {"tokenizes": GPT}
+ for model, vision in (("gpt-5.4", True), ("claude-opus-5.5", True), ("qwen3.7-max", False)):
+ _, _, doc, _ = _turn(model, vision=vision)
+ assert doc["name"] == f"generic.{model}"
+ assert doc["defaults"] == {"streaming_timeout": server._FA_STREAM_WAIT_S}
+ assert server._FA_STREAM_WAIT_S > server.HR_RELAY_UPSTREAM_TIMEOUT_S > 150
def test_a_text_only_channel_reads_text_alone_whatever_the_table_says(view):
@@ -70,7 +81,7 @@ def test_a_text_only_channel_reads_text_alone_whatever_the_table_says(view):
assert doc["metadata"] == {"tokenizes": ["text/plain"]} and "max_tokens" not in flags["drop_fields"]
# an id it does not know is already text only to it: nothing to declare
_, _, doc, _ = _turn("qwen3.7-max", vision=False)
- assert doc is None
+ assert "metadata" not in doc
def test_a_known_text_only_id_whose_channel_takes_images_gets_them(view):
@@ -80,18 +91,18 @@ def test_a_known_text_only_id_whose_channel_takes_images_gets_them(view):
assert "max_tokens" not in flags["drop_fields"]
-def test_the_file_is_this_turns_and_an_earlier_one_goes_when_none_is_needed(view):
+def test_the_file_is_this_turns_and_says_nothing_of_reading_when_none_is_needed(view):
view["gpt-5.4"] = {"tokenizes": GPT}
_, _, doc, ws = _turn("claude-sonnet-5.5", vision=True)
assert doc["model"] == "claude-sonnet-5.5"
_, _, doc, _ = _turn("gpt-5.4", vision=True, ws=ws) # a switch to a model its table knows
- assert doc is None
+ assert doc["model"] == "gpt-5.4" and "metadata" not in doc
def test_when_it_cannot_be_asked_the_turn_is_as_before(view):
view["claude-opus-5.5"] = False
_, flags, doc, _ = _turn("claude-opus-5.5", vision=True)
- assert doc is None and "max_tokens" not in flags["drop_fields"]
+ assert "metadata" not in doc and "max_tokens" not in flags["drop_fields"]
def test_its_view_is_asked_once_per_id(monkeypatch):