Skip to content

perf(sandbox): reuse prepared workspace transport and unchanged packs - #199306

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-local-workspace-transport-20261114
Nov 14, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-local-workspace-transport-20261114

Conversation

@steipete

@steipete steipete commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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):

Workload Main-thread CPU ms Process CPU ms Wall ms Preparation + mutation bytes
10,000 files 6.08 → 6.58 162.98 → 91.86 113.35 → 59.40 915,947 → 23,939
100,000 files 50.17 → 39.54 1,689.15 → 759.15 1,345.64 → 682.95 9,145,594 → 144,783
Repository paths 37.91 → 28.39 1,145.08 → 558.08 876.95 → 433.58 6,866,480 → 12,851

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) and 4cf67e54b24338fa09a6375dc15dbec7cfe906c3e9eaa172e2f20e32ecb6134b (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 10000 or --files repo, and separate --allocation runs. 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:root plus the matching gateway test typecheck were run. Exact-head CI run 43651776889 passed on 2e10ef0151c23004a3685c89d60b2944fda749bd; 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.

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T23:11:38.512856Z 2e10ef0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: M labels Nov 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Preparation encodes 1,003 packs and transfers 9,149,914 compressed bytes.
  • After: Preparation encodes 4 packs and transfers 144,067 compressed bytes, with matching final roots and stored payload hashes.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, apparently correct optimization supported by real owner-boundary measurements and retained regression coverage; evidence remains scoped to the store rather than a shipped Gateway flow.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal transport optimization is outside the shipped-entry-point proof gate; supplied real worker/SQLite measurements exercise replacement and persistence without claiming whole-Gateway latency.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large sandbox baseline replacements spend avoidable CPU and transport work preparing content already protected by the live baseline.
Reason: The maintainer-authored direction has measurable owner-level value, preserves existing behavior, and introduces no configuration, schema, or public API.

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
Reviewed head: 2e10ef0151c23004a3685c89d60b2944fda749bd

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit a25b072 adds src/gateway/worker-environments/local-workspace-cas.ts:38 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a25b072d1684; files: src/gateway/worker-environments/local-workspace-cas.ts)
  • Shakker: Raw commit f2a80d3 adds src/gateway/worker-environments/local-workspace-cas.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f2a80d3a7e49; files: src/gateway/worker-environments/local-workspace-cas.ts)
  • Vincent Koc: Raw commit 240d0ac adds src/gateway/worker-environments/local-workspace-manifest-scan.ts:146 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 240d0ac7e9d3; files: src/gateway/worker-environments/local-workspace-manifest-scan.ts)

PR surface

Source +48, Tests +17, Docs +7, Other +267. Total +339 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 85 37 +48
Tests 2 42 25 +17
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 2 267 0 +267
Total 11 401 62 +339

Preflight source

Source 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

Metric Value Why it matters
Production versus test LOC Production +85/-37, net +48; tests +42/-25, net +17. Production growth carries live pack references and prepared publication facts through existing owners; tests extend existing boundary scenarios and relocate one unchanged receipt test.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a useful, bounded optimization for large sandbox baseline replacements without evidence of an urgent user-facing outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 14, 2026, 6:23 PM ET / 23:23 UTC.

@steipete
steipete merged commit dcf3651 into main Nov 14, 2026
148 of 151 checks passed
@steipete
steipete deleted the steipete/perf-local-workspace-transport-20261114 branch November 14, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant