The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 05:45 UTC
fix(client-runtime): terminals fit their pane again after a reconnect (#29696)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:23 UTC
ee265cc53999dbc8f16b75398088780f85f4d166
2 files changed
+17
-4
packages/client-runtime/src/state/terminalSession.test.ts
+4
@@ -245,10 +245,14 @@ describe("terminal session reducers", () => {
245
snapshot: BASE_SNAPSHOT,
246
});
247
let cursor = readTerminalOutputUpdate(state.output, INITIAL_TERMINAL_OUTPUT_CURSOR).cursor;
248
+ const attachedGeneration = state.output.generation;
249
+ // A socket reconnect resubscribes the same stream, so the server's new snapshot gets no seed.
250
state = applyTerminalAttachStreamEvent(state, { type: "snapshot", snapshot: BASE_SNAPSHOT });
251
const repeated = readTerminalOutputUpdate(state.output, cursor);
252
expect(repeated).toMatchObject({ type: "reset", data: "hello" });
253
expect(state.version).toBe(2);
254
+ // Viewers replay their measured grid once per generation; the new attachment holds the old size.
255
+ expect(state.output.generation).not.toBe(attachedGeneration);
256
cursor = repeated.cursor;
257
258
state = applyTerminalAttachStreamEvent(state, {
packages/client-runtime/src/state/terminalSession.ts
+13
-4
@@ -162,12 +162,21 @@ export function applyTerminalAttachStreamEvent(
162
maxBufferBytes = DEFAULT_MAX_TERMINAL_BUFFER_BYTES,
163
): TerminalBufferState {
164
switch (event.type) {
165
- case "snapshot":
165
+ case "snapshot": {
166
+ if (current.version === 0) {
167
+ return terminalBufferStateFromSnapshot(event.snapshot, maxBufferBytes, current);
168
+ }
169
+ // A later snapshot is a new server attachment, as after a socket reconnect. It starts a
170
+ // new generation because viewers replay their measured grid once per generation.
171
+ const reattached = {
172
+ ...current,
173
+ output: { ...current.output, generation: ++terminalAttachGeneration },
174
+ };
175
return {
167
- ...terminalBufferStateFromSnapshot(event.snapshot, maxBufferBytes, current),
168
- lifecycleVersion:
169
- current.version === 0 ? current.lifecycleVersion : current.lifecycleVersion + 1,
176
+ ...terminalBufferStateFromSnapshot(event.snapshot, maxBufferBytes, reattached),
177
+ lifecycleVersion: current.lifecycleVersion + 1,
178
};
179
+ }
180
case "restarted":
181
return {
182
...terminalBufferStateFromSnapshot(event.snapshot, maxBufferBytes, current),