Skip to content

perf(sandbox): reuse saved workspace fingerprints during acceptance - #199683

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-workspace-mutate-payload-20261115
Nov 15, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-workspace-mutate-payload-20261115

Conversation

@steipete

@steipete steipete commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Sandbox workspace acceptance resends the full fingerprint inventory after the same bytes have already been saved in its recovery checkpoint, even for a one-file edit.

User Impact

Large local workspaces send substantially smaller acceptance requests to the database worker. File contents, accepted roots, conflict and rejection behavior, rollback journals, and persistence timing remain unchanged. No schema change or migration is required.

Why This Change Was Made

Acceptance now references the checkpoint held by the writer under the existing row revision. The writer verifies its roots and publishes its saved fingerprints. Main retains the local publication facts and decodes fingerprint buffers once for commit receipt and acknowledgement, removing the repeated decode.

Legacy checkpoints without saved fingerprints retain their existing conversion path. The production diff is +60 net lines: the additional code separates wire references from local publication facts and resolves the durable reference, including rejected-checkpoint envelopes. This trades repeated main-thread serialization for one worker-side checkpoint read/parse. There is no new cache or stored format.

Evidence

A synthetic filesystem reconciliation with 30,000 files (246 MB) and 10,001 session rows reduced acceptance requests from approximately 406,780 bytes to 770 bytes (99.8%). All eight one-file edits published the expected canonical contents. Other mutation fields were small: journal request approximately 1.3 KB, pause/resume and cleanup 414–514 bytes, and prepare approximately 2 KB. The initial reservation still persists approximately 408 KB of newly captured checkpoint data; that durability write is unchanged.

The byte census attributes the duplicate to mutation.manifest.fingerprints, not authority predicates, rows, unchanged manifests, or journals. This fixture did not reproduce a 19 MB individual mutation. Its checkpoint fingerprint field was approximately 406 KB, while its delta manifests were hundreds of bytes.

Owner benchmark: two counterbalanced pairs, 1,024 cycles per arm per pair (2,048 per revision), 30,000 paths, real SQLite writer. Each cycle performs admission, checkpoint reservation, acceptance and cleanup, then verifies durable readback. Timing and byte census use separate processes.

Measurement Baseline Candidate
Acceptance request 592,944 B 739 B (−99.88%)
All mutation requests per cycle 2,646,947 B 2,054,742 B (−22.37%)
Main-thread CPU per cycle, observed paired mean 12.902 ms 11.096 ms
Process CPU per cycle, observed paired mean 70.806 ms 63.601 ms
Main-isolate V8 allocation per cycle 5,064,320 B 5,069,213 B (+0.10%)
Acceptance-only main CPU 1.425 ms 1.198 ms
Acceptance-only V8 allocation 254,562 B 249,136 B

CPU and small heap-allocation differences are inconclusive, not claimed speedups. Four matched identical-code control pairs varied by up to 19.6% in whole-cycle main CPU, 16.4% in process CPU, and 35.3% in acceptance CPU. An earlier candidate round had opposite timing results (+19.6% main CPU, +25.3% process CPU), while the final round was −14.0% and −10.2%. Final arms' host 1-minute load changed 42.1→37.5 / 35.9→32.9 / 31.5→22.3 / 21.7→20.4 (ABBA). The deterministic win is removing duplicate serialized bytes; V8 heap accounting excludes those external buffer allocations.

The filesystem burst (8 edits per side) observed main CPU 434.6→384.8 ms, process CPU 9,070.5→8,134.1 ms, allocation 21.46→23.19 MB/edit, elapsed 8.46→8.37 s, loop p99 21.54→17.04 ms (675 samples each; context only), and GC 55.95→39.97 ms/min (one major collection each; context only). Host load was 24.9→23.4 vs 21.4→23.0. Each side recorded one minor, one major and one incremental GC: minor total/max 1.09→1.16 ms, major total/max 5.95→4.01 ms, incremental total/max 0.85→0.41 ms. These short samples do not establish a latency or GC improvement. sessions.list latency is not measured by this owner workload.

Unforced main memory after the sustained owner burst, averaged across two arms (MiB):

Memory Baseline before → after Candidate before → after
RSS 771.86 → 596.85 819.04 → 643.95
Heap total 184.15 → 176.78 206.30 → 181.09
Heap used 98.49 → 100.24 98.94 → 104.09
Old-space size / used after 89.12 / 77.28 89.38 / 77.33
Old-space size minus used 20.57 → 11.84 42.25 → 12.05

The old-space gap after the burst is essentially unchanged (11.84→12.05 MiB); no retained-memory or RSS improvement is claimed. Natural worker retirement and GC make RSS deltas unsuitable as a win here.

Formatting, file-scoped lint, pnpm tsgo:test:root, and the gateway core-test typecheck pass. The scripts report field-level bytes, per-operation CPU/allocation and unforced memory so this comparison can be repeated. Runtime production delta is +60 lines; non-test/non-doc delta including benchmark instrumentation and its allocation record is +180 lines.

Regression: the existing real-writer root-publication test now retains fingerprint blobs and verifies durable fingerprint equivalence, a request smaller than 2 KB, and refusal of a mismatched checkpoint reference. It fails on the baseline at 22,621 bytes > 2,048 bytes and passes with the change.

Focused proof: 125 passed, 2 environment-dependent skips across local-workspace-store.test.ts, local-workspace-cas.test.ts, local-workspace-projection.test.ts, and src/agents/sandbox/local-workspace.test.ts. This includes rejected-checkpoint recovery, conflicts, rollback, archive/restore, and lost-reply settlement. The skipped cases require native Podman or filesystem support for non-UTF8 filenames.

The filesystem run exercises the real preparation/reconciliation/publication and SQLite owners with synthetic state; only container engine I/O is mocked. It is not a native Podman, model, WebSocket, or ten-minute Gateway load result. Owner-level CPU, allocation and memory measurements use fresh processes and fixed-work cycles; RSS and unforced heap snapshots are context, not evidence of a retained-memory reduction. Independent review is pending.

Exact-head hosted CI run passed on 103b181bfdab1751a2842bc8ecbfb035dc6b8477. All selected test, typecheck, lint, and baseline jobs passed without reruns. Independent review remains 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts labels Nov 15, 2026
@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-15T16:48:12.217856Z 103b181 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro 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. clawsweeper:intake:needs-repro 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 reuses checkpoint fingerprints during workspace acceptance instead of sending the same inventory to the database worker again.

Example: Accept a one-file edit in the reported 30,000-path SQLite workload.

  • Before: The acceptance request carries 592,944 bytes, including fingerprints already saved in the checkpoint.
  • After: The acceptance request carries 739 bytes and the writer publishes the saved fingerprints.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and source-consistent, with a meaningful real-writer regression and deterministic byte measurements; evidence remains at the production-owner harness boundary.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal transport optimization has reported real SQLite and filesystem-owner measurements with durable readback; it makes no native-container, model, or whole-Gateway performance claim.
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 workspaces repeatedly serialize fingerprint inventories that the database writer already holds durably.
Reason: The maintainer-authored direction removes measured duplicate bytes through existing owners without adding configuration, storage formats, or broader behavior changes.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR removes measurable duplicate workspace transport work through the existing persistence owner, with no introduced correctness or security defect found; exact-head CI remains pending.

Priority: P2
Reviewed head: 103b181bfdab1751a2842bc8ecbfb035dc6b8477

Before merge

None.

Findings

None.

Agent review details

How this fits together

Sandbox reconciliation saves a recovery checkpoint, applies workspace changes, and accepts the resulting baseline through the shared-state writer; commit receipts then update the Gateway's retained projection.

flowchart LR
  A[Workspace scan] --> B[Durable checkpoint reservation]
  B --> C[Workspace reconciliation]
  C --> D[Acceptance reference]
  D --> E[Revision and root checks]
  E --> F[SQLite fingerprint publication]
  F --> G[Gateway commit receipt]
Loading

Technical review

Best possible solution:

Retain the existing checkpoint and writer owners, reuse their saved fingerprints, and preserve exact durable and host publication equivalence.

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

Pinned main visibly resends saved fingerprint inventories, and the PR reports a red-on-base real-writer byte regression; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change follows the smallest complete approach: remove duplicate transport, resolve the existing durable fact under revision and root checks, and reuse the decoded local publication patch without adding a cache or persistence owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +60, Tests +22, Docs +6, Other +120. Total +208 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 69 9 +60
Tests 1 23 1 +22
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 3 140 20 +120
Total 10 238 30 +208

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
Runtime production versus test growth Runtime production +60 lines; tests +22 lines Growth separates compact wire references from local publication facts and resolves the durable reference; the existing regression gains distinct payload, persistence, and mismatch assertions.

Labels

Label changes:

  • add P2: A bounded workspace transport optimization has a deterministic byte reduction without evidence of an urgent user-facing regression.
  • 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: A bounded workspace transport optimization has a deterministic byte reduction without evidence of an urgent user-facing 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.

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, 11:59 AM ET / 16:59 UTC.

@steipete
steipete merged commit 8a8d824 into main Nov 15, 2026
163 of 166 checks passed
@steipete
steipete deleted the steipete/perf-workspace-mutate-payload-20261115 branch November 15, 2026 17:06
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