Skip to content

perf(workspace): avoid copying owned projection mutations - #185256

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-local-workspace-retention-20260919
Oct 27, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-local-workspace-retention-20260919

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large local sandbox checkpoints deep-copy owner-held mutation payloads before the existing worker transport serializes them, allocating another full checkpoint string and journal buffer on the Gateway thread.

User Impact

Reduces allocation during local workspace reconciliation without changing stored bytes, checkpoint ordering, recovery, or authority checks. This is an allocation improvement, not a demonstrated fix for persistent heap growth: the baseline already releases settled rows in the reproduction.

Why This Change Was Made

Projection operations create their mutation inputs and await settlement before reusing them. Reuse those inputs for dispatch and committed-row recovery. Keep the independent predicate snapshot and all live authority checks. Reconstructed rows preserve the worker/database's plain Uint8Array journal shape through a zero-copy view of Buffer inputs.

Runtime source delta: +8 lines. The growth preserves the existing byte-view shape contract that structuredClone previously supplied implicitly; the full mutation copy is removed. Benchmark +355 lines, Knip entry +1 line, existing test +4 net lines. Usage lives in the script header; the shared performance README is unchanged.

Evidence

Two counterbalanced untraced pairs, each arm performing 1,000 updates with a synthetic 100,000-path checkpoint; allocation sampled in separate passes. Final comparisons pin both the store and publication modules.

Metric Baseline Candidate Delta
Main-thread CPU / update 1.428 ms 1.380 ms -3.4%
Sampled allocation / update 6.884 MB 3.510 MB -49.0%
Natural GC / 1,000 updates 110.967 ms 119.812 ms +8.845 ms (+8.0%)
Natural collections / pair 242 / 240 119 / 106 about half
Maximum GC pause / pair 7.672 / 3.944 ms 19.623 / 3.968 ms both below 50 ms
Settled rows retained / 1,000 0 0 unchanged

CPU improved in both pairs: 1.535776→1.458085 s and 1.320573→1.301429 s. GC totals were 124.415→149.126 ms and 97.519→90.497 ms, with mixed signs; the mean absolute rise is 0.008845 ms/update, below the +1 ms/operation absolute gate. Write-wall mean was 8.126→8.196 ms/update (+0.86%), also with mixed signs, so wall timing is context. Host load per arm: baseline 17.10→16.16 and 14.79→13.88; candidate 15.20→14.86 and 14.55→15.29. Forced-GC retention samples are outside measured write windows. These are store-owner measurements, not whole-Gateway results.

All arms release all 1,000 observed rows after settlement, enforced by the workload assertion. Old space remains flat around 57.5 MB while an active store retains only its current row. No growing row history was reproduced.

Real 100,000-file Git checkout, ten rounds of 1,000 guest edits: all edits reached the canonical checkout on both versions, with zero settled rows retained. Old space from cycle 1→10: baseline 92.379→92.325 MB, candidate 92.392→92.329 MB. Heap: baseline 100.695→101.937 MB, candidate 100.712→101.963 MB. Matching trends do not reproduce persistent workspace retention.

Full-reconciliation timing is context only: baseline/candidate main-thread CPU 2.015/2.123 s, wall 160.921/174.057 s, natural GC 30.490/36.050 ms (33/32 collections; max 4.635/12.135 ms). These single runs had host loads 23.55→25.32 and 23.66→24.92, and the baseline preceded an unrelated-main rebase, so no full-flow speedup is claimed. An additional baseline compression-branch probe used a 1,000,000-path inventory (34.120 MiB, above the 32 MiB threshold): across 20 writes old space stayed 154.611→154.545 MB and all observed rows were released.

Proof and Limits

  • Existing lost-reply recovery regression now verifies canonical Uint8Array shape and reuse of the owner's journal backing buffer, offset and length. The zero-copy assertion fails on original main.
  • Initial CI caught a real compatibility regression in service.retire-snapshot.test.ts: removing structuredClone also removed Buffer→Uint8Array normalization. Reproduced locally, repaired at committed-row publication with a zero-copy byte view, then 37 focused tests passed (store 18; retire-snapshot 19). This failure was ours, not inherited.
  • Projection sibling file 35 passed, 2 skipped: real Podman unavailable; host filesystem rejects non-UTF-8 filenames. Closure guard files 29 passed; export-name collision guard passed.
  • Changed-file formatting and lint passed. Broad validation: final-head PR CI. The earlier run was superseded by the substantive compatibility repair; no CI rerun was requested.
  • Independent subagent review (autoreview route unavailable): scoped clean, no actionable P0–P2 findings, including a fresh review of the compatibility repair. Autoreview preflight refused the configured provider mismatch; operator configuration was left unchanged.
  • No Testbox lease or production load was used. The scoped copy deletion follows the authorized fast-path proof policy; no listening Gateway, provider-turn load, or multi-pair whole-Gateway stress campaign was run. Client/server RPC latency and whole-Gateway CPU/heap are therefore not claimed.
  • The reported production heap growth remains unexplained. Allocation attribution alone does not establish a retaining path; a full heap snapshot is needed to identify that retainer.

Reproduce with node --expose-gc --import ./scripts/tsx.mjs scripts/perf/local-workspace-retention.ts --iterations 1000 --files 100000; add --allocation for a separate sampled-allocation pass, or --reconcile --iterations 10 --files 100000 --edits 1000 for real filesystem reconciliation. --source-dir replaces both store and publication modules with captured baseline source; other dependencies remain identical within each comparison. CPU is main-thread CPU; worker/Git CPU is not included.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T01:59:06.391107Z 85b5c3a New commits
ℹ️ 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 gateway Gateway runtime scripts Repository scripts size: M labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses owner-held workspace mutation payloads for worker dispatch and commit recovery instead of deep-copying them.

Example: A local workspace checkpoint contains 100,000 paths.

  • Before: The Gateway deep-copies the mutation before serializing it for the worker.
  • After: The Gateway serializes the owned mutation directly and reuses it through settlement.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported optimization with reported production-owner measurements and recovery coverage; proof remains harness-level and broad CI is pending.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; reported real-worker and filesystem measurements cover allocation and reconciliation, but no shipped Gateway checkpoint run is supplied.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Large local sandbox checkpoints allocate an unnecessary additional copy on the Gateway thread.
Reason: The maintainer-authored direction has measurable allocation value, a minimal runtime change, and no new configuration or storage contract.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR removes a redundant allocation that remains on main, with no actionable correctness or security findings.

Priority: P2
Reviewed head: 59dce8be5bf5abe91423cca1ec9129948e58f904

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence exercises real workers and Git reconciliation through a standalone harness rather than a shipped Gateway checkpoint entry point.
Agent review details

How this fits together

Local workspace reconciliation supplies checkpoint and journal mutations to the existing worker-backed store, which persists them and publishes acknowledged projection rows.

flowchart LR
  A[Workspace changes] --> B[Projection reconciliation]
  B --> C[Local workspace store]
  C --> D[Existing worker transport]
  D --> E[SQLite transaction]
  E --> F[Committed projection snapshot]
  F --> B
Loading

Technical review

Best possible solution:

Reuse the projection-owned payload within the existing store while preserving predicate snapshots, live authority checks, and settlement recovery.

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

Source confirms the redundant clone on current main; supplied measurements distinguish allocation churn from retention, but this read-only review ran no workload.

Is this the best way to solve the issue?

The smallest complete change removes the copy at its existing owner, and the standalone workload supports the allocation claim without adding runtime machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Mutation capture, dispatch, and recovery changes intended behavior with a stated reason (cd326f9: Move projection persistence into existing workers while retaining custody, live authority, complete payloads, and recovery without replay.)
  • Compressed and prepared manifest transport keeps the original intent (7462184: Keep full baseline preparation off the Gateway thread and forward prepared bytes through the existing worker transaction.)
  • Standalone benchmark entry registration keeps the original intent (b24990a: Represent maintained standalone commands in the existing exact Knip entry list without broadly ignoring files or exports.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit cd326f9 adds src/gateway/worker-environments/local-workspace-store.ts:150 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cd326f915580; files: src/gateway/worker-environments/local-workspace-store.ts)

PR surface

Source -1, Tests +1, Other +348. Total +348 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 7 8 -1
Tests 1 2 1 +1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 348 0 +348
Total 4 357 9 +348

Labels

Label changes:

  • add P2: The measured allocation reduction benefits large workspace checkpoints without evidence of an urgent outage or persistent memory leak.
  • 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: The measured allocation reduction benefits large workspace checkpoints without evidence of an urgent outage or persistent memory leak.
  • 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 October 26, 2026, 8:56 PM ET / October 27, 2026, 00:56 UTC.

Projection operations own mutation data through settlement. Reuse it for worker dispatch and committed-row recovery while retaining predicate snapshots and live authority checks. Add a reproducible retained-row and allocation workload; this reduces copying without claiming to fix an unproven persistent retainer.
Normalize Buffer-backed journal data to a plain Uint8Array view at commit publication without copying its backing bytes. Preserve the existing worker/database row shape for creation and lost-reply recovery; cover both changed owners in the allocation workload.
@steipete
steipete force-pushed the steipete/perf-micro-local-workspace-retention-20260919 branch from 59dce8b to 85b5c3a Compare October 27, 2026 01:56
@steipete
steipete merged commit ce503a5 into main Oct 27, 2026
144 of 145 checks passed
@steipete
steipete deleted the steipete/perf-micro-local-workspace-retention-20260919 branch October 27, 2026 02:07
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…85256)

* perf(workspace): avoid copying owned projection mutations

Projection operations own mutation data through settlement. Reuse it for worker dispatch and committed-row recovery while retaining predicate snapshots and live authority checks. Add a reproducible retained-row and allocation workload; this reduces copying without claiming to fix an unproven persistent retainer.

* fix(workspace): preserve published journal byte views

Normalize Buffer-backed journal data to a plain Uint8Array view at commit publication without copying its backing bytes. Preserve the existing worker/database row shape for creation and lost-reply recovery; cover both changed owners in the allocation workload.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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