The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): a missing server-request registry lets the channel answer -32601
kshitijk4poorab6e665807ed
diff --git a/apps/desktop/src/api/client.ts b/apps/desktop/src/api/client.tsindex e0b1d761fa9..07e2ceaef37 100644--- a/apps/desktop/src/api/client.ts+++ b/apps/desktop/src/api/client.ts@@ -35,6 +35,9 @@ export class HermesGateway extends JsonRpcGatewayClient {// The channel already answered -32603; surface the crash in devtools like the dial-failure sink.onRequestHandlerError: (error, request) =>console.error(`[gateway] server request handler crashed for ${request.method} (${request.id}):`, error),+ // The channel already answered -32601; note the missing registry in devtools.+ onUnhandledRequest: request =>+ console.warn(`[gateway] Hermes Desktop has no server-request registry for ${request.method} (${request.id})`),requestTimeoutMs: DEFAULT_GATEWAY_REQUEST_TIMEOUT_MS})}diff --git a/apps/desktop/src/store/gateway.test.ts b/apps/desktop/src/store/gateway.test.tsindex 293488781bb..9d5d11c41f8 100644--- a/apps/desktop/src/store/gateway.test.ts+++ b/apps/desktop/src/store/gateway.test.ts@@ -363,16 +363,15 @@ describe('server→client request routing without a registry handler (#112791)',const request = { fail: vi.fn(), id: 'srq-1', method: 'clarify', params: { session_id: 's1' }, respond: vi.fn() }// beforeEach configured a registry with onEvent only: nobody can answer,- // so the backend must hear -32601 now instead of waiting out its deadline.- dispatchPrimaryServerRequest(request as never, 'default')- expect(request.fail).toHaveBeenCalledTimes(1)- expect(request.fail).toHaveBeenCalledWith(-32601, expect.stringMatching(/registry/))+ // so the handler declines (false) and the channel answers -32601 now+ // instead of the backend waiting out its deadline.+ expect(dispatchPrimaryServerRequest(request as never, 'default')).toBe(false)+ expect(request.fail).not.toHaveBeenCalled()const onServerRequest = vi.fn()configureGatewayRegistry({ onEvent: vi.fn(), onServerRequest } as never)- request.fail.mockClear()- dispatchPrimaryServerRequest(request as never, 'work')+ expect(dispatchPrimaryServerRequest(request as never, 'work')).toBe(true)expect(request.fail).not.toHaveBeenCalled()expect(onServerRequest).toHaveBeenCalledTimes(1)expect(onServerRequest).toHaveBeenCalledWith(expect.objectContaining({ id: 'srq-1', method: 'clarify', profile: 'work' }))diff --git a/apps/desktop/src/store/gateway.ts b/apps/desktop/src/store/gateway.tsindex 61d586864d5..141d8917c11 100644--- a/apps/desktop/src/store/gateway.ts+++ b/apps/desktop/src/store/gateway.ts@@ -1,7 +1,6 @@import {type ConnectionState,type GatewayEvent,- JSON_RPC_METHOD_NOT_FOUND,reconnectBackoffDelayMs,registryBackendScopeKey,resolveGatewayWsUrl,@@ -294,21 +293,22 @@ export interface ScopedServerRequest extends ServerRequest {* Route a server→client request into the registry handler with its source tags.* Fail fast, never swallow: the backend blocks on this answer (clarify waits* its full 3600s deadline). Without a registry there is nobody to answer —- * -32601 tells the tool immediately instead of stalling the turn.+ * returning `false` lets the channel answer -32601 immediately instead of+ * stalling the turn (it also fires the client's `onUnhandledRequest` sink).*/-function dispatchServerRequest(request: ServerRequest, profile: string, connectionId: null | string): void {+function dispatchServerRequest(request: ServerRequest, profile: string, connectionId: null | string): boolean {if (!g.config?.onServerRequest) {- request.fail(JSON_RPC_METHOD_NOT_FOUND, 'Hermes Desktop has no server-request registry yet')-- return+ return false}g.config.onServerRequest({ ...request, ...(connectionId ? { connectionId } : {}), profile })++ return true}/** Fan a primary-socket server request into the registry handler with the active source tags. */-export function dispatchPrimaryServerRequest(request: ServerRequest, profile: string): void {- dispatchServerRequest(request, profile, g.config?.activeConnectionId?.() ?? null)+export function dispatchPrimaryServerRequest(request: ServerRequest, profile: string): boolean {+ return dispatchServerRequest(request, profile, g.config?.activeConnectionId?.() ?? null)}export function setPrimaryGateway(gateway: HermesGateway | null, profile = 'default'): void {diff --git a/apps/shared/src/index.ts b/apps/shared/src/index.tsindex 93a64e4e409..9d612f83ec6 100644--- a/apps/shared/src/index.ts+++ b/apps/shared/src/index.ts@@ -75,6 +75,7 @@ export {DEFAULT_HEARTBEAT_DEADLINE_MS,DEFAULT_HEARTBEAT_INTERVAL_MS,type GatewayRequestId,+ JSON_RPC_INTERNAL_ERROR,JSON_RPC_METHOD_NOT_FOUND,jsonRpcErrorFromFrame,type JsonRpcErrorPayload,diff --git a/apps/shared/src/json-rpc-gateway.ts b/apps/shared/src/json-rpc-gateway.tsindex f548c3595ac..2c546e8f7a0 100644--- a/apps/shared/src/json-rpc-gateway.ts+++ b/apps/shared/src/json-rpc-gateway.ts@@ -24,6 +24,8 @@ export interface GatewayClientOptions {heartbeatIntervalMs?: number/** A server→client request handler threw; the channel already answered `-32603`. */onRequestHandlerError?: JsonRpcRequestChannelOptions['onRequestHandlerError']+ /** No handler accepted a server→client request; the channel already answered `-32601`. */+ onUnhandledRequest?: JsonRpcRequestChannelOptions['onUnhandledRequest']/** Return true to intercept the default closed-state transition. */onSocketClose?: (event: { code: number }) => boolean | void/** Fetch `session.events.since` after a reconnect (default). Off for notification-only feeds whose peer never answers RPCs. */@@ -129,8 +131,10 @@ export class JsonRpcGatewayClient {*/private replayEpoch: string | null = nullprivate readonly stateHandlers = new Set<(state: ConnectionState) => void>()- private readonly options: Required<Omit<GatewayClientOptions, 'onRequestHandlerError' | 'socketFactory'>> &- Pick<GatewayClientOptions, 'onRequestHandlerError' | 'socketFactory'>+ private readonly options: Required<+ Omit<GatewayClientOptions, 'onRequestHandlerError' | 'onUnhandledRequest' | 'socketFactory'>+ > &+ Pick<GatewayClientOptions, 'onRequestHandlerError' | 'onUnhandledRequest' | 'socketFactory'>constructor(options: GatewayClientOptions = {}) {this.options = {@@ -145,6 +149,7 @@ export class JsonRpcGatewayClient {replay: options.replay ?? true,requestIdPrefix: options.requestIdPrefix ?? 'r',onRequestHandlerError: options.onRequestHandlerError,+ onUnhandledRequest: options.onUnhandledRequest,requestTimeoutMs: options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,socketFactory: options.socketFactory}@@ -158,6 +163,7 @@ export class JsonRpcGatewayClient {onEvent: event => this.handleEvent(event),onHeartbeatFailure: error => this.invalidate(error.message),onRequestHandlerError: this.options.onRequestHandlerError,+ onUnhandledRequest: this.options.onUnhandledRequest,requestTimeoutMs: this.options.requestTimeoutMs})}