Repository navigation
perf(sandbox): reuse prepared workspace transport and unchanged packs - #199306
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR skips unchanged workspace packs and forwards worker-prepared compressed mutations without rebuilding them on the Gateway thread. Example: Replace a 100,000-file sandbox baseline after changing one file in the supplied benchmark.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes measurable workspace preparation and transport waste using existing owners, with no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe local workspace store connects sandbox reconciliation to manifest computation workers and the SQLite writer, turning workspace documents into prepared content, committed roots, and published projection facts. flowchart LR
A[Sandbox reconciliation] --> B[Workspace store]
B --> C[Snapshot reader]
C --> D[Manifest computation worker]
D --> B
B --> E[SQLite writer]
E --> F[Committed projection publication]
Technical reviewBest possible solution: Reuse live pack references and prepared mutation facts through the existing snapshot, computation, writer, and publication owners while preserving their settlement contracts. Do we have a high-confidence way to reproduce the issue? Current-main source shows replacement encoding all packs and acceptance inflating and rebuilding prepared mutations; the PR reports baseline-red regressions and real-store measurements, which were inspected but not rerun during this read-only review. Is this the best way to solve the issue? The change follows the smallest complete approach: preserve content and commit invariants while carrying existing prepared facts instead of adding a cache, manager, or competing persistence path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 491c2944f56a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +48, Tests +17, Docs +7, Other +267. Total +339 across 11 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 14, 2026, 6:23 PM ET / 23:23 UTC. |
What Problem This Solves
Large local sandbox baseline replacements repeatedly encode and send unchanged content-addressed directory packs. The Gateway also expands worker-prepared mutations and serializes them again before publication.
User Impact
Workspace preparation and recovery do less CPU and transport work, with unchanged workspace contents, checkpoint/protection semantics, stored pack bytes and tree references. No schema, migration, configuration, or protocol change.
Why This Change Was Made
The existing state reader supplies only the live baseline's reachable pack digests for replacement. The computation worker skips those packs before encoding. Those packs remain protected by the live root; new packs retain the existing preparation-epoch check. Missing packs are rebuilt. No cross-request cache is added.
The computation worker also prepares source-path content and the complete compressed mutation. Main forwards that mutation unchanged and uses its prepared publication header after settlement, including lost-reply recovery. Direct large mutations retain compression because oversized checkpoint receipts must fit the broker's queue budget.
Runtime production code grows by 48 lines to carry the live pack references and prepared publication facts across existing owners. The measurement script is separate tooling. A pure receipt test moved into the existing smaller CAS test file to keep both test files within their line limits; no test coverage was deleted.
Evidence
Acceptance rule, declared in the committed benchmark before measurement: identical roots and stored payloads, fewer preparation requests/bytes, lower CPU/allocation, and no consistent end-to-end regression. The workload alternates a one-file edit through the real worker-backed store, using synthetic contents and 10k/100k paths or the repository's 65,076 tracked path names. This is an owner replacement workload, not a full project-fetch trace.
Mean per refresh (untraced timing; five iterations per side for 10k/repository, ten for 100k in AB then BA order):
Separate sampled-allocation passes, five iterations per side: 100k main-thread allocation 15,002,608 → 14,628,710 bytes/refresh (−2.5%); repository paths 12,686,619 → 11,779,094 (−7.2%). The small 10k main-CPU increase is 0.50 ms; total CPU falls 44%. Main allocation gains are modest compared with the reduction in native transport buffers and total worker CPU.
An untimed diagnostic refresh reports 100k preparation 1,003 → 4 packs, 35,693,352 → 373,915 bytes before deflate, and 9,149,914 → 144,067 compressed bytes. Preparation writes drop 4 → 1, followed by one mutation. Repository preparation drops 2,346 → 3 packs, 27,875,966 → 36,857 raw bytes, 6,877,064 → 12,140 compressed bytes, and 10 → 1 preparation writes. The read remains one owner snapshot per replacement. Already-incremental normal scans retain their existing selected-path behavior.
On current main, manifest/tree construction and pack deflate already run in the Git worker: their main-thread cost in this replacement path is zero. Across the first five 100k refreshes, observed main-thread v8 serialization falls 2.85 → 0.21 ms and mutation inflation 0.48 → 0 ms; synchronous main deflate is zero on both sides. Main thread CPU includes the actual broker and callbacks, not just these timers.
All final tree roots match. Hashes of sorted stored digest/record/children payload rows match exactly across base and candidate:
e19eee2e05e603986e08767014366a246294a94c39c4afcc11125f91b22b0e39(100k) and4cf67e54b24338fa09a6375dc15dbec7cfe906c3e9eaa172e2f20e32ecb6134b(repository).100k main GC totals over the five-refresh arms: 13.35 → 7.90 ms and 13.59 → 4.67 ms; max pauses 5.91 → 6.13 ms and 4.78 → 3.62 ms. Counts are too low for percentile gates. The first timing arms' sampled peak RSS/heap were 1,246/107 → 1,275/107 MiB (100k) and 1,304/100 → 1,196/120 MiB (repository); these are process samples, not a claim of reduced retained memory. One-minute host loads per 100k arm: A/B 20.82/35.60, B/A 20.35/16.12; repository A/B 24.03/32.71. No metric is declared adverse from these short noisy memory windows.
Reproduce with
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/local-workspace-transport.ts --files 100000 --iterations 5; use--files 10000or--files repo, and separate--allocationruns. Baseline:7f7b16cdc243309cc9d78e3aa2c961b68739ff6c.Both final regressions fail on the unchanged baseline: identical replacement still issues preparation requests; prepared observation acceptance rebuilds its mutation. They pass with the fix. Focused worker-environments tests: 46 passed; sandbox tests: 7 passed; real warm-reuse/interrupted-base-refresh scenarios: 2 passed. Existing rollback, expiry, stale revision, lease revocation, legacy conversion, persisted source paths, and lost-reply checks remain covered. The final focused worker test command took 56 s including compiled fixture setup. One earlier attempt was discarded because formatting changed source during fixture compilation.
The export-name guard passed; eager-import and PR-wrapper closure guards passed (24 tests). Changed-file formatting/lint and strict
pnpm tsgo:test:rootplus the matching gateway test typecheck were run. Exact-head CI run 43651776889 passed on2e10ef0151c23004a3685c89d60b2944fda749bd; all 71 reported PR checks passed, with none pending or failed. Review and merge are reserved for the maintainer handoff; no local autoreview was launched under this lane's explicit workflow.No Team load, production-state access, or full Gateway stress campaign was run. This follows the scoped fast-path instruction for removing duplicate preparation/transport work; these owner results do not establish whole-Gateway latency or attribute the production GC bursts to a specific project-fetch caller. Initial/direct mutations still have their existing main-thread preparation path.