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
fix(dsh): cross-process resume — the one seam upstream left open, used for the one gap it left shut
richard-epsilladad09c585a29
diff --git a/runner/dsh_driver.py b/runner/dsh_driver.pyindex 130e8c10..8211e32b 100644--- a/runner/dsh_driver.py+++ b/runner/dsh_driver.py@@ -109,10 +109,17 @@ def _emit(method: str, payload) -> None:sys.stdout.flush()-def _mcp_cordis(home: pathlib.Path, servers: list[dict]) -> str | None:- """Bundled default composition + one dsh-mcp-client entry per enabled server."""+def _compose_cordis(home: pathlib.Path, servers: list[dict]) -> str:+ """Our runtime composition: the wheel's bundled default, with the SDK server entry swapped+ for the resume-or-create subclass (see hr_dsh_server.cjs — packaged-bin loads+ configuration-relative plugins), plus one dsh-mcp-client entry per enabled MCP server."""import deepseek_harness_runtime as runtimebase = pathlib.Path(runtime.bundled_default_config_path()).read_text()+ needle = "name: '@deepseek-ai/dsh-sdk-jsonrpc-server'"+ if base.count(needle) != 1:+ raise SystemExit("dsh bundled cordis no longer names the sdk server exactly once — "+ "re-verify hr_dsh_server.cjs against this runtime before shipping")+ base = base.replace(needle, "name: './hr_dsh_server.cjs'")blocks = []for i, s in enumerate(servers):url = (s or {}).get("url")@@ -130,12 +137,15 @@ def _mcp_cordis(home: pathlib.Path, servers: list[dict]) -> str | None:if hdrs:entry["config"]["headers"] = hdrsblocks.append(entry)- if not blocks:- return None- import yamlpath = home / ".dsh" / "cordis.yml"path.parent.mkdir(parents=True, exist_ok=True)- path.write_text(base + "\n" + yaml.safe_dump(blocks, sort_keys=False))+ import shutil+ shutil.copy(pathlib.Path(__file__).with_name("hr_dsh_server.cjs"), path.parent / "hr_dsh_server.cjs")+ extra = ""+ if blocks:+ import yaml+ extra = "\n" + yaml.safe_dump(blocks, sort_keys=False)+ path.write_text(base + extra)return str(path)@@ -157,10 +167,8 @@ def main() -> int:from deepseek_harness import DeepSeekHarnesskwargs = dict(provider="deepseek-official", model=job["model"],- cwd=cwd, session_root=str(sessions))- cordis = _mcp_cordis(home, job.get("mcp_servers") or [])- if cordis:- kwargs["cordis"] = cordis+ cwd=cwd, session_root=str(sessions),+ cordis=_compose_cordis(home, job.get("mcp_servers") or []))sid = job.get("session_id") or None_emit("__hr_init", {"session_id": sid or "", "relay_port": srv.server_address[1]})with DeepSeekHarness(**kwargs) as h:diff --git a/runner/hr_dsh_server.cjs b/runner/hr_dsh_server.cjsnew file mode 100644index 00000000..4d28ae26--- /dev/null+++ b/runner/hr_dsh_server.cjs@@ -0,0 +1,99 @@+/**+ * hr-sdk-jsonrpc-server — the upstream SDK server with one override: RESUME-OR-CREATE.+ *+ * Upstream's HarnessSdkJsonRpcServer only ever calls ctx.agents.create(), and the persistence+ * coordinator refuses a create whose sessionId already has a persisted log (a fresh process has+ * no in-memory seed, so adoption cannot apply). That makes every cross-process follow-up die+ * with "persisted log on disk that does not match this live session (id collision)" — captured+ * live on 2026-08-20, and precisely the continuation gap the DeepSeek-Harness audit predicted.+ * The wire itself has no resume method, so the fix lives at the one seam upstream left open:+ * this file loads as a CONFIGURATION-RELATIVE plugin (a documented packaged-bin feature),+ * subclasses the exported server class from the bundled snapshot, and tries+ * ctx.agents.resume({resumeSessionId}) before falling back to the parent's create.+ *+ * Version-locked: refuses to boot against any other upstream version, loudly, because this+ * reaches into TS-private fields (this.ctx / this.provider / this.model / this.maxTokens)+ * that only exist by compiled-JS convention.+ */+'use strict'++// This file lives OUTSIDE the runtime's pkg snapshot, so its own require cannot resolve the+// bundled '@deepseek-ai/*' modules. The snapshot's patched fs is process-global though, so a+// createRequire anchored INSIDE the snapshot's node_modules resolves them fine. The anchor is+// derived from the running entry script (…/node_modules/@deepseek-ai/dsh-sdk-jsonrpc-demo/lib/+// packaged-bin.js), which holds for both runtime carriers.+const path = require('node:path')+const { createRequire } = require('node:module')+const entry = process.argv[1] || ''+const nmIdx = entry.lastIndexOf('node_modules')+if (nmIdx < 0) {+ throw new Error(`hr-sdk-jsonrpc-server: cannot locate the runtime's node_modules from entry '${entry}'`)+}+const sreq = createRequire(path.join(entry.slice(0, nmIdx + 'node_modules'.length), 'hr-anchor.js'))+const base = sreq('@deepseek-ai/dsh-sdk-jsonrpc-server')+const { SessionId } = sreq('@deepseek-ai/dsh-session')+const { JsonRpcLineTransport } = sreq('@deepseek-ai/dsh-sdk-protocol')++const PINNED = '0.1.0-rc.7' // the repo-wide version the runtime wheel bundles+const got = sreq('@deepseek-ai/dsh-sdk-jsonrpc-server/package.json').version+if (got !== PINNED) {+ throw new Error(`hr-sdk-jsonrpc-server is pinned to @deepseek-ai/dsh-sdk-jsonrpc-server@${PINNED} ` ++ `but the runtime bundles ${got} — re-verify the private-field override before bumping`)+}++class HrServer extends base.HarnessSdkJsonRpcServer {+ async createSession(sessionId) {+ try {+ const handle = await this.ctx.agents.resume({+ resumeSessionId: SessionId(sessionId),+ agentOptions: {+ provider: this.provider,+ model: this.model,+ ...this.maxTokens === undefined ? {} : { maxTokens: this.maxTokens },+ },+ })+ const rec = { handle }+ this.sessions.set(sessionId, rec)+ process.stderr.write(`[hr-dsh] resumed session ${sessionId}\n`)+ return rec+ } catch (e) {+ // Nothing stored (a fresh id), or resume genuinely failed: fall through to the parent's+ // create. A create that then collides surfaces the collision rather than hiding it.+ process.stderr.write(`[hr-dsh] resume miss for ${sessionId}: ${String(e && e.message || e).slice(0, 160)}\n`)+ return super.createSession(sessionId)+ }+ }+}++exports.name = 'hr-sdk-jsonrpc-server'+exports.inject = ['agents']++exports.apply = function apply(ctx, config) {+ const rootFiber = ctx.root.fiber+ const transport = new JsonRpcLineTransport(process.stdin, process.stdout)+ const server = new HrServer(ctx, transport, {+ maxTokensAsSuccess: !!(config && config.maxTokensAsSuccess),+ })+ let exitTask+ const disposeAndExit = () => {+ exitTask ??= (async () => {+ await Promise.allSettled([Promise.resolve().then(() => transport.flush())])+ await Promise.allSettled([Promise.resolve().then(() => rootFiber.dispose())])+ process.exit(0)+ })()+ return exitTask+ }+ transport.onRequest(async (method, params) => {+ if (method === 'initialize') await ctx.get('loader')?.await()+ const result = await server.handleRequest(method, params)+ if (method === 'shutdown') setImmediate(() => { void disposeAndExit() })+ return result+ })+ ctx.effect(() => {+ transport.start()+ return async () => {+ await server.shutdown()+ transport.close()+ }+ }, 'hr-jsonrpc.serve')+}