Repository navigation
Bound hot-terminal full-snapshot checkpoints with a per-session cooldown - #7088
Conversation
A streaming session (build logs, yes) re-triggered a full multi-MB checkpoint.json tmp+rename on every 5s tick via pending-buffer overflow or the 5MB log cap - hundreds of MB/min of disk writes from one busy terminal, and the dominant Orca-generated filesystem event volume. Cap/overflow-triggered full snapshots now honor a 45s per-session cooldown: while cooling down the session's checkpoint work is deferred entirely (no takePendingOutput RPC, no increment appends - appending past a dropped range would leave a hole in the log, so the on-disk state stays a consistent, merely stale, prefix) and the session stays dirty so the timer retries until the cooldown expires. Final/teardown checkpoints (quit, sleep, clean disconnect) bypass the cooldown, and a session's first-ever snapshot is never delayed, so cold-restore fidelity changes only for hot sessions mid-stream: at most 45s of tail scrollback staleness after a hard crash. Co-authored-by: Orca <[email protected]>
From adversarial review of the cooldown commit: - Warm reattach by an adapter that was not already managing the session now forces a full-snapshot re-anchor: the previous adapter may have drained daemon records it never persisted (deferred hot-session tick), and appending past that unknown drain point would put a seq gap in the log, which the restore reader rejects wholesale. This also closes the pre-existing (previously ~ms-wide) drain-vs-persist crash window. - Cold-restore re-anchor clears any cooldown inherited from the pre-crash generation (daemon respawn within one adapter), so the revived session's first snapshot is never deferred. - Exit-event routing clears lastFullCheckpointAt (reused ptyIds must not inherit a dead session's cooldown); fanoutSyntheticExits now clears sessionsNeedingFullCheckpoint for consistency. - Backward wall-clock jumps count as expired instead of extending the deferral. Co-authored-by: Orca <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis change introduces a cooldown mechanism for full-snapshot checkpointing in DaemonPtyAdapter, tracked via a per-session Sequence Diagram(s)sequenceDiagram
participant Worker as Checkpoint Worker
participant Adapter as DaemonPtyAdapter
participant Snapshot as takeSnapshotAndCheckpoint
Worker->>Adapter: checkpointSession(sessionId, opts)
alt opts.final or no prior checkpoint
Adapter->>Snapshot: take full snapshot
Snapshot-->>Adapter: success
Adapter->>Adapter: lastFullCheckpointAt.set(sessionId, now)
Adapter-->>Worker: 'done'
else cooling down
Adapter->>Adapter: sessionsNeedingFullCheckpoint.add(sessionId)
Adapter-->>Worker: 'deferred'
end
Worker->>Worker: mark session completed only if 'done'
Compact MetadataType: Enhancement/Bug fix Related issues: None referenced Poem A rabbit watched the snapshots race too fast, ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…own (stablyai#7088) * Bound hot-terminal full-snapshot checkpoints with a per-session cooldown A streaming session (build logs, yes) re-triggered a full multi-MB checkpoint.json tmp+rename on every 5s tick via pending-buffer overflow or the 5MB log cap - hundreds of MB/min of disk writes from one busy terminal, and the dominant Orca-generated filesystem event volume. Cap/overflow-triggered full snapshots now honor a 45s per-session cooldown: while cooling down the session's checkpoint work is deferred entirely (no takePendingOutput RPC, no increment appends - appending past a dropped range would leave a hole in the log, so the on-disk state stays a consistent, merely stale, prefix) and the session stays dirty so the timer retries until the cooldown expires. Final/teardown checkpoints (quit, sleep, clean disconnect) bypass the cooldown, and a session's first-ever snapshot is never delayed, so cold-restore fidelity changes only for hot sessions mid-stream: at most 45s of tail scrollback staleness after a hard crash. Co-authored-by: Orca <[email protected]> * Harden checkpoint cooldown against crash-boundary and reuse edges From adversarial review of the cooldown commit: - Warm reattach by an adapter that was not already managing the session now forces a full-snapshot re-anchor: the previous adapter may have drained daemon records it never persisted (deferred hot-session tick), and appending past that unknown drain point would put a seq gap in the log, which the restore reader rejects wholesale. This also closes the pre-existing (previously ~ms-wide) drain-vs-persist crash window. - Cold-restore re-anchor clears any cooldown inherited from the pre-crash generation (daemon respawn within one adapter), so the revived session's first snapshot is never deferred. - Exit-event routing clears lastFullCheckpointAt (reused ptyIds must not inherit a dead session's cooldown); fanoutSyntheticExits now clears sessionsNeedingFullCheckpoint for consistency. - Backward wall-clock jumps count as expired instead of extending the deferral. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
Follow-up to #7068 (the fseventsd load audit): this addresses the top deferred finding — terminal-history checkpoints are Orca's dominant self-generated disk write source.
Problem
The daemon adapter checkpoints dirty PTY sessions every 5s. For calm sessions that's a cheap increment append. But a streaming session (build logs, test runners,
yes-style floods) hits the full-snapshot path on nearly every tick, two ways:takePendingOutputoverflow: >2MB of output accumulated within one 5s tick, orneeds-checkpoint) — recurring every ~5MB of output.Each full snapshot is a multi-hundred-KB-to-multi-MB
checkpoint.jsonwrite + rename +output.logheader rewrite — up to 12×/min per hot session, i.e. hundreds of MB/min of disk writes from a single busy terminal, and the largest Orca-generated contribution to system-wide filesystem event volume (see #7068 for why that matters on macOS).Live baseline on an affected machine (146-worktree workload, quiet evening load): 72 file touches and ~1.3MB growth per 2 minutes in
terminal-history/, 231MB accumulated across 2,851 files.Fix
Cap/overflow-triggered full snapshots now honor a 45s per-session cooldown:
takePendingOutputRPC, no increment appends. Appending past a dropped range would leave a hole in the log, so skipping keeps the on-disk state a consistent (merely stale) prefix that the eventual full snapshot re-anchors from the live emulator.An independent adversarial review of the first commit traced six invariants through the restore/reattach/respawn paths; the second commit hardens the edges it found:
Evidence
Unit (asserted in
daemon-pty-adapter.test.ts): 24 consecutive hot-session ticks (~2 simulated minutes of overflow) produce 1 full snapshot and zero further daemon RPCs while cooling down; previously every tick produced one. Final checkpoints bypass; log-cap deferrals follow the same cycle.Live (dev build, real daemon,
yesflooding a PTY): first overflow snapshot lands immediately (423KBcheckpoint.json), then the session defers —output.logstays at its 9-byte header instead of cycling 5MB generations, andcheckpoint.jsonrewrites at the cooldown cadence instead of every 5s. Steady-state hot-session write volume drops from ~5MB/min (12 × 423KB) plus ~1MB/min log cycling to ~0.6MB/min — ~9× less, with proportionally fewer filesystem events.The live run also exercised an unplanned failure mode: the daemon client connection dropped mid-stream, the deferred session retried each tick (surfaced as
[history] checkpoint failed ... Not connected, identical to old behavior under RPC failure), and the flagged snapshot landed on reconnect.Trade-off
For a session that is mid-stream when the machine hard-crashes (daemon dies too — power loss, kernel panic), cold restore can be up to 45s more stale for that session's tail scrollback. Warm reattach (daemon survives, e.g. app restart), quit/sleep-time final checkpoints, and calm sessions are unaffected. Increment appends for normal typing/output cadence are untouched.
Notes
pty-subprocess.test.tshas one WSL env-import test failing onmainat this base commit — pre-existing, unrelated.Made with Orca 🐋