Skip to content

Commit 14c0225

Browse files
committed
fix(server): quiet terminals are still snapshotted every 30th poll tick
Bounds how long a child started with no terminal input or output goes unseen.
1 parent 0f91bbe commit 14c0225

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎apps/server/src/terminal/Manager.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,10 @@ it.layer(
11761176
assert.isTrue(finished.type === "activity" && !finished.hasRunningSubprocess);
11771177
yield* TestClock.adjust("4 seconds");
11781178
assert.equal(snapshots, 9);
1179+
1180+
// A quiet shell is still snapshotted on every 30th tick.
1181+
yield* TestClock.adjust("30 seconds");
1182+
assert.equal(snapshots, 10);
11791183
}).pipe(Effect.provide(TestClock.layer())),
11801184
);
11811185

‎apps/server/src/terminal/Manager.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ const MAX_HISTORY_CHUNK_LENGTH = 16 * 1024;
9494
const DEFAULT_PERSIST_DEBOUNCE_MS = 250;
9595
const DEFAULT_SUBPROCESS_POLL_INTERVAL_MS = 1_000;
9696
const MAX_SUBPROCESS_POLL_INTERVAL_MS = 60_000;
97+
// Quiet sessions are still snapshotted on every 30th poll tick, so a child started
98+
// with no terminal input or output is found within that bound.
99+
const QUIET_SUBPROCESS_SNAPSHOT_EVERY_TICKS = 30;
97100
const DEFAULT_PROCESS_KILL_GRACE_MS = 1_000;
98101
const DEFAULT_MAX_RETAINED_INACTIVE_SESSIONS = 128;
99102
const DEFAULT_OPEN_COLS = 120;
@@ -2391,9 +2394,10 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
23912394
// Running sessions the last snapshots found without a child process, with the
23922395
// activity mark they had. A shell at its prompt starts a child only after input
23932396
// or output, so while every running session is quiet the poll skips the
2394-
// process-table snapshot. Requiring two idle snapshots covers a child forked
2395-
// just after the snapshot that followed the input.
2397+
// process-table snapshot on all but every 30th tick. Requiring two idle
2398+
// snapshots covers a child forked just after the snapshot that followed the input.
23962399
let quietSessions = new Map<string, QuietTerminalSession>();
2400+
let skippedQuietTicks = 0;
23972401
const isQuiet = (session: TerminalSessionState & { pid: number }) => {
23982402
const quiet = quietSessions.get(toSessionKey(session.threadId, session.terminalId));
23992403
return (
@@ -2412,9 +2416,17 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
24122416
session.status === "running" && Number.isInteger(session.pid),
24132417
);
24142418

2415-
if (runningSessions.every(isQuiet)) {
2419+
if (runningSessions.length === 0) {
24162420
return true;
24172421
}
2422+
if (
2423+
runningSessions.every(isQuiet) &&
2424+
skippedQuietTicks < QUIET_SUBPROCESS_SNAPSHOT_EVERY_TICKS - 1
2425+
) {
2426+
skippedQuietTicks += 1;
2427+
return true;
2428+
}
2429+
skippedQuietTicks = 0;
24182430

24192431
const inspectorOption = yield* acquireSubprocessInspector.pipe(
24202432
Effect.asSome,

0 commit comments

Comments
 (0)