Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix: increase paste size limit to 4MB to prevent legitimate large code pastes from being rejected

0xken15ee51efa31654
diff --git a/cli/src/lib/terminalStreamManager.spec.ts b/cli/src/lib/terminalStreamManager.spec.ts
index 992ea6dc6..94796f7e3 100644
--- a/cli/src/lib/terminalStreamManager.spec.ts
+++ b/cli/src/lib/terminalStreamManager.spec.ts
@@ -199,9 +199,16 @@ describe('TerminalStreamManager', () => {
expect(sent.at(-1)?.payload.code).toBe('TERMINAL_PASTE_INVALID')
expect(stream.pastes).toHaveLength(2)
- await manager.handleFrame('web-1', 'terminal_paste', { streamId, text: 'x'.repeat(65 * 1024) })
+ // A real paste of ordinary code (tens/hundreds of KB) must not bounce off a limit sized for one
+ // keystroke chunk — this is the exact regression that froze a real terminal over a normal paste.
+ const ordinaryLargePaste = 'x'.repeat(200 * 1024)
+ await manager.handleFrame('web-1', 'terminal_paste', { streamId, text: ordinaryLargePaste })
+ expect(stream.pastes.at(-1)).toBe(ordinaryLargePaste)
+ expect(stream.pastes).toHaveLength(3)
+
+ await manager.handleFrame('web-1', 'terminal_paste', { streamId, text: 'x'.repeat(5 * 1024 * 1024) })
expect(sent.at(-1)?.payload.code).toBe('TERMINAL_PASTE_INVALID')
- expect(stream.pastes).toHaveLength(2)
+ expect(stream.pastes).toHaveLength(3)
})
it('does not replay pre-snapshot repaint bytes after the authoritative keyframe', async () => {
diff --git a/cli/src/lib/terminalStreamManager.ts b/cli/src/lib/terminalStreamManager.ts
index e493142fd..0a53f32f9 100644
--- a/cli/src/lib/terminalStreamManager.ts
+++ b/cli/src/lib/terminalStreamManager.ts
@@ -15,6 +15,13 @@ const SYNC_INTERVAL_MS = 5_000
const OUTPUT_FLUSH_MS = 8
const OUTPUT_CHUNK_BYTES = 32 * 1024
const INPUT_MAX_BYTES = 64 * 1024
+// A paste is delivered whole, in one frame, unlike ordinary typed input — which the client already
+// caps at 8 KiB per binary frame before INPUT_MAX_BYTES ever matters. Reusing INPUT_MAX_BYTES here
+// made a large-but-entirely-normal clipboard paste (a few hundred lines of real code, tens of KB)
+// bounce off a limit sized for keystrokes and fail the WHOLE stream ("TERMINAL FROZEN") over
+// something that never touched tmux. `tmux paste-buffer`'s stdin-loaded buffer has no comparable
+// size constraint — this is a sanity ceiling against a broken/malicious client, not a real limit.
+const PASTE_MAX_BYTES = 4 * 1024 * 1024
const PAUSE_HIGH_WATERMARK_BYTES = 384 * 1024
const RESUME_LOW_WATERMARK_BYTES = 128 * 1024
const RENDER_STALL_TIMEOUT_MS = 10_000
@@ -432,7 +439,7 @@ export class TerminalStreamManager {
this.sendError(connId, 'TERMINAL_PASTE_INVALID', { streamId: state.streamId })
return
}
- if (Buffer.byteLength(text, 'utf8') > INPUT_MAX_BYTES) {
+ if (Buffer.byteLength(text, 'utf8') > PASTE_MAX_BYTES) {
this.sendError(connId, 'TERMINAL_PASTE_INVALID', { streamId: state.streamId, message: 'paste too large' })
return
}