Skip to content

Commit 3b39d14

Browse files
committed
fix: terminal sendChatMessage — handle streaming/started status, extend timeout to 2min
The terminal only handled status='ok' responses. When gateway returns 'started'/'streaming'/'in_flight' (async responses), the function fell through without acknowledging, causing responses to appear lost. Now properly waits for streaming events on async status codes.
1 parent 94f3791 commit 3b39d14

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

components/gateway-terminal.tsx

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -544,34 +544,46 @@ export function GatewayTerminal() {
544544
const sendChatMessage = useCallback(
545545
async (message: string) => {
546546
setSending(true)
547+
streamBuf.current = ''
548+
streamId.current = null
547549
try {
548550
const resp = (await sendRequest('chat.send', {
549551
sessionKey: 'main',
550552
message,
551553
idempotencyKey: `gw-term-${Date.now()}`,
552554
})) as Record<string, unknown> | undefined
553555

554-
const status = resp?.status as string | undefined
555-
if (status === 'ok') {
556+
const respStatus = resp?.status as string | undefined
557+
558+
// Streaming/async — response will arrive via onEvent('chat')
559+
if (respStatus === 'started' || respStatus === 'in_flight' || respStatus === 'streaming') {
560+
// setSending stays true; events will clear it on 'final'
561+
setTimeout(
562+
() =>
563+
setSending((prev) => {
564+
if (prev) {
565+
addEntry('system', '⏱ Response timed out')
566+
return false
567+
}
568+
return prev
569+
}),
570+
120000, // 2 min timeout for long agent runs
571+
)
572+
return
573+
}
574+
575+
// Synchronous reply
576+
if (respStatus === 'ok' || !respStatus) {
556577
const reply = extractEventText(resp)
557578
if (reply && !isNoReply(reply)) {
558579
addEntry('response', reply)
559-
setSending(false)
560-
} else if (isNoReply(reply)) {
561-
setSending(false)
562580
}
581+
setSending(false)
582+
return
563583
}
564-
setTimeout(
565-
() =>
566-
setSending((prev) => {
567-
if (prev) {
568-
addEntry('system', '⏱ Response timed out')
569-
return false
570-
}
571-
return prev
572-
}),
573-
60000,
574-
)
584+
585+
// Unknown status — still wait for events
586+
setSending(false)
575587
} catch (e) {
576588
addEntry('error', e instanceof Error ? e.message : 'Send failed')
577589
setSending(false)

0 commit comments

Comments
 (0)