Skip to content

The agent that grows with you

fix(desktop): a zero request timeout is no deadline on the canonical socket

Teknium50e50484f86e
diff --git a/apps/desktop/src/api/canonical-deadline.test.ts b/apps/desktop/src/api/canonical-deadline.test.ts
index 663b8f5f1b3..3395d4e6127 100644
--- a/apps/desktop/src/api/canonical-deadline.test.ts
+++ b/apps/desktop/src/api/canonical-deadline.test.ts
@@ -93,3 +93,27 @@ test('a prerequisite attachment resolves the launch profile alias before prepari
expect(calls[1]).toMatchObject({ method: 'session.mutate', params: { profile: 'work', expected_revision: 3 } })
} finally { client.close() }
})
+
+test('a zero timeout is no deadline on the canonical socket: the request is sent and waits (F3)', async () => {
+ // onboarding.state / onboarding.start pass 0 (NO_DEADLINE): the shared channel arms no timer for 0.
+ // The canonical wrapper used to read 0 as an already-spent deadline and throw before sending, so the
+ // first-run decision settled at once and the setup card covered a configured home until readiness answered.
+ vi.spyOn(JsonRpcGatewayClient.prototype, 'connect').mockResolvedValue()
+ const calls: Array<{ method: string; timeout?: number }> = []
+ let answer: (value: unknown) => void = () => undefined
+
+ vi.spyOn(JsonRpcGatewayClient.prototype, 'request').mockImplementation(async (method, _params, timeout) => {
+ calls.push({ method, timeout })
+
+ return new Promise(resolve => { answer = resolve }) as never
+ })
+ const client = new HermesGateway()
+ await client.connect('ws://localhost/api/ws?native_dial=fixture&ticket=fixture')
+
+ try {
+ const state = client.request('onboarding.state', {}, 0)
+ await vi.waitFor(() => expect(calls).toEqual([{ method: 'onboarding.state', timeout: 0 }]))
+ answer({ run: false, eligible: false })
+ await expect(state).resolves.toEqual({ run: false, eligible: false })
+ } finally { client.close() }
+})
diff --git a/apps/desktop/src/api/client.ts b/apps/desktop/src/api/client.ts
index 02e7d45269d..2b7390caf0c 100644
--- a/apps/desktop/src/api/client.ts
+++ b/apps/desktop/src/api/client.ts
@@ -78,8 +78,18 @@ function legacyParams(method: string, params: Record<string, unknown>): Record<s
return Object.fromEntries(Object.entries(params).filter(([key]) => !strip.includes(key)))
}
+// A caller timeout of 0 (or less) means no deadline, as in the shared channel, which arms no timer
+// for it. Callers that wait on a way-out offer instead (onboarding.state / onboarding.start) pass 0.
+function requestDeadline(timeoutMs: number | undefined): number {
+ const budget = timeoutMs ?? DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS
+
+ return budget > 0 ? Date.now() + budget : Number.POSITIVE_INFINITY
+}
+
function remainingRequestBudget(deadline: number, signal?: AbortSignal): number {
signal?.throwIfAborted()
+
+ if (deadline === Number.POSITIVE_INFINITY) { return 0 }
const remaining = deadline - Date.now()
if (remaining <= 0) { throw new Error('Hermes gateway request timed out') }
@@ -376,7 +386,7 @@ export class HermesGateway extends JsonRpcGatewayClient {
override async request<T>(method: string, params: Record<string, unknown> = {}, timeoutMs?: number, signal?: AbortSignal): Promise<T> {
if (!this.canonical) { return super.request<T>(method, legacyParams(method, params), timeoutMs, signal) }
const generation = this.connectionGeneration
- const deadline = Date.now() + (timeoutMs ?? DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS)
+ const deadline = requestDeadline(timeoutMs)
// A truncating submit (edit / regenerate / restore) is the owner's rewind, then the submit.
const rewind = method === 'prompt.submit' ? splitRewindSubmit(params) : null