Skip to content

Commit 655724a

Browse files
authored
fix(gateway): run timeouts reach the browser as timeout, not generic failed (#123511)
classifyAgentRunTerminalOutcome computes the timeout classification and the emit path discarded it: errorKind came only from event metadata the lifecycle producer never sets, plus text-sniffing an often-undefined error. The browser projection classifies status timeout only via errorKind, so an idle/run-budget timeout rendered generic failed with empty error while sessions.list and the TUI both said timeout. The recorded classification now flows through.
1 parent 678c89c commit 655724a

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎src/gateway/server-chat.agent-events.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,11 +3251,42 @@ describe("agent event handler", () => {
32513251
runId: "client-timeout",
32523252
state: "error",
32533253
stopReason: "timeout",
3254+
// The recorded classification must reach the browser as errorKind or
3255+
// the projection renders a generic "failed" while sessions.list says
3256+
// "timeout".
3257+
errorKind: "timeout",
32543258
errorMessage: "agent provider timeout",
32553259
});
32563260
expect(payload).not.toHaveProperty("message");
32573261
});
32583262

3263+
it("classifies a timeout end without error text via the recorded outcome", () => {
3264+
// Idle/run-budget timeouts end with no error field; without deriving
3265+
// errorKind from the terminal classification the projection falls back
3266+
// to text-sniffing an undefined error and renders a generic "failed".
3267+
const { broadcast, chatRunState, handler } = createHarness();
3268+
registerChatRun(chatRunState, "provider-idle-timeout", "session-idle", "client-idle");
3269+
3270+
emitAgentEvent(
3271+
handler,
3272+
"provider-idle-timeout",
3273+
"lifecycle",
3274+
{ phase: "end", aborted: true, stopReason: "timeout", timeoutPhase: "idle" },
3275+
{ seq: 2, ts: 1_500 },
3276+
);
3277+
3278+
const payload = expectDefined(
3279+
chatBroadcastCalls(broadcast)[0],
3280+
"chatBroadcastCalls(broadcast)[0] test invariant",
3281+
)[1] as Record<string, unknown>;
3282+
expect(payload).toMatchObject({
3283+
runId: "client-idle",
3284+
state: "error",
3285+
stopReason: "timeout",
3286+
errorKind: "timeout",
3287+
});
3288+
});
3289+
32593290
it.each([
32603291
{
32613292
name: "older timestamp",

‎src/gateway/server-chat.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,8 @@ export function createAgentEventHandler({
841841
timeoutPhase: evt.data?.timeoutPhase,
842842
error: evt.data?.error,
843843
});
844-
const terminalState =
845-
CHAT_STATE_BY_TERMINAL_CLASSIFICATION[classifyAgentRunTerminalOutcome(terminalOutcome)];
844+
const terminalClassification = classifyAgentRunTerminalOutcome(terminalOutcome);
845+
const terminalState = CHAT_STATE_BY_TERMINAL_CLASSIFICATION[terminalClassification];
846846
if (!(opts?.skipChatErrorFinal && terminalState === "error")) {
847847
emitChatTerminal(
848848
terminalSessionKey,
@@ -852,8 +852,13 @@ export function createAgentEventHandler({
852852
terminalState,
853853
terminalOutcome.error ?? evt.data?.error,
854854
terminalOutcome.stopReason,
855-
readChatErrorKind(evt.data?.errorKind) ??
856-
resolveChatErrorKindFromError(evt.data?.error),
855+
// Timeout is a recorded classification, not event metadata: the
856+
// lifecycle producer emits no errorKind, so without this the UI
857+
// shows a generic "failed" while sessions.list says "timeout".
858+
terminalClassification === "timeout"
859+
? "timeout"
860+
: (readChatErrorKind(evt.data?.errorKind) ??
861+
resolveChatErrorKindFromError(evt.data?.error)),
857862
{
858863
agentId: terminalAgentId,
859864
controlUiVisible: isControlUiVisible,

0 commit comments

Comments
 (0)