Skip to content

perf(sandbox): reduce workspace reconcile payloads - #199524

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-workspace-reconcile-payload-20261115
Nov 15, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-workspace-reconcile-payload-20261115

Conversation

@steipete

@steipete steipete commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A small sandbox edit still retransmits an entire changed directory pack during reconciliation, adding allocation and pause time even after #199306 skips unchanged packs.

User Impact

Reconciliations send much smaller pack preparations. File contents, tree digests, conflict handling, acceptance, recovery, and persisted pack bytes stay unchanged. There is no schema, index, migration, configuration, or durability change.

Why This Change Was Made

The scan owner now carries predecessor pack references and changed treap records, including changed child references. The existing SQLite writer reconstructs the complete pack in its existing transaction. Initial publication and verified repair still supply full packs because no persisted predecessor is available. Missing predecessors use the existing baseline-repair error contract.

Payload telemetry now distinguishes 13 fixed localWorkspace.* operation names in request_class; unknown suffixes retain the bounded family label. No workspace or path labels are introduced.

Runtime production delta: +108 lines (+95 for delta preparation/reconstruction, +13 fixed metric labels). This growth preserves the current complete-pack storage contract instead of changing the schema. The scan caller loses its duplicate pack-selection logic. Benchmark instrumentation adds 91 net lines; the shared perf README is unchanged.

Evidence

Synthetic owner-boundary reproduction on baseline c149398aacc4e9bb98e2398024b49a672668bdd4: 20,000 flat-directory files × 12,000 bytes (240 MB), 10,001 synthetic session rows, one changed file per reconcile, real filesystem/projection/SQLite owners. Only container pause/inspect I/O is simulated. This is not a built Gateway, native Podman/btrfs, or live-server result.

Three pairs, 20 reconciles per arm per process (60 per revision), ordered ABBA then one predeclared BA pair for mixed timing signs. All arms are included. Work counts and payload bytes are deterministic; timings are noisy on the shared Mac.

Per reconcile, mean Base Candidate Delta
All localWorkspace writer payload 3.114 MB 0.544 MB -82.52%
Pack preparation payload 2571324.350 B 1964.400 B -99.92%
Main-isolate allocation 18.713 MB 18.152 MB -3.00%
Main-thread CPU 36.165 ms 35.946 ms -0.61%
Process CPU, including workers 733.775 ms 577.282 ms -21.33%
Guest pause 440.967 ms 359.583 ms -18.46%
Reconcile wall time 592.551 ms 559.918 ms -5.51%

Packing falls from 20,001 to 12 records. Both revisions perform 9 content hashes/reads, 108,000 bytes read, and 19,999 fingerprint hits per reconcile, including patch/capture/verification. The residual ~542 KB of mutation traffic is dominated by checkpoint/fingerprint publication; it is preserved. The complete directory pack is still written in SQLite.

The reported production-scale two-minute pause did not reproduce locally. Scanning/preparation dominates this fixture; filesystem/platform/host differences remain unqualified. Main CPU is approximately neutral. The mixed-sign timing arms below do not establish a consistent pause-speed guarantee.

Exclusive phase, mean ms/reconcile Base Candidate
operation 0.125 0.142
scan 411.169 323.977
staging 29.290 35.096
patch 68.949 100.320
apply 8.384 9.607
preflight 4.420 6.660
materialization 26.147 34.151
capture 0.884 1.026
acceptance 3.564 4.499

Patch/application code is unchanged. Candidate arm 3 was slower across several unchanged phases at higher host load; no window was discarded. Per-phase wall times are context, while the complete reconcile and pause totals above include that arm. No adverse classification or rejection is based on these noisy subphase timings.

Every arm: CPU, allocation, pause, GC, event loop, memory, worker execution, and host load
Arm CPU ms/op Allocation MB/op Pause ms/op GC ms/min Loop p99 ms (samples) RSS / heap MiB Worker execution mean / max ms (samples) Host load start → end
final-1-base 38.10 19.30 502.12 93.02 101.38 (1188) 1238.9 / 156.4 8.08 / 455.53 (200) 8.43 → 8.32
final-2-final 34.96 18.62 323.26 62.27 105.97 (907) 1256.4 / 160.4 5.78 / 45.68 (200) 10.70 → 10.01
final-3-final 40.56 18.29 468.24 56.71 103.48 (1277) 1130.3 / 161.6 4.96 / 45.78 (200) 13.06 → 13.86
final-4-base 35.27 18.69 405.85 99.75 102.76 (1003) 1296.7 / 154.5 4.05 / 30.81 (200) 12.51 → 11.51
final-5-final 32.32 17.54 287.25 68.30 107.28 (810) 1297.2 / 160.6 4.85 / 33.14 (200) 7.44 → 7.46
final-6-base 35.12 18.15 414.93 102.52 102.24 (1014) 1315.1 / 154.5 4.33 / 29.76 (200) 7.27 → 7.44

Allocation uses the main-isolate V8 total allocation counter, including background work, excluding worker heaps and external buffers. Worker execution is executeFinished - executeStarted for all localWorkspace requests, rather than client round-trip time. RSS includes worker isolates. Loop delay includes synchronous fixture mutation subprocess startup and is not Gateway latency. Low-sample tails and major-GC counts are context; no GC/max-pause rejection was made.

GC details by V8 kind (count / total ms / maximum ms):

  • final-1-base: kind 4: 5 / 21.855 / 4.768, kind 8: 5 / 1.607 / 0.384
  • final-2-final: kind 1: 3 / 2.634 / 0.892, kind 4: 2 / 8.971 / 4.695, kind 8: 2 / 0.801 / 0.411
  • final-3-final: kind 1: 3 / 2.660 / 0.910, kind 4: 2 / 12.472 / 8.096, kind 8: 2 / 0.799 / 0.410
  • final-4-base: kind 4: 5 / 20.114 / 4.820, kind 8: 5 / 1.572 / 0.385
  • final-5-final: kind 1: 3 / 2.828 / 0.984, kind 4: 2 / 8.451 / 4.482, kind 8: 2 / 1.088 / 0.565
  • final-6-base: kind 4: 5 / 20.908 / 5.303, kind 8: 5 / 1.664 / 0.387

The extended incremental-pack regression fails on baseline for edit and both deletion shapes: 15,026 / 9,234 / 14,909 bytes, against the 6,000-byte budget. The candidate passes while comparing records_json and children_json byte-for-byte with a full rebuild, retaining equal roots through acceptance and GC. Existing missing-pack recovery tests exposed an error-contract mismatch during development; preserving the established missing-baseline error fixed it.

Validation: 46 focused CAS/scan/store tests and 5 SQLite client tests passed; the broader owner/projection run had 120 passing and 2 skipped tests, with two recovery failures then repaired and rerun successfully (2 passing). Closure guards, export-name collision check, changed-file lint/format, pnpm tsgo:test:root, and matching gateway/infra test typechecks passed. Exact-head PR CI passed on aa7bb143a6c5c825c5643291312a295f987c1c73, including all PostgreSQL conformance shards and PostgreSQL 16 smoke. A 29-line allocation record covers the regression growth. The closure guard also found the newly eager tree module missing from the wrapper extraction inventory; the inventory was updated and both closure files now pass (24 tests).

Reproduction (same committed harness for both frozen sources):

node --import ./scripts/tsx.mjs scripts/perf/local-workspace-checkpoint-measure.ts \
  --freeze-source .local/source-base --revision <base-sha> --fingerprint-import
node --import ./scripts/tsx.mjs scripts/perf/local-workspace-checkpoint-measure.ts \
  --freeze-source .local/source-candidate --fingerprint-import
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/local-workspace-checkpoint-measure.ts \
  --source-root .local/source-base --output .local/reconcile-fixture \
  --mode reconcile --requests 20 --burst 1 --files 20000 --file-bytes 12000 \
  --reconcile-traffic --fingerprint-import

For subsequent arms use the same output with --reuse-fixture --report <arm>.json and alternate --source-root. These reused, deterministic fixtures measure warm reconciliation; they do not qualify cold pack-insertion I/O. Keep the default TMPDIR. Source hashes, phase samples, request bytes, worker execution timings, hash/pack counts and memory are in each report.

No Testbox or Team load was used. No 10-minute Gateway stress campaign was run. This reconciliation transport change has direct filesystem/worker proof; whole-Gateway behavior and native-container pause duration remain unqualified. Independent review is pending.

@clawsweeper

clawsweeper Bot commented Nov 15, 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 15, 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-15T08:31:05.871313Z aa7bb14 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 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR sends incremental workspace pack records to the SQLite writer, which reconstructs complete packs, and adds bounded operation-level telemetry.

Example: Reconcile one changed file in the reported 20,000-file workspace fixture.

  • Before: Pack preparation transmits about 2.57 MB and packs 20,001 records.
  • After: Pack preparation transmits about 1.96 KB and packs 12 records while retaining complete persisted packs.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, apparently correct optimization with meaningful production-owner measurements and storage regressions; proof remains scoped to an owner harness.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): The supplied benchmark exercises real filesystem, projection, Git-worker transport, and SQLite owners after the change, reporting reduced preparation bytes with unchanged hash counts; container pause/inspect I/O is simulated, so it establishes transport savings rather than native-container or 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: Small sandbox edits can incur large reconciliation transport and packing costs in wide directories.
Reason: The maintainer-authored direction has measurable payload savings, retains existing workspace semantics, and explicitly limits timing claims to the measured workload.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed optimization addresses remaining reconciliation overhead and preserves the existing storage contract. No actionable correctness or security findings were identified; exact-head CI remains pending.

Priority: P2
Reviewed head: aa7bb143a6c5c825c5643291312a295f987c1c73

Before merge

None.

Findings

None.

Agent review details

How this fits together

The workspace scanner compares live files with the accepted manifest, prepares immutable content, and sends it through the existing worker transport; SQLite stores complete packs before checkpoint acceptance publishes their root.

flowchart LR
  A[Workspace files] --> B[Manifest scanner]
  B --> C[Changed records and predecessor references]
  C --> D[SQLite worker transport]
  D --> E[Existing writer transaction]
  F[Persisted predecessor packs] --> E
  E --> G[Complete immutable packs]
  G --> H[Checkpoint acceptance]
Loading

Technical review

Best possible solution:

Carry incremental records through the existing preparation path and reconstruct complete packs in the existing SQLite writer.

Do we have a high-confidence way to reproduce the issue?

Current-main source confirms that a changed directory still serializes its complete sibling pack; the PR supplies a repeatable owner-boundary workload, which was inspected but not executed during this read-only review.

Is this the best way to solve the issue?

The change follows the existing ownership boundaries, preserves complete stored packs and deletion promotion, and removes duplicate caller-side pack selection; the added --reconcile-traffic switch is benchmark instrumentation only.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f0e04c2f13af.

Provenance checked

  • Workspace pack preparation and storage changes intended behavior with a stated reason (a25b072: Content-addressed directory packs reduced duplicated inventories while preserving immutable roots and bounded preparation transactions.)
  • Deletion and promoted directory roots keeps the original intent (f2a80d3: Removing a sibling-tree root can promote an unchanged child whose standalone pack must be prepared before acceptance.)
  • Unchanged-pack reuse keeps the original intent (dcf3651: Avoid encoding unchanged reachable packs and preserve already prepared publication payloads across existing workers.)
  • Bounded worker request attribution keeps the original intent (60c989e: Identify worker operation costs without exposing caller-controlled command suffixes or introducing unbounded labels.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +108, Tests +29, Docs +4, Other +94. Total +235 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 131 23 +108
Tests 2 30 1 +29
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 3 98 4 +94
Total 10 263 28 +235

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 regression growth production +108 net lines; tests +29 net lines The production growth implements delta preparation and reconstruction without changing persisted format; the tests extend existing storage and telemetry contracts.

Labels

Label changes:

  • add P2: This is a bounded performance improvement with measured transport savings and no established urgent availability regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a bounded performance improvement with measured transport savings and no established urgent availability regression.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 15, 2026, 3:42 AM ET / 08:42 UTC.

@steipete
steipete merged commit 33a1413 into main Nov 15, 2026
174 of 177 checks passed
@steipete
steipete deleted the steipete/perf-workspace-reconcile-payload-20261115 branch November 15, 2026 08:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
* perf(sandbox): send workspace reconcile pack deltas

* perf(sandbox): include tree owner in wrapper extraction
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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