Skip to content

Commit e68f3d8

Browse files
authored
fix(ui): surface rejected terminal actions (#124046)
Mark stale terminal tabs exited when the Gateway rejects input or resize, so operators see an actionable outcome instead of silently losing keystrokes.
1 parent 4b8ca98 commit e68f3d8

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎ui/src/components/terminal/terminal-connection.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,29 @@ describe("TerminalConnection", () => {
545545
]);
546546
});
547547

548+
it.each([
549+
["terminal.input", (conn: TerminalConnection) => conn.input("s1", "echo lost\n")],
550+
["terminal.resize", (conn: TerminalConnection) => conn.resize("s1", 120, 40)],
551+
] as const)("marks the session unavailable when %s rejects its live owner", async (_, act) => {
552+
const { client, conn } = makeHarness();
553+
const exits: unknown[] = [];
554+
await openSession(conn, { onExit: (info) => exits.push(info) });
555+
client.nextResponse = { ok: false };
556+
557+
await act(conn);
558+
559+
expect(exits).toEqual([
560+
{
561+
exitCode: null,
562+
signal: null,
563+
reason: "disconnected",
564+
error: "Terminal session is no longer available. Open a new terminal session.",
565+
},
566+
]);
567+
expect(conn.size).toBe(0);
568+
expect(client.listenerCount()).toBe(0);
569+
});
570+
548571
it("buffers output that races ahead of sink registration and replays it in order", async () => {
549572
const { client, conn } = makeHarness();
550573
const data: string[] = [];

‎ui/src/components/terminal/terminal-connection.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,25 @@ export class TerminalConnection {
612612
}
613613

614614
async input(sessionId: string, data: string): Promise<void> {
615-
await this.client.request("terminal.input", { sessionId, data }).catch(() => undefined);
615+
await this.requestAction("terminal.input", sessionId, { sessionId, data });
616616
}
617617

618618
async resize(sessionId: string, cols: number, rows: number): Promise<void> {
619-
await this.client.request("terminal.resize", { sessionId, cols, rows }).catch(() => undefined);
619+
await this.requestAction("terminal.resize", sessionId, { sessionId, cols, rows });
620+
}
621+
622+
private async requestAction(method: string, sessionId: string, params: unknown): Promise<void> {
623+
const stream = this.streams.get(sessionId);
624+
const result = await this.client.request<{ ok: boolean }>(method, params).catch(() => null);
625+
if (result?.ok !== false || !stream || this.streams.get(sessionId) !== stream) {
626+
return;
627+
}
628+
this.deliverExit(sessionId, stream, {
629+
exitCode: null,
630+
signal: null,
631+
reason: "disconnected",
632+
error: "Terminal session is no longer available. Open a new terminal session.",
633+
});
620634
}
621635

622636
/** Closes a session server-side and drops its local stream state. */

0 commit comments

Comments
 (0)