Fix terminal slot review issues

This commit is contained in:
Mohamed Boudra
2026-03-23 12:44:18 +07:00
parent ea41dbc8e7
commit df99442123
5 changed files with 27 additions and 11 deletions
+1 -1
View File
@@ -2613,7 +2613,7 @@ export class DaemonClient {
timeout: 10000,
options: { skipQueue: true },
});
if (!payload.error) {
if (payload.error === null) {
this.setTerminalSlot(terminalId, payload.slot);
}
return payload;
@@ -404,6 +404,11 @@ async function subscribeRawTerminal(
if (message.message.type !== "subscribe_terminal_response") {
throw new Error("Expected subscribe_terminal_response");
}
if (message.message.payload.error !== null) {
throw new Error(
`Expected successful subscribe_terminal_response: ${message.message.payload.error}`,
);
}
expect(message.message.payload).not.toHaveProperty("state");
return message.message.payload.slot;
}
+7 -3
View File
@@ -7661,7 +7661,6 @@ export class Session {
type: "subscribe_terminal_response",
payload: {
terminalId: msg.terminalId,
slot: 0,
error: "Terminal manager not available",
requestId: msg.requestId,
},
@@ -7675,7 +7674,6 @@ export class Session {
type: "subscribe_terminal_response",
payload: {
terminalId: msg.terminalId,
slot: 0,
error: "Terminal not found",
requestId: msg.requestId,
},
@@ -7686,11 +7684,17 @@ export class Session {
const slot = this.bindActiveTerminalStream(session);
if (slot === null) {
this.sessionLogger.warn(
{
terminalId: msg.terminalId,
activeTerminalStreamCount: this.activeTerminalStreams.size,
},
"Terminal stream slot exhaustion",
);
this.emit({
type: "subscribe_terminal_response",
payload: {
terminalId: msg.terminalId,
slot: 0,
error: "No terminal stream slots available",
requestId: msg.requestId,
},
+13 -6
View File
@@ -2161,12 +2161,19 @@ export const CreateTerminalResponseSchema = z.object({
export const SubscribeTerminalResponseSchema = z.object({
type: z.literal("subscribe_terminal_response"),
payload: z.object({
terminalId: z.string(),
slot: z.number().int().min(0).max(255),
error: z.string().nullable(),
requestId: z.string(),
}),
payload: z.union([
z.object({
terminalId: z.string(),
slot: z.number().int().min(0).max(255),
error: z.null(),
requestId: z.string(),
}),
z.object({
terminalId: z.string(),
error: z.string(),
requestId: z.string(),
}),
]),
});
export const KillTerminalResponseSchema = z.object({
@@ -84,7 +84,7 @@ export function decodeTerminalStreamFrame(bytes: Uint8Array): TerminalStreamFram
}
return {
opcode,
slot: bytes[1] ?? 0,
slot: bytes[1],
payload: bytes.subarray(2),
};
}