Repository navigation
Conversation
The delegation transport spawns tui_gateway.entry as a standalone stdio
server. Upstream hermes-agent (9595c3f345) made that server refuse to
start when a gateway already owns HERMES_HOME - both are state.db
writers, so the reservation is correct - which means every delegation
spawn fails with '[gateway-exit] refused' whenever the messaging
gateway is running (Telegram/Feishu/etc. keep it resident).
Replace the stdio server launch with a thin WS bridge: ensure the
gateway runtime, mint a session ticket on the control socket, dial the
canonical WebSocket, and pipe stdin JSON-RPC lines to it. The WS
transport reuses the same tui_gateway.server.dispatch, so the RPC
surface is unchanged; attached clients (Ink TUI, Desktop, this bridge)
coexist with the resident gateway by design.
The bridge runs top-level code without a __main__ guard: the native
launcher executes the script via exec(script, {}) whose fresh globals
lack __name__.
The WS bridge attaches to the gateway's canonical hermes-gateway-v1 channel, whose method contracts differ from the stdio/TUI surface the transport was written against. Session creation failed with 4001 invalid_params and turns never started: - session.create: drop close_on_disconnect, rename reasoning_effort to reasoning (CanonicalCreateParams); canonical lazy sessions build the agent on the first prompt and never emit a non-lazy session.info, so stop waiting (the official TUI renders lazy info with placeholders); the persisted identity only rides the create response top level - session.resume: drop eager_build - config.set yolo: session-scoped switch must omit scope (the scoped variant is the global toggle and is refused); value on/off, reply 1/0 - config.set model: refused with use_session_mutation_model — switch via session.mutate (operation=model, revision/generation fenced), confirm from the mutation receipt (config.get key=provider does not exist) - prompt.submit: requires a caller-chosen submission_id (idempotent admission identity); answers AdmissionStatus queued/started, never streaming - session.interrupt: requires execution_generation; session.close does not exist — detach with the receipt's subscription_id - delegation bootstrap: tui_gateway.server redirects sys.stdout to sys.stderr at import (stdio-entry protection), which hijacked the bridge's RPC channel to the host under delegation env; save and restore stdout around that import Track revision/execution_generation/subscription_id from the create receipt and session.info events. Test assertions updated to the new wire contract.
…history for hermes opens Hermes session opens paid ~3.3s where ACP harnesses answer in well under a second: every open spawned a fresh bridge (launcher probe + interpreter + WS attach), every helper subprocess re-ran the launcher probe, and the history pair spawned twice. - Warm bridge pool: a settled session's bridge is a stateless pipe to the resident gateway, so the adapter now hands it back on settle and the next open acquires it instead of spawning (exclusive ownership per session; cwd is a session.create parameter and the delegation skill text is thread-independent, so nothing is keyed per-thread) - Launcher-prefix cache: --print-runtime-command answers embed the caller's script verbatim, but the interpreter prefix is script-independent; cache that prefix keyed on the launcher's stat so a hermes update invalidates it, and re-append the passthrough arguments per spawn - Stable delegation skill directory (was mkdtemp): the bootstrap script stays byte-identical across opens so the prefix cache always hits - One-shot history: ensure + identity reconciliation ride a single interpreter start via a new ensure_and_resolve operation Measured against a live resident gateway under Desktop conditions (delegation env, model + thinking selected): cold open 3329ms -> 2446ms, warm open 1424ms; full turn round-trip unchanged and healthy.
|
Caution Review failedThe pull request is closed. 📝 Summary
Merge Risk:
|
Stacked on #631 (canonical wire fixes) — merge that first; once it lands, this PR's diff collapses to just the performance changes. Based on
perf/hermes-warm-bridge=fix/hermes-delegation-ws-bridge+ one commit.Problem
Hermes session opens paid ~3.3s where the ACP harnesses answer in well under a second. Cost breakdown per open, all against the same resident gateway:
resolveGatewayModel, the history pair) re-ran the launcher probe before its own interpreter startensure+ identity reconciliation) spawned twiceChanges
gateway-transport-pool.ts, new). A bridge is a stateless pipe between the host and the resident gateway's canonical WebSocket — session state lives in the gateway process — so a settled session's bridge can serve the next open. The adapter acquires from the pool before spawning and releases on session settle; each bridge serves one session at a time (exclusive ownership, no event routing changes). Faulted or never-started bridges are discarded on acquire/release; capacity 2. Nothing is keyed per-thread on purpose: cwd is asession.createparameter (never read from the bridge process), and the delegation skill text is thread-independent — the same per-thread-identity mistake that broke the ACP warm pool (PR feat: 集成 Hermes ACP 并修复会话生命周期 #206) is not repeated here.hermes-runtime.ts).--print-runtime-commandanswers embed the caller's script verbatim, but the interpreter prefix (python +-I+-cbootstrap) is script-independent. Cache the prefix keyed on the launcher's stat (mtime/size — ahermes updaterewrites the launcher and invalidates) plusHERMES_HOME/PATH; re-append the passthrough timeit arguments per spawn. Cache only stores entries whose echo tail matches the request verbatim.gateway-delegation.ts, wasmkdtemp): the bootstrap script stays byte-identical across opens so the prefix cache always hits. The file is intentionally not deleted on dispose — warm bridges keep serving the registered skill path, and the next open overwrites it.gateway-history-script.ts,gateway-history.ts,gateway-open.ts): a newensure_and_resolveoperation persists the session row and reads the storage identity back in a single interpreter start; resume/fork paths keep resolve-only.Measured
Against a live resident gateway (Telegram/Feishu connected), Desktop-identical conditions (delegation env,
--print-runtime-commandnative chain, model + thinking selected), same machine before/after:Verification (SHA
be506a79)hermes verifyon this branch: bootstrap / build (tsc full repo + plugins + renderer + rust) / typecheck / test:rust / lint / format:check all PASS. Full vitest 7111 passed; the single failure is the pre-existing baselinepackages/adapters/workbuddy/test/discovery.test.ts > finds the macOS bundle— reproduced on the parent commits of fix(adapters): attach the hermes delegation gateway to the resident gateway and speak its canonical wire #631 (documented there): the branch base predates the workbuddy discovery update while the local WorkBuddy.app CLI moved on. Unrelated to this PR's files.gateway-transport-pool.test.ts, 7 cases: idle acquire, fault/never-started discard, runtime mismatch, capacity eviction, teardown).