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.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
console: the gateway proxy waits as long as it declares, not undici's five minutes (#214)
Hao Lu8031f3cfd70a
diff --git a/ui/package-lock.json b/ui/package-lock.jsonindex 63d99edb..a280887d 100644--- a/ui/package-lock.json+++ b/ui/package-lock.json@@ -55,6 +55,7 @@"remark-gfm": "^4.0.1","tailwind-merge": "^3.3.1","tailwindcss": "^3.4.1",+ "undici": "^6.28.1","xlsx": "^0.18.5","y-prosemirror": "^1.3.7","y-protocols": "^1.0.7",@@ -14233,6 +14234,15 @@"integrity": "sha512-DXtD3ZtEQzc7M8m4cXotyHR+FAS18C64asBYY5vqZexfYryNNnDc02W4hKg3rdQuqOYas1jkseX0+nZXjTXnvQ==","license": "MIT"},+ "node_modules/undici": {+ "version": "6.28.1",+ "resolved": "https://registry.npmjs.org/undici/-/undici-6.28.1.tgz",+ "integrity": "sha512-zWpdTVD54H48CIybL0rWQ3ukpb9d23wM7eH5RtfdmeP70cWHNjtfo7P4vZX+5CoDcO53J4Pu5uXp7lNfjc6DRA==",+ "license": "MIT",+ "engines": {+ "node": ">=18.17"+ }+ },"node_modules/undici-types": {"version": "6.21.0","resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",diff --git a/ui/package.json b/ui/package.jsonindex 0da203a9..d4ce00d4 100644--- a/ui/package.json+++ b/ui/package.json@@ -64,6 +64,7 @@"remark-gfm": "^4.0.1","tailwind-merge": "^3.3.1","tailwindcss": "^3.4.1",+ "undici": "^6.28.1","xlsx": "^0.18.5","y-prosemirror": "^1.3.7","y-protocols": "^1.0.7",diff --git a/ui/src/app/api/harness/[...path]/route.ts b/ui/src/app/api/harness/[...path]/route.tsindex afd7cee6..6abcc866 100644--- a/ui/src/app/api/harness/[...path]/route.ts+++ b/ui/src/app/api/harness/[...path]/route.ts@@ -16,6 +16,7 @@// UI's port is published), so it presents the key on its own and PINS org/member from server// constants — a request from the browser cannot claim an identity this box doesn't have.import type { NextRequest } from 'next/server';+import { Agent } from 'undici';import { LOCAL_MEMBER, LOCAL_ORG, SELF_HOSTED } from '@/lib/edition';import { AUTH_DISABLED, SESSION_COOKIE, sessionValid } from '@/lib/selfhost-auth';@@ -26,6 +27,15 @@ const GATEWAY =process.env.HARNESS_GATEWAY_URL ||'https://api.harnessrouter.ai';const INTERNAL_KEY = process.env.HARNESS_INTERNAL_KEY || '';+// maxDuration above is not what bounds the upstream call: Node's fetch gives the gateway 300 s to+// answer with response HEADERS and 300 s between body chunks (undici's headersTimeout and+// bodyTimeout defaults), then fails the request as "fetch failed". A synchronous+// POST /v1/responses sends nothing until the turn ends, so a turn longer than five minutes came+// back 502 "harness-gateway unreachable" while the runner finished it (measured: 301.0 s and+// 300.3 s on turns the session store shows completing at 340 s and 354 s), and a streamed turn+// silent for five minutes inside one tool call would end the same way. The gateway's own hop to+// the runner reads for an hour on purpose; this hop now allows what it declares.+const upstream = new Agent({ headersTimeout: maxDuration * 1000, bodyTimeout: maxDuration * 1000 });async function proxy(req: NextRequest, ctx: { params: Promise<{ path: string[] }> }) {const { path } = await ctx.params;@@ -80,12 +90,13 @@ async function proxy(req: NextRequest, ctx: { params: Promise<{ path: string[] }headers[lk] = v;});- const init: RequestInit = { method: req.method, headers, cache: 'no-store' };+ const init: RequestInit & { dispatcher: Agent; duplex?: 'half' } =+ { method: req.method, headers, cache: 'no-store', dispatcher: upstream };// STREAM the request body straight through (byte-exact, no buffering) so large uploads (up to GBs)// never get fully materialized in the BFF's memory. duplex:'half' is required by undici/fetch when// body is a ReadableStream. Falls back to arrayBuffer if the runtime didn't expose a body stream.if (req.method !== 'GET' && req.method !== 'HEAD') {- if (req.body) { init.body = req.body; (init as RequestInit & { duplex: 'half' }).duplex = 'half'; }+ if (req.body) { init.body = req.body; init.duplex = 'half'; }else init.body = await req.arrayBuffer();}