Skip to content

Commit 463af27

Browse files
committed
fix: match chat events by runId/idemKey in terminal
Gateway sends streaming events with runId instead of idempotencyKey, causing terminal chat to show 'Processing...' forever (events were silently discarded by the matching logic).
1 parent 39c0c97 commit 463af27

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

components/gateway-terminal.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313
* - Raw RPC mode (> method.name key=val)
1414
*/
1515

16-
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties } from 'react'
16+
import {
17+
useCallback,
18+
useEffect,
19+
useLayoutEffect,
20+
useMemo,
21+
useRef,
22+
useState,
23+
type CSSProperties,
24+
} from 'react'
1725
import { Icon } from '@iconify/react'
1826
import { useGateway } from '@/context/gateway-context'
1927
import { useTheme } from '@/context/theme-context'
@@ -450,13 +458,23 @@ export function GatewayTerminal() {
450458
(typeof p.session === 'object' && p.session !== null
451459
? (p.session as Record<string, unknown>).key
452460
: undefined)) as string | undefined
453-
const eventIdempotencyKey = (p.idempotencyKey ?? p.idempotency_key) as string | undefined
461+
const eventIdempotencyKey = (p.idempotencyKey ??
462+
p.idempotency_key ??
463+
p.idemKey ??
464+
p.runId) as string | undefined
454465

455466
// Accept if: idempotency key matches one we sent, OR session is terminal's, OR no session key
456-
const idempotencyMatch = eventIdempotencyKey && pendingIdempotencyKeys.current.has(eventIdempotencyKey)
467+
const idempotencyMatch =
468+
eventIdempotencyKey && pendingIdempotencyKeys.current.has(eventIdempotencyKey)
457469
const sessionMatch = !eventSessionKey || eventSessionKey === TERMINAL_SESSION_KEY
458470

459-
console.log('[GW-Terminal] chat event:', { state, sessionKey: eventSessionKey, idempotencyKey: eventIdempotencyKey, idempotencyMatch, sessionMatch })
471+
console.log('[GW-Terminal] chat event:', {
472+
state,
473+
sessionKey: eventSessionKey,
474+
idempotencyKey: eventIdempotencyKey,
475+
idempotencyMatch,
476+
sessionMatch,
477+
})
460478

461479
if (!idempotencyMatch && !sessionMatch) {
462480
console.log('[GW-Terminal] skipping event — no match:', eventSessionKey)
@@ -586,7 +604,10 @@ export function GatewayTerminal() {
586604
})) as Record<string, unknown> | undefined
587605

588606
const respStatus = resp?.status as string | undefined
589-
console.log('[GW-Terminal] chat.send response:', { status: respStatus, keys: resp ? Object.keys(resp).join(',') : 'null' })
607+
console.log('[GW-Terminal] chat.send response:', {
608+
status: respStatus,
609+
keys: resp ? Object.keys(resp).join(',') : 'null',
610+
})
590611

591612
// Check if the response contains an inline reply (synchronous path)
592613
const inlineReply = extractEventText(resp)

0 commit comments

Comments
 (0)