Repository navigation
perf(terminal): bound and de-synchronize cold-restore replay on the main process - #9990
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughCold restore detection now uses asynchronous filesystem access and serialized replay admission. Replay output is written through budgeted, UTF-16-safe chunks with yielding, while header-only checkpoint restores bypass replay. Sticky cold-restore payloads use a byte-bounded LRU cache with cleanup callbacks. Adapter and restore tests now await detection, and new tests cover replay serialization, checkpoint-only bypass, cache eviction, and renderer acknowledgment cleanup. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 097a8b3c-cf08-48af-ab22-07c7d95ba498
📒 Files selected for processing (10)
config/reliability-gates.jsoncsrc/main/daemon/cold-restore-payload-cache.test.tssrc/main/daemon/cold-restore-payload-cache.tssrc/main/daemon/cold-restore-replay-writer.tssrc/main/daemon/daemon-pty-adapter.test.tssrc/main/daemon/daemon-pty-adapter.tssrc/main/daemon/hibernation-cold-restore-repro.test.tssrc/main/daemon/history-reader.test.tssrc/main/daemon/history-reader.tssrc/main/daemon/terminal-history-incremental-restore.test.ts
…ory file limits Semantic resolutions where #10179 bounded the same reads this PR made asynchronous: - add async variants of the bounded terminal-history readers and use them for checkpoint.json, output.log, and legacy scrollback.bin so the reads are both off-thread and size/JSON-structure capped - keep the header-only stat bypass ahead of the replay semaphore; the bounded log read now rejects oversized logs inside the slot - daemon-pty-adapter keeps the shared ColdRestorePayload type from cold-restore-payload-cache alongside main's PtyProcessListAdmission - await the now-async detectColdRestore in main's history-reader-memory tests - extract the legacy scrollback restore path into terminal-history-legacy-scrollback-restore.ts to stay within max-lines
This reverts commit 8f40ddf (#10179). Rebased on current main. The revert applied cleanly across the vast majority of the 1,626-file PR; the remaining work was preserving PRs that had been built on top of #10179 after it merged. All are preserved: - #9990 perf(terminal): cold-restore replay - #10213 fix(codex): TUI settings promotion - #10135 fix(mobile): images in native chat - #9387 fix(status-bar): Resource Manager badge + concurrent listSessions - #9853 fix(app): bound wake/quit paths (phone-session-ended freeze) - #10237 fix(claude-accounts): quote claude path for Windows (kept shell:false) Because those PRs were written against helper modules/APIs that #10179 introduced, the minimal, typecheck-verified closure they depend on is kept so the tree builds and every later-PR test passes: - bounded file/JSON readers used by #10213/#9990 (agent-state-file-reader, node-bounded-file-reader, json-text-structure-limit, terminal-history limits) - claimed-agent-pty-owner cap API + pty:listSessions admission (#9990/#9387) - the mobile-E2EE outbound-memory-budget subsystem #9853 builds on (e2ee-channel, mobile-e2ee-*, ws-outbound-backpressure-queue, remote-runtime-request-frames/-memory-limits, map-with-concurrency, e2ee-crypto) Everything else #10179 added (~555 files) is deleted; every file it modified elsewhere is restored to its pre-#10179 state. Verified: root typecheck (node+cli+web), mobile typecheck, full root test suite, full mobile test suite, oxlint, localization catalog + coverage, reliability gates, max-lines ratchet, and the CLI emit build all pass. Two checks fail only locally and fail identically on clean origin/main (this clone's git-tag namespace for verify:skill-bundle-manifest; an inherited GIT_CONFIG_* env for one relay test) — both pass on a clean CI environment. Co-authored-by: Orca <[email protected]>
…ain process (stablyai#9990) * fix(terminal): bound cold restore replay * fix(terminal): bound cold restore replay slices * perf(terminal): avoid rescanning cold restore payloads
Fixes #9971
Follow-up from the #9441 / #9446 investigation.
Problem
On terminal reattach during startup restore, the main process synchronously replayed up to ~5 MB of persisted history per session through a
HeadlessEmulator, with no concurrency bound, and retained multi-MB snapshot/scrollback ANSI strings per session. A profile with dozens of restorable histories could stall startup for seconds and retain hundreds of MB.The first implementation yielded only between persisted batches. A single batch or checkpoint seed can itself exceed the event-loop budget, so that still allowed the original long main-thread block. It also made header-only sleep/final-checkpoint restores wait behind the global replay semaphore even though they have no replay work.
Fix
Reliability contract
terminal-performance.cold-restore-replay-budget— persisted output remains correct while scratch replay concurrency, per-turn replay work, and retained sticky payload bytes remain bounded; header-only restores do not queue behind replay work.setImmediateduring two large single-batch restores, require exactly one admitted replay/yield at a time, preserve an emoji split at the slice boundary, and require a concurrent header-only checkpoint restore to complete. Cache tests cover LRU/oversize behavior and ACK cleanup.config/reliability-gates.jsonc.Verification
pnpm run typecheckpassed.pnpm run lintreaches a pre-existing unrelated switch-exhaustiveness error insrc/renderer/src/components/skills/skill-freshness-group.tsx:101; changed-file lint is clean.