Bulk hydrate shell snapshots in the web store#2780
Conversation
Build shell snapshot thread indexes and records in one pass instead of routing every shell thread through the single-thread writer. The old snapshot path repeatedly spread growing thread maps, which made 10k-thread startup spend seconds in store hydration. 10k Chrome first-load click profile, fresh copied fixture, 5 runs, median: | metric | previous | after | delta | |---|---:|---:|---:| | initial render | 5409.939 ms | 3630.273 ms | -1779.666 ms (-32.9%) | | click settle | 9804.401 ms | 9687.877 ms | -116.525 ms (-1.2%) | | total | 15216.020 ms | 13357.292 ms | -1858.729 ms (-12.2%) | | FunctionCall | 3287.106 ms | 1195.416 ms | -2091.690 ms (-63.6%) | | RunTask | 4670.482 ms | 2682.802 ms | -1987.680 ms (-42.6%) | | UpdateLayoutTree | 702.926 ms | 685.519 ms | -17.407 ms (-2.5%) | Verification: bun fmt; bun lint; bun typecheck; bun run test.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors shell snapshot syncing to build thread indexes/maps in a single pass (with deduplication) while retaining existing per-thread detail slices, and adds tests to lock in the intended behavior.
Changes:
- Replaces incremental
writeThreadShellStateupdates with direct construction ofthreadIds,threadIdsByProjectId, and per-thread shell/session/summary records during shell snapshot sync. - Retains existing thread-scoped detail records only for threads that remain present in the snapshot.
- Adds Vitest coverage for shell snapshot syncing, including malformed duplicate thread entries.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/web/src/store.ts | Builds thread indices and shell-related records directly from the shell snapshot and retains thread-scoped detail slices via filtering. |
| apps/web/src/store.test.ts | Adds tests for shell snapshot sync behavior (indexing, retention, and deduplication). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ApprovabilityVerdict: Approved Performance refactor that builds shell snapshot state in a single pass rather than iteratively. The change is internal to state construction, uses secure null-prototype records, and includes comprehensive tests. No runtime behavior changes. You can customize Macroscope's approvability policy. Learn more. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
What Changed
Changed shell snapshot sync from N single-thread writes into one bulk pass that builds thread IDs, project indexes, shell records, session records, turn state, and sidebar summaries together.
Why
The old path repeatedly spread growing maps while hydrating large snapshots. On the synthetic 10,000-thread fixture, that made startup spend seconds in web store hydration.
Chrome first-load click profile against a synthetic 10,000-thread home (100 projects x 100 threads, 0 activities/thread, projected seed). Each side used 5 measured runs, and each run seeded a fresh synthetic home before Chrome opened
Startup Thread 29/69. Table shows medians:UI Changes
No visual UI changes.
Checklist
Verification:
bun fmtbun lintbun typecheckbun run testNote
Medium Risk
Moderate risk because it rewrites
syncEnvironmentShellSnapshotto rebuild multiple thread-related indices/maps in one pass; mistakes could drop/reshuffle thread bookkeeping or sidebar data during bootstrap. Adds tests and keeps detail slices only for threads present, but changes touch core state hydration behavior.Overview
Shell snapshot hydration is rewritten to run as a single bulk pass.
syncEnvironmentShellSnapshotnow buildsthreadIds,threadIdsByProjectId,threadShellById,threadSessionById,threadTurnStateById, andsidebarThreadSummaryByIddirectly while iteratingsnapshot.threads, instead of repeatedly applying per-thread writes.During sync it deduplicates duplicate thread IDs (keeps first occurrence), retains existing per-thread detail slices only for threads still present in the snapshot, and initializes the new thread maps with
Object.create(null)to safely accept server-provided IDs like__proto__.Adds focused tests for bulk shell sync covering project indexing, bootstrap completion, detail-slice retention/removal, deduplication behavior, and prototype-pollution-style IDs.
Reviewed by Cursor Bugbot for commit 7392fca. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Bulk hydrate shell snapshots in the web store with deduplication and safe key handling
syncEnvironmentShellSnapshotin store.ts to build all thread maps in a single pass over the snapshot rather than iterating and callingwriteThreadShellStateper thread.threadIds,threadIdsByProjectId, and shell-derived maps in first-seen order.createRecord(null-prototype objects viaObject.create(null)) so keys like__proto__are stored verbatim without triggering prototype pollution.Macroscope summarized 7392fca.