The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): a transient runtime.describe failure no longer bricks new sessions
Tekniumc0eff62a8bb5
diff --git a/ui-tui/src/__tests__/gatewayClient.test.ts b/ui-tui/src/__tests__/gatewayClient.test.tsindex 74a58b83169..dce14acc735 100644--- a/ui-tui/src/__tests__/gatewayClient.test.ts+++ b/ui-tui/src/__tests__/gatewayClient.test.ts@@ -178,6 +178,38 @@ describe('GatewayClient websocket attach mode', () => {}})+ it('re-reads a failed runtime.describe on the next session.create instead of bricking creation', async () => {+ vi.useFakeTimers()+ delete process.env.HERMES_TUI_GATEWAY_URL+ delete process.env.HERMES_TUI_SIDECAR_URL+ const gw = new GatewayClient(async () => ({ url: 'ws://gateway.test/api/ws', protocols: [], instance_id: 'owner', profile_id: 'fixture' }))+ gw.on('event', () => undefined)++ try {+ gw.start(); gw.drain()+ await vi.advanceTimersByTimeAsync(0)+ const socket = FakeWebSocket.instances[0]!+ socket.open()+ await vi.advanceTimersByTimeAsync(0)+ const frames = () => socket.sent.map(text => JSON.parse(text) as { id: number; method: string; params: any })+ const first = frames().find(frame => frame.method === 'runtime.describe')!+ socket.message(JSON.stringify({ jsonrpc: '2.0', id: first.id, error: { code: -32000, message: 'owner busy' } }))+ await vi.advanceTimersByTimeAsync(0)++ const created = gw.request<{ session_id: string }>('session.create', { model: 'm' })+ await vi.advanceTimersByTimeAsync(0)+ const retry = frames().filter(frame => frame.method === 'runtime.describe')+ expect(retry).toHaveLength(2)+ socket.message(JSON.stringify({ jsonrpc: '2.0', id: retry[1]!.id, result: {+ session_create: { sources: ['tui'], parameters: ['source', 'request_id', 'model'] } } }))+ await vi.advanceTimersByTimeAsync(0)+ const create = frames().find(frame => frame.method === 'session.create')!+ expect(create.params).toMatchObject({ source: 'tui', model: 'm' })+ socket.message(JSON.stringify({ jsonrpc: '2.0', id: create.id, result: { session_id: 'fresh', info: {} } }))+ await expect(created).resolves.toMatchObject({ session_id: 'fresh' })+ } finally { gw.kill(); vi.useRealTimers() }+ })+it('keeps discovery-only retries alive and delivers readiness to the mounted subscriber', async () => {vi.useFakeTimers()delete process.env.HERMES_TUI_GATEWAY_URLdiff --git a/ui-tui/src/gatewayClient.ts b/ui-tui/src/gatewayClient.tsindex 166026d3c75..1d8f7fd6e11 100644--- a/ui-tui/src/gatewayClient.ts+++ b/ui-tui/src/gatewayClient.ts@@ -170,6 +170,7 @@ export class GatewayClient extends EventEmitter {private localGeneration = 0isCanonical = falseprivate creationContract?: CreationContract+ private describeFlight?: Promise<void>constructor(private bootstrap: (start: boolean) => Promise<LocalGatewayGrant> = bootstrapLocalGateway) {super()@@ -545,9 +546,8 @@ export class GatewayClient extends EventEmitter {this.connectSidecarMirror()if (this.isCanonical) {- void this.requestOverWebSocket<{session_create: CreationContract}>('runtime.describe').then(description => {- this.creationContract = description.session_create-+ this.describeFlight = undefined+ void this.describeRuntime().then(() => {// The canonical gateway has no ready frame (readiness is the discovery// grant + runtime.describe); publish a client-local ready with no skin so// the renderer boots on its default theme.@@ -765,6 +765,24 @@ export class GatewayClient extends EventEmitter {private notConnected = (method: string) => new Error(`gateway not connected: ${method}`)+ /** The owner's session.create contract. A failed read is not cached: the next+ * session.create asks again instead of reporting an outdated gateway forever. */+ private describeRuntime(): Promise<void> {+ if (!this.describeFlight) {+ const flight: Promise<void> = this.requestOverWebSocket<{ session_create: CreationContract }>('runtime.describe').then(+ description => { this.creationContract = description.session_create },+ error => {+ if (this.describeFlight === flight) { this.describeFlight = undefined }++ throw error+ })++ this.describeFlight = flight+ }++ return this.describeFlight+ }+private requestOverWebSocket<T = unknown>(method: string, params: Record<string, unknown> = {}, timeoutMs?: number): Promise<T> {return this.ensureAttachedWebSocket(method).then(() =>this.channel.request<T>(method, params, timeoutMs, undefined, () => this.notConnected(method)))@@ -788,8 +806,10 @@ export class GatewayClient extends EventEmitter {if (!this.bootstrapFlight) { this.start() }- return this.bootstrapFlight!.then(() => {+ return this.bootstrapFlight!.then(async () => {if (this.bootstrapError) { throw this.bootstrapError }++ if (method === 'session.create' && !this.creationContract) { await this.describeRuntime() }const request = canonicalRequest(method, params, this.creationContract)return this.requestOverWebSocket<T>(request.method, request.params, timeoutMs)