Files
orca/src/main/daemon/daemon-session-scrollback-window.ts
T
Brennan Benson 9a81874bc1 fix(daemon): restore previously recoverable scrollback from durable history (#14193)
* fix(daemon): restore previously recoverable scrollback from durable history

Keep the 1000-row live daemon window so session count cannot grow the
grid without bound. Rebuild, remount, restart, and reattach now
reconstruct the desktop 5000-row depth from durable history instead of
compacting that live window.

STA-4091

* fix(daemon): bound durable snapshot replay

* fix daemon history reanchor after checkpoint failure

* fix daemon checkpoint continuity on reconnect

* test assert live scrollback write succeeds

* fix(terminal): preserve incremental restore continuity

* fix(terminal): retain live history after restore loss
2026-08-13 05:09:12 -07:00

25 lines
1.3 KiB
TypeScript

const DAEMON_SESSION_SCROLLBACK_ENV_VAR = 'ORCA_DAEMON_SESSION_SCROLLBACK_ROWS'
// Why a flat live window and not full renderer depth: retained grid is the daemon's dominant heap
// term and session count is unbounded — a host owning 100+ terminals at full depth retained ~1 GB
// of grid and was OOM-killed, taking every session it owned with it. A terminal the user has open
// scrolls its full live renderer buffer. Rebuilds (reload, remount, restart, remote attach) restore
// from durable history at DAEMON_RESTORE_SCROLLBACK_ROWS, not this live RAM window.
export const DAEMON_SESSION_SCROLLBACK_ROWS = 1000
// Why: keep any override within sane terminal bounds — 0 would lose the visible screen's context and
// huge values silently reintroduce the unbounded-retention failure this window exists to prevent.
const MIN_OVERRIDE_ROWS = 100
const MAX_OVERRIDE_ROWS = 5000
export function resolveDaemonSessionScrollbackRows(env: NodeJS.ProcessEnv = process.env): number {
const raw = env[DAEMON_SESSION_SCROLLBACK_ENV_VAR]?.trim()
if (!raw || !/^\d+$/.test(raw)) {
return DAEMON_SESSION_SCROLLBACK_ROWS
}
const parsed = Number(raw)
if (!Number.isSafeInteger(parsed) || parsed < MIN_OVERRIDE_ROWS || parsed > MAX_OVERRIDE_ROWS) {
return DAEMON_SESSION_SCROLLBACK_ROWS
}
return parsed
}