Repository navigation
improve(gateway): reduce Git subprocesses when staging worker results - #150057
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 8:57 AM ET / 12:57 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +128, Tests +275. Total +403 across 8 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
) 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.
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:
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.
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.