Repository navigation
fix(codex): avoid fleet startup stalls during catalog registration - #150004
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, 12:47 PM ET / 16:47 UTC (Revision 3). ClawSweeper reviewWhat this changesDefers Codex session-store discovery until a catalog request or persisted-session recovery needs it, while preserving source selection and ownership checks across asynchronous callers. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still performs eager fleet-wide catalog preparation. No actionable introduced defect was found, and the measured improvement supports the explicitly bounded startup fix. Priority: P1 Review scores
Verification
How this fits togetherThe Codex plugin connects OpenClaw’s session catalog and supervised conversations to native Codex stores. Agent configuration and saved session bindings determine which store receives catalog, recovery, and control requests. flowchart TD
A[Agent configuration] --> B[Plugin registration]
B --> C[Publish lazy resolver]
D[Catalog request or saved session] --> C
C --> E[Discover and reuse home facts]
E --> F[Validate current owner and source]
F --> G[Native Codex store]
G --> H[Catalog results or session operation]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +161, Tests +419. Total +580 across 53 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep catalog preparation demand-driven within the Codex plugin, preserving native-store identity and existing settings while broader fleet bottlenecks remain separately tracked. Do we have a high-confidence way to reproduce the issue? Yes: current main visibly performs eager per-agent roster construction during registration, and the supplied fleet measurements attribute substantial CPU time to that path; this review did not execute it. Is this the best way to solve the issue? Yes: extending the existing resolver and migrating its callers removes the startup work while retaining cold recovery, source ordering, native authentication, and configuration-generation checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 70747f3a8aeb. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
3af0b2d to
03d40f6
Compare
03d40f6 to
d142bf2
Compare
|
Merged via squash.
|
…penclaw#150004) * fix(codex): defer fleet catalog discovery at startup * test(codex): adapt registration fixture to async catalog * fix(codex): keep registration independent of binding runtime
Refs #149538
Refs #148529
What Problem This Solves
Gateways with large agent fleets stall during Codex plugin registration because OpenClaw eagerly builds every agent's native session-catalog roster.
User Impact
Codex registration no longer prepares the fleet's catalog homes. The first catalog request or cold persisted-binding recovery discovers the homes it needs, with yielding directory discovery and the existing 100-host limit. Agent additions and removals follow runtime config generations. No operator action or config migration is needed.
This is the third startup owner in the reliability series, following #149600 (skill review reconciliation) and #149716 (chat metadata). It does not claim to fix whole-startup serving; the 600-agent arm is intentionally omitted for this part.
Why This Change Was Made
The OpenClaw-side
createCodexCatalogHomeResolverconstructor built a runtime projection for every agent, and each projection rescanned the fleet. The 200-agent CPU profile attributed 29.755 seconds to that eager snapshot. The snapshot also seeded a connection-home map used by supervised bindings after restart, so simply deleting startup preparation would break cold recovery.The resolver now prepares directory facts lazily per immutable config generation and returns runtime projections for the requesting agent. It preserves primary/user/selected-agent/lexical-peer/configured-home ordering, canonical deduplication, and the host cap. Warm requests reuse discovered facts without filesystem freshness polling. The eager snapshot and global connection-home map are removed; cold bindings use the same lazy resolver through the existing plugin runtime store. Async callers revalidate their current owner before dispatch. Already admitted archive operations and cursor chains retain their captured connection.
All production changes stay inside the Codex plugin and use existing public SDK contracts. There is no SDK, config, environment, CLI, dependency, or schema surface change. After compression and the CI repair, the production delta is +161 lines (+593/-432); test/support is +419 (+1191/-772). It removed the separate connection-home result and forwarding resolver, folded recovery into the binding owner, combined pending/completed path storage, and removed a forwarding alias.
Native Codex source checked
The native app-server resolves one home into its configuration manager: app-server/src/lib.rs. Native home validation is in utils/home-dir/src/lib.rs.
thread/listdispatches to its asynchronous thread-store query in thread_processor.rs and the query loop. The measured cost here belongs to OpenClaw's registration-time roster, not nativemodel/list.Evidence
Fresh Codex autoreview in branch mode against
origin/mainis scoped-clean at P1.The original measured candidate build passed in 22m 23s. The current CI repair build passed in 11m 37s with no
[INEFFECTIVE_DYNAMIC_IMPORT]output.git diff --checkpassed. Build and fleet timings were captured on3af0b2dd23a62a7b0116fb36d4091d02fc159ab1(treead2993dd5e668a2c13b9d86ad68fa0bc99d4df02). Aftermainadvanced, the branch was rebased, preserving its new cache, managed-thread store, and compaction changes. The later CI repair puts connection policy behind a real lazy runtime boundary and binds the published generation callbacks; the original timing measurements remain historical evidence. The full boot was not repeated after rebase; the final head has fresh integration tests, typechecks, lint checks, and branch review.All 375 focused tests passed after compression, including a cold agent request after startup and adding/removing agents after boot. After rebase, 187 integration tests and 29 registration tests passed. Both production and test typechecks passed on the final source. The other changed-check lanes passed; extension lint uses the approved local substitute below.
Direct type-aware oxlint and oxfmt pass on the current changed extension files. The registration fixture has an existing file-length warning; this PR adds no lines or suppression to that file. A temporary one-line
debugger;canary made oxlint fail with exit 1 andeslint/no-debugger; the original file was restored byte-for-byte. The substitute also caught a shadowed variable and two Promise-executor returns, which were fixed before the clean run.lint extensionscould not run locally because of the nested-checkout boundary guard; CI runs it.The isolated rig uses 200 separate workspaces and 200 agent databases created through the product bootstrap, independently verified at schema 21, with 54 configured models per agent (10,800 entries), 12 enabled bundled plugins, no channels, loopback, and a free port. Baseline and candidate use separate fresh state directories. The Gateway runs built
dist/entry.json Node 24 with startup tracing, one health probe per second (5-second timeout), event-loop sampling, RSS sampling, and CPU profiling. The rig is local untracked test support, not shipped code.buildSnapshotinclusive CPU samplesplugins.runtime-post-bind/healthanswered during post-bind pluginsThe baseline's per-span event-loop histogram reported zero while its timer was starved; this is not evidence of a responsive event loop. CPU samples and health probes supply the attribution. Other startup owners remain outside this PR. The candidate reached ready at 730.9 seconds and answered 80/90 probes during the next 90 seconds; broader startup starvation remains. Whole-process peak RSS was 1,801.1 MiB (baseline 1,412.7 MiB), with the candidate peak occurring in bootstrap before plugin registration. No total-boot or total-memory improvement is claimed. Both Gateways exited cleanly with code 0. Measurements ran on a shared host, so the scoped CPU attribution and boundary tests accompany the wall times.
Boundary proof: the startup regression failed on the original code with two eager runtime preparations (expected zero). Focused tests cover cold selected-agent requests, a stalled obsolete discovery while HTTP and a replacement owner progress, config-added/removed agents, warm requests without repeated directory polling, bounded shared discovery, cold secondary-home binding recovery before catalog browsing, and ownership retarget rejection while unrelated bookkeeping updates remain valid.
Exact-head CI repair
The first CI run caught three authoring defects. Connection policy now loads through
binding-connection.runtime.tsonly for an actual request, so the unchanged registration import test no longer reaches the installed-manifest registry. Both published generation callbacks bind their snapshot owner. Compaction consumes the agent ID already resolved by the binding identity; nine diagnostics confirmation cases moved intact to a colocated suite and share the existing fixtures.compact.tscommands.test.tsThe canonical line-cap, suppression, and assertion ratchets pass without baseline edits or new suppressions. The requested suite union passed 601 tests across 19 files, including the unchanged registration boundary and native catalog test. The final listing test rerun passed 18 tests. Both typechecks and the database-first, media, runtime-sidecar, and import-cycle guards pass. The approved type-aware lint substitute rejected an intentionally unbound-method canary with exit 1; the canary was restored byte-for-byte before the clean lint run.
The full repair build passed without
[INEFFECTIVE_DYNAMIC_IMPORT]; the shared fleet rig remains untouched and was not rerun. Exact-head CI is tracked on this PR.Repair head:
d142bf2a0d38679e6ac9abb848269baf77ed6530. Fresh branch-mode Codex autoreview againstorigin/mainis scoped-clean at P1.