Skip to content

improve(gateway): reduce Git subprocesses when staging worker results - #150057

Merged
steipete merged 1 commit into
mainfrom
codex/team-workspace-result-batch-20260916
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/team-workspace-result-batch-20260916

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Staging a worker result starts a separate Git process for every changed file or symlink, adding avoidable process overhead for larger results.

User Impact

Worker results with many entries require substantially fewer Git subprocesses while preserving staged content, file modes, symlinks, ordering, validation, cancellation and cleanup. There are no configuration or migration steps.

Why This Change Was Made

The existing workspace-result owner now reads verified blob OIDs in ordered, finite batches of at most 256 entries and 8 MiB. Large individual files keep the existing singleton path. Strict frame, size, digest and symlink validation remain before materialization, and the host still owns Git execution and its authority/cancellation lifecycle. Preview and materialization readers use the same path.

Evidence

Counted synthetic controls through the real staging entry point preserved bytes, modes, symlink targets and staged commits:

Result entries Git processes before Git processes after
1 3 3
67 69 3
303 305 4

The regression fails on the baseline's process count and passes with batching. Thirty focused staging, checkpoint, shipped v1, limits and cancellation/cleanup tests passed, including SHA-256 repositories, newline filenames, a 9 MiB singleton and malformed batch rejection. Production and core-test typechecks passed; the selected changed-file checks passed after correcting two test-only lint findings. Codex P2 review was scoped-clean.

Timing was contaminated by concurrent local validation/review work. Bulk cases favored batching, but singleton CPU and latency outcomes were mixed and sometimes worse. The landing claim is the verified reduction in Git process starts, not an isolated CPU-saving percentage or a production-wide performance claim.

All paired timing observations and measurement limits

macOS arm64, Node 26.8.2, three fresh-process pairs per shape, eight measured operations after two warmups per cell. Pair order was baseline/candidate, candidate/baseline, baseline/candidate. All 18 cells and 144 measurements were retained; no selective reruns or discarded cells.

Materialization runs from the staging call through entry to its consumer callback, excluding imports, setup, warmups, consumer verification and cleanup. CPU and elapsed values below are means in milliseconds per operation. Main CPU covers Node's main thread; Node CPU includes worker threads and excludes Git children. Whole-cell CPU is seconds over the complete child lifetime, including imports, setup, warmups, verification, cleanup and reaped Git children. These scopes overlap and must not be added.

Entries / pair Main CPU before → after Node CPU before → after Elapsed before → after Whole-cell CPU before → after
1 / 1 12.637 → 12.526 16.989 → 16.852 45.539 → 46.330 4.276 → 3.631
1 / 2 13.162 → 14.037 17.730 → 22.612 45.981 → 45.850 4.249 → 4.423
1 / 3 13.346 → 14.790 18.034 → 19.854 49.467 → 59.355 4.593 → 4.643
67 / 1 356.402 → 75.417 497.518 → 163.468 1690.240 → 328.539 19.549 → 6.655
67 / 2 384.793 → 78.359 530.263 → 171.809 3272.291 → 370.332 20.086 → 6.959
67 / 3 370.703 → 80.423 513.720 → 168.764 2774.164 → 424.984 19.863 → 6.848
303 / 1 1533.130 → 260.999 2114.024 → 630.102 8549.214 → 888.701 71.613 → 12.418
303 / 2 1578.624 → 280.946 2169.615 → 659.995 7925.151 → 1196.155 71.661 → 12.744
303 / 3 1532.505 → 264.592 2114.339 → 637.484 7578.606 → 1154.839 68.998 → 12.195

Every 67-entry cell and the first four 303-entry cells overlapped local focused tests; local review overlapped every cell from the second 67-entry baseline through the final 303-entry candidate, and Git preparation also overlapped several bulk cells. Only whole-cell overlap can be mapped: individual materializations have no absolute UTC timestamps. The review's final receipt closes its execution interval, but cumulative CPU/I/O are unknown, and native operation log spans do not establish exact process lifetimes. Cells without a recorded overlap are not proven isolated. These observations do not establish causal CPU or memory reductions.

Read verified workspace blobs in finite ordered Git batches instead of starting
one child for every entry. Keep framing, size, digest and symlink validation,
large-file singleton handling, and host-owned cancellation and cleanup.

Real staging controls preserve content and reduce Git starts from 69 to 3 for
67 entries and from 305 to 4 for 303 entries; one entry remains 3 starts.
Timing observations overlap other local work and include mixed singleton
results, so they are not an isolated CPU-saving claim.
@clawsweeper

clawsweeper Bot commented Sep 16, 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.

@steipete
steipete marked this pull request as ready for review September 16, 2026 12:46
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Sep 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 8:57 AM ET / 12:57 UTC.

ClawSweeper review

What this changes

The PR batches Git reads when restoring worker results, reducing subprocess starts while preserving content validation, file modes, symlinks, and ordering.

Merge readiness

✅ Ready for maintainer review

This remains a useful optimization: current main still reads staged blobs individually, and the earlier checkpoint optimization addresses different Git calls. No blocking correctness or security defect was found.

Priority: P2
Reviewed head: 3915a192fcf87b35e3152dc7d3c6fda13d338f88

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with useful production-path measurements, meaningful regression coverage, and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured PR body records before/after runs through the real staging entrypoint on macOS with real Git, showing fewer subprocess starts and preserved materialized content. Timing contamination limits broader performance conclusions; focused tests supplement these observations.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR body records before/after runs through the real staging entrypoint on macOS with real Git, showing fewer subprocess starts and preserved materialized content. Timing contamination limits broader performance conclusions; focused tests supplement these observations.
Evidence reviewed 9 items Pinned introduction and clean checkout: The merge-base-to-head diff contains the eight supplied paths. Inspection covered all changed modules and the complete new test file; git diff --check passed and the checkout remained clean.
Bounded reads retain integrity checks: The runtime bounds batches, permits only hexadecimal object IDs in stdin, checks returned object identity/type/size/framing, validates file digests and symlink targets, and rejects trailing bytes before returning contents.
Caller cutover and lifecycle: Materialization consumes the ordered batch iterator, previews reuse the singleton reader, and temporary cleanup remains in finally. Searches found no surviving references to the retired singular operation. The unchanged Git broker retains subprocess cancellation, host execution, and settlement; this patch does not transfer authorization or change durable formats.
Findings None None.
Security None None.

How this fits together

The Gateway stores completed worker changes as Git objects and authenticated workspace manifests. Its staging reader reconstructs temporary files for checkpoint recovery and workspace reconciliation.

flowchart TD
 A[Stored worker result] --> B[Validate manifests and tree]
 B --> C[Group entries into bounded batches]
 C --> D[Host-owned Git reads]
 D --> E[Validate frames and contents]
 E --> F[Materialize temporary workspace]
 F --> G[Checkpoint or reconcile]
 G --> H[Clean temporary files]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +128, Tests +275. Total +403 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 7 190 62 +128
Tests 1 275 0 +275
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 465 62 +403

Review metrics

Metric Value Why it matters
Observed Git process reduction 67 entries: 69 → 3; 303 entries: 305 → 4; singleton: 3 → 3 The supplied production-path measurements support the specific optimization without relying on contaminated timing comparisons.
Batch bounds 256 entries / 8 MiB; larger files use singleton reads Finite batches limit buffered payload growth while retaining the existing large-file path.
Production versus test growth Production net +128 lines; tests +275 lines Production growth implements bounded batching and strict frame parsing; tests protect materialization and malformed-input rejection.

Technical review

Best possible solution:

Keep bounded blob batching within the existing staging owner, preserving its validation, host-owned execution, and unchanged recovery format.

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

Not applicable as a bug reproduction: this is a performance improvement. Current source confirms individual blob reads, and the supplied before/after staging runs quantify the process overhead.

Is this the best way to solve the issue?

Yes. Batching immutable blob reads in the existing owner is a focused solution, with a complete internal caller cutover and no new public API, configuration, or persisted format.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded performance improvement for worker results containing many files, with no demonstrated urgent outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body records before/after runs through the real staging entrypoint on macOS with real Git, showing fewer subprocess starts and preserved materialized content. Timing contamination limits broader performance conclusions; focused tests supplement these observations.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR body records before/after runs through the real staging entrypoint on macOS with real Git, showing fewer subprocess starts and preserved materialized content. Timing contamination limits broader performance conclusions; focused tests supplement these observations.

Label justifications:

  • P2: This is a bounded performance improvement for worker results containing many files, with no demonstrated urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR body records before/after runs through the real staging entrypoint on macOS with real Git, showing fewer subprocess starts and preserved materialized content. Timing contamination limits broader performance conclusions; focused tests supplement these observations.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body records before/after runs through the real staging entrypoint on macOS with real Git, showing fewer subprocess starts and preserved materialized content. Timing contamination limits broader performance conclusions; focused tests supplement these observations.

Evidence

What I checked:

  • Pinned introduction and clean checkout: The merge-base-to-head diff contains the eight supplied paths. Inspection covered all changed modules and the complete new test file; git diff --check passed and the checkout remained clean. (3915a192fcf8)
  • Bounded reads retain integrity checks: The runtime bounds batches, permits only hexadecimal object IDs in stdin, checks returned object identity/type/size/framing, validates file digests and symlink targets, and rejects trailing bytes before returning contents. (src/gateway/worker-environments/workspace-result-inventory.runtime.ts:156, 3915a192fcf8)
  • Caller cutover and lifecycle: Materialization consumes the ordered batch iterator, previews reuse the singleton reader, and temporary cleanup remains in finally. Searches found no surviving references to the retired singular operation. The unchanged Git broker retains subprocess cancellation, host execution, and settlement; this patch does not transfer authorization or change durable formats. (src/gateway/worker-environments/workspace-result-staging.ts:208, 3915a192fcf8)
  • Current main still has the overhead: Fetched main reads each selected entry through readGitBlob, which invokes git cat-file blob separately. The proposed batching remains absent. (src/gateway/worker-environments/workspace-result-inventory.runtime.ts:140, d182240bcffe)
  • Latest release comparison: The GitHub contents endpoint for v2026.9.4 shows the older staging implementation invoking cat-file blob for individual objects. This release does not establish that the proposed optimization has shipped. (src/gateway/worker-environments/workspace-result-staging.ts:248, 3a9d69db306c)
  • Production-path observations: The complete supplied PR body, captured under sourceRevision b1dfad14fc135b19ef08fe7f866d196369c3c48c0bb10e30cf18840d7550bfe8, records real staging runs on macOS arm64 with Node 26.8.2: Git starts changed from 69 to 3 for 67 entries and 305 to 4 for 303 entries; singleton starts stayed at 3. It reports preserved bytes, modes, symlink targets, and staged commits, and explicitly disclaims causal CPU or memory conclusions from overlapping timing runs. (3915a192fcf8)

Likely related people:

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

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 14e0a99 into main Sep 16, 2026
266 checks passed
@steipete
steipete deleted the codex/team-workspace-result-batch-20260916 branch September 16, 2026 13:21
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
)

Read verified workspace blobs in finite ordered Git batches instead of starting
one child for every entry. Keep framing, size, digest and symlink validation,
large-file singleton handling, and host-owned cancellation and cleanup.

Real staging controls preserve content and reduce Git starts from 69 to 3 for
67 entries and from 305 to 4 for 303 entries; one entry remains 3 starts.
Timing observations overlap other local work and include mixed singleton
results, so they are not an isolated CPU-saving claim.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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