The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): the ensure client outlives the gateway's own startup deadline
Tekniumf9c83ffb9c3f
diff --git a/apps/desktop/electron/local-gateway-deadline.test.ts b/apps/desktop/electron/local-gateway-deadline.test.tsindex a3ce82dfa6a..1b25d771e1a 100644--- a/apps/desktop/electron/local-gateway-deadline.test.ts+++ b/apps/desktop/electron/local-gateway-deadline.test.ts@@ -63,3 +63,23 @@ test('a stale-owner restart client that times out but obeys SIGTERM is logged anexpect(ensures).toBe(2)expect(logs).toEqual(['gateway restart exited 7: hermes gateway restart timed out'])})++// `hermes gateway ensure` owns a 60 s startup deadline (hermes_cli/gateway_runtime.py+// DEFAULT_ENSURE_TIMEOUT) and always answers with a protocol verdict by then. Killing the client+// earlier turned a slow-but-valid cold start into "produced no result … Update Hermes".+test('the default ensure client outlives the protocol deadline and reads a late verdict', async () => {+ vi.useFakeTimers()++ const child = Object.assign(new EventEmitter(), {+ stdout: new EventEmitter(), stderr: new EventEmitter(), kill: vi.fn(() => true)+ })++ vi.doMock('node:child_process', () => ({ spawn: () => child }))+ const { runGatewayEnsure } = await import('./local-gateway')+ const result = runGatewayEnsure({ command: 'owned-client', args: [], env: {}, shell: false }, '.', 'profile', {})+ await vi.advanceTimersByTimeAsync(60_000)+ child.stdout.emit('data', Buffer.from('{"state":"starting","reason_code":"deadline"}'))+ child.emit('close', 5)+ await expect(result).resolves.toEqual({ code: 5, stdout: '{"state":"starting","reason_code":"deadline"}', stderr: '' })+ expect(child.kill).not.toHaveBeenCalled()+})diff --git a/apps/desktop/electron/local-gateway.ts b/apps/desktop/electron/local-gateway.tsindex dc88f563e9e..12382d4b58c 100644--- a/apps/desktop/electron/local-gateway.ts+++ b/apps/desktop/electron/local-gateway.ts@@ -3,10 +3,17 @@ import crypto from 'node:crypto'import { hiddenWindowsChildOptions, windowsShellCommand } from './windows-child-options'+// `hermes gateway ensure` answers with a protocol verdict (ready, or `starting: deadline`) within+// its own startup deadline: `--timeout` defaults to 60 s (hermes_cli/gateway_runtime.py+// DEFAULT_ENSURE_TIMEOUT). The client is killed only after that deadline plus interpreter start+// and verdict output, so a slow-but-valid cold start is never reported as "produced no result".+const GATEWAY_ENSURE_PROTOCOL_DEADLINE_MS = 60_000+const GATEWAY_ENSURE_CLIENT_GRACE_MS = 15_000+/** Run one bounded `hermes ... gateway <verb>` client (`ensure` by default; `restart` for a stale owner). */export function runGatewayEnsure(backend, cwd: string, home: string, parentEnv: NodeJS.ProcessEnv = process.env,- { timeoutMs = 40_000, label = 'hermes gateway ensure' }: { timeoutMs?: number; label?: string } = {}+ { timeoutMs = GATEWAY_ENSURE_PROTOCOL_DEADLINE_MS + GATEWAY_ENSURE_CLIENT_GRACE_MS, label = 'hermes gateway ensure' }: { timeoutMs?: number; label?: string } = {}): Promise<{ code: number; stdout: string; stderr: string }> {return new Promise((resolve, reject) => {// shell: true hands cmd.exe one command line it cuts at the first unquoted space,