Repository navigation
fix: avoid chat metadata stalls during fleet startup - #149716
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: needs maintainer review before merge. Reviewed September 16, 2026, 3:43 AM ET / 07:43 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR prepares chat commands and model metadata when requested, bounds retained caches, and updates lifecycle tests and protocol documentation. Merge readiness✅ Ready for maintainer review This remains a useful, scoped fix absent from current main. No actionable patch defects remain; the clarified owner-level scope resolves the previous whole-fleet concern without claiming that the broader startup issues are fixed. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway's chat metadata service combines published model, account, and skill facts into responses for chat clients. Startup refreshes its facts, while metadata requests and optional history decorations consume its projections. flowchart TD
A[Published model and account facts] --> B[Metadata refresh]
B --> C[Current generation]
D[Chat metadata request] --> E[Prepare requested agent]
C --> E
E --> F[Bounded projection caches]
F --> G[Metadata response]
F --> H[Optional history catalogs]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -62, Tests +37, Docs +1. Total -24 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep metadata preparation demand-driven within its existing lifecycle owner, preserving optional history reads and account freshness. Do we have a high-confidence way to reproduce the issue? Yes: current main eagerly prepares every agent during metadata refresh, and the supplied isolated Gateway comparison measures that cost; this review did not execute the workload. Is this the best way to solve the issue? Yes: removing eager presentation work from the existing owner is a focused repair, with bounded reuse and preserved publication checks; other startup owners can be repaired independently. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 891a6b7d1977. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
1b602e4 to
fce07c6
Compare
|
Merged via squash.
|
Refs #149538
Refs #148529
What Problem This Solves
Gateways with large agent fleets block HTTP service while startup eagerly prepares and retains chat command and model projections for every agent, before any metadata request.
User Impact
Metadata requests prepare their agent on demand and reuse bounded caches. History continues using already-settled optional catalogs; shared model/account publication fences and personal-account isolation remain in place. Other startup owners still need work to restore serving throughout startup on large fleets.
Why This Change Was Made
The existing chat-metadata owner now publishes captured owner facts on refresh. This removes the eager fleet loop, aggregate presentation wait, and staged-generation path. Command preparation and neutral/session projections use the existing 64-entry bound, and shutdown still joins evicted or superseded work.
Production: +51/-113 (−62). Tests: +207/-170 (+37). Docs: +5/-4 (+1). This runtime cache change requires no configuration or state migration. #149389’s model-row indexing fix is included by the required rebase; #148264’s cross-refresh reuse remains separate. The fingerprint owners in #149314 are untouched by this patch.
Evidence
Three new regression cases failed against unchanged production because refresh entered presentation preparation for all agents, including 200 builder calls in the fleet case. All 172 focused tests pass on the final rebased head, including a real HTTP health request while one agent is suspended, another agent's metadata response, bounded retention and rebuild after eviction, shutdown joins, real Gateway RPC failure isolation, native/personal-account behavior, optional history, and published SQLite model-owner fixtures.
node scripts/check-changed.mjsandgit diff --checkpass. Fresh local and committed-branch Codex reviews through P1 are scoped-clean.pnpm buildpasses at final headfce07c65784dfac5ae7f1535555525e995c459af. Its exact-head CI run is green.#149389 merged while the 600-agent arm was running. The required rebase onto
fbf926add80bis complete atfce07c65784d, with the identical stable patch IDd1b7c84609f3948dd96bd97ce44c898b91f140b9. The metadata owner/facts/lifecycle code is unchanged on the new base; the landed model-row index was verified with the expanded focused suites. Measurements below remain labeled with their actual original candidate revision.200-agent results (before
fa67da641b30, after1b602e4a91ef):/healthanswered/totalThe after metadata phase finished between one-second probes/RSS samples, so its 0/0 is an empty observation interval. Trace histograms can miss blocks during timer starvation; the post-ready delay uses the independent sampler. The metadata invariant is also enforced by zero eager builder calls, successful health/other-agent work while one requested agent is suspended, and a 64-entry retention/rebuild boundary.
Process peak RSS remains about 2.2 GiB (2239.0 → 2215.5 MiB); this run does not establish a whole-process memory reduction. The startup owner now retains no command/model projections until requested, and populated caches remain bounded. Other owners still block serving: after-run health was 35/251 overall with 181 deadlines, and model-runtime preparation took 142.749 s. These original measurements predate the required rebase. The final base also includes the independent post-ready reconciliation fix in #149600, so those post-ready rows do not describe the final combined tree.
Bootstrap varied from 742.717 to 411.193 s, so the aggregate timing difference must not be attributed solely to this patch. Both observed Gateways exited normally after the rig's cutoff. Teardown probes are excluded.
The rig uses isolated state and a free loopback port, distinct workspaces and product-bootstrapped agent SQLite databases, 54 configured models per agent, 12 enabled bundled plugins, no channels, and a 2560 MiB heap cap. Node: 24.21.0. These are single observations on a shared host; process RSS and aggregate startup timings include other owners.
Original-head CI run 35057945784 failed on three main-side issues:
ui/src/pages/chat/chat-pane-render.tshas 702 counted lines;goals-operations.test.tsobserves 4 reads against a bound of 3; and the CI-planner tail-48/tail-49 fixtures throw “expected fixture config to be defined”. CI tested merge commit1c6d934d2cdf, whose main parent isf0eb01f0f160. Each failing file and its primary owner is byte-identical between that parent and the CI merge. The Goal assertion and planner fixtures came from #149537 and #149665 respectively. These unrelated repairs were kept outside this metadata change. The final rebased head’s CI is green.ClawSweeper reviewed this exact head and found no patch defects. Its remaining merge-risk item concerns whole-fleet recovery. The maintainer scope for this series is one measured owner per PR: keep metadata preparation demand-driven here and track the remaining startup bottlenecks separately in #149538 and #148529. The 600-agent arm records progress without claiming whole-startup recovery.
The one 600-agent progress arm ran after the PR was marked ready, on original head
1b602e4a91efbefore the mandatory rebase:Four completed config-snapshot spans took 177.400, 193.400, 127.177, and 154.046 seconds; legacy-state migration took 259.058 seconds. The last completed trace was plugin-index persistence at 1499.425 seconds. Bootstrap had not settled at the cutoff, so this arm supplies no 600-agent observation of the repaired metadata owner. The rig stopped the observation; this was not an observed OOM. Whole-fleet startup recovery remains unproven.
An additional boot attempt on final head
fce07c65784dexited 78 before bind because the retained fixture needed the newly landed agent-schema 20→21 migration. The authorized isolateddoctor --fix --non-interactiverun upgraded all 200 databases, usingOPENCLAW_SERVICE_REPAIR_POLICY=externalto skip native service maintenance and a freeOPENCLAW_GATEWAY_PORTfor the isolated target. After the plugin-index message, Doctor continued CPU-heavy diagnostics without finishing; the next contribution in its source is the per-agent active-tool-schema diagnostic. At 32m39s it used 81% CPU and 2154.9 MiB RSS. I stopped only that fixture process with SIGTERM and used the lane’s stop-report escape hatch for this additional verification. Full Doctor completion and a new final-head fleet boot measurement are not claimed. No host state or Gateway was modified.# Additional final-head attempt and the required fixture migration: git switch --detach fce07c65784dfac5ae7f1535555525e995c459af pnpm install --frozen-lockfile pnpm build /opt/homebrew/opt/node@24/bin/node .local/fleet-serve/run.mjs 200 baseline-200 profile pr-b-after-rebase /opt/homebrew/opt/node@24/bin/node .local/fleet-serve/doctor.mjs baseline-200The generator and instrumentation remain untracked under
.local/fleet-serve/. Reproduction source follows.Synthetic fleet rig source
seed.mtsrun.mjssampler.mjsprofile.mjssummarize.mjsIsolated Doctor helper used for the additional attempt