diff --git a/src/main/runtime/rpc/methods/terminal.ts b/src/main/runtime/rpc/methods/terminal.ts index 667b64deb50..0bf4a936673 100644 --- a/src/main/runtime/rpc/methods/terminal.ts +++ b/src/main/runtime/rpc/methods/terminal.ts @@ -2682,7 +2682,6 @@ export const TERMINAL_METHODS: RpcAnyMethod[] = [ 'initial-snapshot' ) : null - const retainedTail = read.tail.length > 0 ? `${read.tail.join('\r\n')}\r\n` : '' const snapshotPublication = sendSnapshotFrames( (opcode, payload) => sendFrame(request.streamId, opcode, payload), { @@ -2703,7 +2702,9 @@ export const TERMINAL_METHODS: RpcAnyMethod[] = [ // tail, is a genuinely empty pane and must not be reported as a failure. unavailable: serialized || read.tail.length > 0 ? undefined : 'no-serializable-buffer', - data: serializedContent?.data ?? retainedTail + data: + serializedContent?.data ?? + (read.tail.length > 0 ? `${read.tail.join('\r\n')}\r\n` : '') } ) const replacement = stream.sourceRangeReplacement diff --git a/src/main/runtime/rpc/terminal-multiplex-initial-snapshot-fallback.test.ts b/src/main/runtime/rpc/terminal-multiplex-initial-snapshot-fallback.test.ts index 7894a2e59a0..652c8ebe122 100644 --- a/src/main/runtime/rpc/terminal-multiplex-initial-snapshot-fallback.test.ts +++ b/src/main/runtime/rpc/terminal-multiplex-initial-snapshot-fallback.test.ts @@ -142,6 +142,19 @@ describe('terminal multiplex initial snapshot fallback', () => { expect(snapshot.start.unavailable).toBeUndefined() }) + it('does not rebuild the retained tail when serialized content is available', async () => { + const tail = ['retained line'] + const tailJoin = vi.spyOn(tail, 'join') + const snapshot = await subscribeSnapshot({ + connectionId: 'conn-serialized-snapshot-tail', + serialized: { data: 'serialized screen', cols: 120, rows: 40 }, + tail + }) + + expect(snapshot.data).toBe('serialized screen') + expect(tailJoin).not.toHaveBeenCalled() + }) + it('reports unavailable when neither serialized data nor a retained tail exists', async () => { const snapshot = await subscribeSnapshot({ connectionId: 'conn-null-snapshot-no-tail',