Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/proxy-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ export function attachProxyUpgradeHandler(server: http.Server): void {

proxySocket.on('error', (err) => {
log.warn({ err, targetPort, path: targetPath }, 'WebSocket proxy connection failed')
if (socket.writable) {
socket.write('HTTP/1.1 502 Bad Gateway\r\nContent-Type: text/plain\r\n\r\nExtension server on port ' + targetPort + ' is unavailable\r\n')
}
Comment on lines +209 to +211
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict 502 writes to pre-upgrade failures only

The new proxySocket error handler always writes an HTTP 502 response whenever the client socket is writable, but this handler also runs for errors that can happen after the WebSocket handshake/piping is already established (for example if the extension process restarts mid-session). In that state, sending an HTTP status line into an active WebSocket stream corrupts the protocol and can produce noisy disconnect/retry behavior; the safe behavior is to send 502 only before upgrade bytes have been relayed, and otherwise just close/destroy the socket.

Useful? React with 👍 / 👎.

socket.destroy()
})

Expand Down
6 changes: 3 additions & 3 deletions server/terminal-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { getOpencodeEnvOverrides, resolveOpencodeLaunchModel } from './opencode-
import { generateMcpInjection, cleanupMcpConfig } from './mcp/config-writer.js'

const MAX_WS_BUFFERED_AMOUNT = Number(process.env.MAX_WS_BUFFERED_AMOUNT || 2 * 1024 * 1024)
const DEFAULT_MAX_SCROLLBACK_CHARS = Number(process.env.MAX_SCROLLBACK_CHARS || 64 * 1024)
const DEFAULT_MAX_SCROLLBACK_CHARS = Number(process.env.MAX_SCROLLBACK_CHARS || 512 * 1024)
const MIN_SCROLLBACK_CHARS = 64 * 1024
const MAX_SCROLLBACK_CHARS = 2 * 1024 * 1024
const APPROX_CHARS_PER_LINE = 200
const MAX_SCROLLBACK_CHARS = 4 * 1024 * 1024
const APPROX_CHARS_PER_LINE = 300
const MAX_TERMINALS = Number(process.env.MAX_TERMINALS || 50)
const DEFAULT_MAX_PENDING_SNAPSHOT_CHARS = 512 * 1024
const OUTPUT_FLUSH_MS = Number(process.env.OUTPUT_FLUSH_MS || process.env.MOBILE_OUTPUT_FLUSH_MS || 40)
Expand Down
2 changes: 1 addition & 1 deletion server/terminal-stream/replay-ring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type ReplayFrame = {
at: number
}

export const DEFAULT_TERMINAL_REPLAY_RING_MAX_BYTES = 256 * 1024
export const DEFAULT_TERMINAL_REPLAY_RING_MAX_BYTES = 1024 * 1024

function resolveMaxBytes(explicitMaxBytes?: number): number {
if (typeof explicitMaxBytes === 'number' && Number.isFinite(explicitMaxBytes) && explicitMaxBytes > 0) {
Expand Down
2 changes: 1 addition & 1 deletion shared/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ export function createDefaultServerSettings(options: SettingsDefaultsOptions = {
autoKillIdleMinutes: 180,
},
terminal: {
scrollback: 5000,
scrollback: 10000,
},
panes: {
defaultNewPane: 'ask',
Expand Down
4 changes: 2 additions & 2 deletions test/unit/server/production-edge-cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ describe('TerminalRegistry Production Edge Cases', () => {
emitData(largeChunk)
}

// Buffer should be capped at DEFAULT_MAX_SCROLLBACK_CHARS (64KB default)
// Buffer should be capped at DEFAULT_MAX_SCROLLBACK_CHARS (512KB default)
const snapshot = record.buffer.snapshot()
expect(snapshot.length).toBeLessThanOrEqual(64 * 1024)
expect(snapshot.length).toBeLessThanOrEqual(512 * 1024)
})

it('idle monitor timer is created and runs', () => {
Expand Down
Loading