Repository navigation
improve(gateway): reduce idle worker startup memory - #133176
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 4:11 AM ET / 08:11 UTC. ClawSweeper reviewWhat this changesThe branch defers Gateway worker session-tool executor loading and construction until a worker first requests a session, publication, or portal tool, with import-boundary and concurrent-first-use coverage. Merge readinessNo introduced correctness defect was found. Current main still eagerly imports the worker session-tool executor, so this optimization remains necessary; as a maintainer-authored, maintainer-labeled PR, it should remain in ordinary maintainer review until exact-head checks finish. Priority: P3 Review scores
Verification
How this fits togetherThe Gateway initializes worker-environment services for hosted worker sessions. Worker tool requests pass through the session-tool executor to session dispatch, GitHub publication, or portal services after the Gateway has started. flowchart LR
A[Gateway startup] --> B[Worker environment runtime]
B --> C[Idle worker service]
D[Worker tool request] --> E[Lazy executor initialization]
E --> F[Session-tool executor]
F --> G[Session, publication, or portal action]
Decision needed
Why: The patch is focused and no correctness blocker was found, but the maintainer label requires ordinary human acceptance rather than automated cleanup. Before merge
Agent review detailsSecurityNone. PR surfaceSource +12, Tests +117. Total +129 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one memoized lazy executor per Gateway while preserving the current request-time authority checks and live-binding closures for dispatch, publication, and portals. Do we have a high-confidence way to reproduce the issue? Not applicable as a performance optimization rather than a discrete bug report; current main source confirms the eager startup import that the branch targets. Is this the best way to solve the issue? Yes. It uses the repository's existing lazy-runtime abstraction at the Gateway owner boundary while leaving worker RPC validation and executor-side authority checks intact. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against eb3e09b47bce. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
ClawSweeper's remaining procedural item is addressed: the PR stayed draft while the ARM64 proof was running. The body now includes the exact-head 1 GB/no-swap result, the PR is in ordinary maintainer review, and no repair lane is requested. |
What Problem This Solves
Fixes an issue where every Gateway process paid the memory cost of worker session-tool execution even when no worker invoked
sessions_spawn,sessions_send, or related tools. On memory-constrained devices, that idle import graph consumed roughly 20-27 MiB of avoidable resident memory.Why This Change Was Made
The worker session-tool executor is now loaded on first use through the existing lazy-runtime boundary. Executor construction is memoized per Gateway, so concurrent first calls share one initialization while the existing live dispatch, publication, portal, placement, and authority bindings remain unchanged.
User Impact
Idle Gateway startup uses less memory. In an 11-pair real Gateway A/B run, ready-state RSS fell by 27.0 MiB and maximum RSS fell by 19.6 MiB. Operators who use worker session tools keep the same behavior; the first tool call pays the one-time module load.
Evidence
t4g.micro:gateway statusmaximum RSS: 178,712 KiB