Repository navigation
improve: reduce Gateway broker memory at startup - #206104
Conversation
|
🦞👀 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: passed. What this changesThis PR gives spawn brokers private runtime chunks and captures only their permitted command and file-reader implementations before readiness. Example: A packaged Linux x64 native-resource broker reaches readiness on Node 24.22.1.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR provides a useful, focused broker startup improvement; no actionable correctness or security defect was found. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway delegates command execution and native-resource custody to broker children; private IPC carries requests, process handles, results, and cleanup receipts. flowchart TD
A[Gateway host] --> B[Broker bootstrap]
B --> C[Capture permitted handlers]
C --> D[Command execution]
C --> E[Ordinary broker file reads]
B --> F[Native resource server]
D --> G[Results and cleanup receipts]
E --> G
F --> G
Technical reviewBest possible solution: Retain this focused broker optimization while the linked issue continues to own constrained ARM64 response-and-soak acceptance. Do we have a high-confidence way to reproduce the issue? Current main statically imports the full-file reader even for resource brokers that reject reads; the PR supplies packaged before/after memory measurements, which this read-only review did not rerun. Is this the best way to solve the issue? The change uses the existing build inventory and broker lifecycle, preserves SQLite read isolation, and captures permitted handlers before package replacement can remove their chunks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8e2c8f5b57ac. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +21, Tests +35, Other +1. Total +57 across 7 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 26, 2026, 2:12 PM ET / 19:12 UTC. |
|
Merged via squash.
|
* perf(process): reduce memory used by Gateway brokers * fix(tooling): include the broker handlers in PR workspaces
What Problem This Solves
On a memory-constrained Gateway, the helper that holds native resources loaded readers for file operations that its mode rejects. In the original ARM investigation this helper accounted for 66,174 KiB of proportional set size shortly before the service reached its limit. Related Gateway report
User Impact
The Gateway can keep its native resources open with a smaller resident helper. Ordinary command helpers also start with less memory. Existing installations pick up the change on restart.
Why This Change Was Made
Build the broker with the private runtime chunks already used by other process entry points. Before announcing readiness, each broker captures the implementations its mode permits. Both modes capture command execution, and ordinary brokers also capture full and paged file reads. A running broker can still serve its first permitted command after an update removes its original package directory. A missing required implementation returns the existing startup failure to its owner.
Evidence
Three fresh packaged Linux x64 processes per arm and mode, comparing the same launcher, Node 24.22.1 and inputs against
c30fc8135800. The table gives medians measured from the kernel after readiness. PSS apportions shared pages between processes.The native-resource broker saved 43.65 MiB PSS at readiness. After its first synthetic native claim, PSS was 83,082 → 38,412 KiB. The claim, seal and close completed on both builds. In the separately matched 768 MiB ARM Gateway run, the original chat still failed before any acknowledgement or provider request. The native broker measured 66,174 KiB PSS on stock and 72,524 KiB on the updated package at each run’s last sample before its first kill. Those samples include the Gateway’s actual native claims, whose identities were unobserved. The isolated x64 saving did not carry through to that operating point. Isolated runner allocation
After removing the original installation, the first command execution succeeded in both modes. Ordinary brokers still served full and paged file reads and honored cancellation. Resource brokers still refused raw reads. With the original installation present, both builds identified a large PDF. Once its optional MIME detector became unavailable, both returned the same PDF prefix bytes and the same text metadata.
The new startup regression failed on stock. On the updated source, 43 broker and file-reader tests and the targeted Gateway import-boundary test passed. Independent source review also checked startup failure, disconnect, shutdown, cancellation and update behavior.