Skip to content

Commit 1cc9019

Browse files
committed
fix: skip idle terminal.onEvent subscription and release pruned terminal buffers
- connection.ts: Only subscribe to client.terminal.onEvent when applyTerminalEvent handler is provided. No production caller passes this handler, so the subscription was a no-op wasting WebSocket traffic. - terminalSessionState.ts: Reset buffer atoms to EMPTY_TERMINAL_BUFFER_STATE when metadata snapshot pruning removes terminals no longer reported by the server. Releases up to 512KB of retained string data per pruned terminal session on long-running clients.
1 parent 4db082a commit 1cc9019

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

apps/web/src/environments/runtime/connection.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ export function createEnvironmentConnection(
143143
},
144144
);
145145

146-
const unsubTerminalEvent = input.client.terminal.onEvent(
147-
(event: Parameters<Parameters<WsRpcClient["terminal"]["onEvent"]>[0]>[0]) => {
148-
input.applyTerminalEvent?.(event, environmentId);
149-
},
150-
);
146+
const unsubTerminalEvent = input.applyTerminalEvent
147+
? input.client.terminal.onEvent(
148+
(event: Parameters<Parameters<WsRpcClient["terminal"]["onEvent"]>[0]>[0]) => {
149+
input.applyTerminalEvent!(event, environmentId);
150+
},
151+
)
152+
: () => undefined;
151153

152154
const cleanup = () => {
153155
disposed = true;

packages/client-runtime/src/terminalSessionState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ export function createTerminalSessionManager(config: TerminalSessionManagerConfi
402402

403403
for (const key of Object.keys(next)) {
404404
if (!retainedKeys.has(key)) {
405+
const removedEntry = next[key];
406+
if (removedEntry) {
407+
setBuffer(removedEntry.target, EMPTY_TERMINAL_BUFFER_STATE);
408+
}
405409
delete next[key];
406410
}
407411
}

0 commit comments

Comments
 (0)