Repository navigation
fix(gateway): prevent idle CPU spikes on multi-agent hosts - #124334
Conversation
Configured agents now use their canonical direct store paths while retired and manual owners retain broad discovery. This prevents Gateway startup prewarm from rescanning every agent root once per configured agent.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: found issues before merge. Reviewed August 15, 2026, 9:39 PM ET / August 16, 2026, 01:39 UTC. ClawSweeper reviewWhat this changesThe branch returns configured agents’ validated canonical session-store paths before broad directory discovery to avoid repeated scans during Gateway startup prewarm. Merge readinessThe performance target is valid, but the early return drops an existing compatibility path for manually named session directories that normalize to a configured agent ID, so this PR is not ready to merge. Priority: P1 Review scores
Verification
How this fits togetherGateway startup prewarms each configured agent’s session data for dashboard and protocol access. The session-target resolver supplies canonical configured paths plus discovered legacy or manually created stores to the combined Gateway store. flowchart LR
A[Configured agents] --> B[Session target resolver]
C[Manual or legacy agent directories] --> B
B --> D{Target ownership}
D --> E[Canonical direct paths]
D --> F[Validated directory discovery]
E --> G[Combined Gateway store]
F --> G
G --> H[Startup prewarm and session views]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +6, Tests +9. Total +15 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Have Gateway prewarm project configured agents from one complete validated target map, preserving normalized legacy/manual stores without rescanning every root for every configured agent. Do we have a high-confidence way to reproduce the issue? Yes, from source: configure Is this the best way to solve the issue? No. The early return removes the repeated scan but also removes intentional normalized-directory compatibility; the optimization should preserve the complete target set and avoid repetition at the Gateway prewarm boundary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9c6539c97533. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready verification for exact head
Known proof gap: this publication lane did not rerun the full Molty process after the fix; the live CPU/RSS/strace evidence is pre-fix, while the owner regression, Gateway siblings, changed gate, autoreview, and exact-head CI are post-fix. |
|
Merged via squash.
|
Configured agents now use their canonical direct store paths while retired and manual owners retain broad discovery. This prevents Gateway startup prewarm from rescanning every agent root once per configured agent.
What Problem This Solves
Fixes an issue where operators with several configured agents could see a freshly started Gateway consume 100–140% idle CPU and 1.8–2.7 GB RSS, with intermittent HTTP, RPC, and WebSocket handshake timeouts.
On Molty's 11-agent installation,
stracerecorded about 27,684 failedreadlinkcalls in 12 seconds and 8,735 path calls in 3 seconds. Gateway dashboard prewarm resolves session stores once per configured agent, while each resolution was unnecessarily enumerating every agent root and retiredsessions.jsonpath.Why This Change Was Made
Configured agents already own deterministic canonical session-store paths. After those direct targets are validated, the resolver now returns their deduplicated paths before broad filesystem discovery. Retired and manually created agents still use the existing broad discovery path unchanged.
This repairs the discovery owner directly and avoids adding a cache or downstream Gateway workaround. It does not change config schema, storage format, API, generated baselines, or canonical session ownership.
User Impact
Multi-agent Gateways avoid quadratic session-store discovery during startup prewarm, reducing idle filesystem churn and the CPU/RSS pressure that could delay dashboard and protocol handshakes. Retired/manual agent discovery is preserved.
Evidence
readlinkcalls in 12 seconds and 8,735 path calls in 3 seconds.src/config/sessions/targets.test.tsfailed 1/40 becauseresolveAgentSessionDirsFromAgentsDirSyncwas called twice (configured custom root plus default state root).node scripts/run-vitest.mjs src/config/sessions/targets.test.ts— 40/40 passed.node scripts/run-vitest.mjs src/gateway/server-startup-handler-prewarm.test.ts src/gateway/server.sessions.list-store-materialization.test.ts— 12/12 passed.git diff --checkpassed.node scripts/check-changed.mjs --dry-run -- src/config/sessions/targets.ts src/config/sessions/targets.test.tsselectedcore, coreTests. The remote router's installed Crabbox binary failed its version/help sanity check before execution, so the documented trusted-source local fallback ran the identical changed gate; all guards, production/test typechecks, lint, and architecture checks passed..agents/skills/autoreview/scripts/autoreview --mode branch --base origin/mainpassed cleanly with no accepted/actionable findings on the final rebased head.cd7a9d2dfe139e43a142a9e3df8d6b23ba917fec.ClawSweeper review disposition
The P1 finding and both optional rank-up moves are intentionally skipped. The proposed
Retired Agent→ configuredretired-agentcase mixes two ownership modes: once an ID is configured, its runtime-owned store path is canonical and deterministic; broad normalized-directory discovery remains available for unconfigured retired/manual owners. No public config/data contract or observed installation was identified for treating a noncanonical directory as an additional store for an actively configured owner. Preserving that speculative runtime compatibility would retain the reported hot-path scan or require a broader prewarm target-planning redesign outside this focused repair. This boundary follows the repository's canonical-runtime/no-unowned-fallback doctrine and the task's explicit configured-versus-retired/manual ownership split.AI-assisted: yes. The implementation and evidence were reviewed; no agent transcript is included.