Skip to content

fix(codex): avoid fleet startup stalls during catalog registration - #150004

Merged
steipete merged 3 commits into
mainfrom
upd/fleet-codex-catalog-homes
Sep 16, 2026
Merged

steipete merged 3 commits into
mainfrom
upd/fleet-codex-catalog-homes

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

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 createCodexCatalogHomeResolver constructor 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.

Remaining production delta Capability preserved
Roster and prepared-home identity: +49 On-demand generation facts, bounded shared candidates, real yields, and canonical hashing without freshness polling
Binding owner, lazy policy module, and removed eager map: +31 Cold secondary-home recovery through the existing managed plugin runtime slot; only a guarded fingerprint match can be admitted
Async callers and control contracts: +81 Propagate lazy discovery through existing entry points and preserve current-owner checks across awaits, including native tools and diagnostics
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/list dispatches 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 native model/list.

Evidence

Fresh Codex autoreview in branch mode against origin/main is 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 --check passed. Build and fleet timings were captured on 3af0b2dd23a62a7b0116fb36d4091d02fc159ab1 (tree ad2993dd5e668a2c13b9d86ad68fa0bc99d4df02). After main advanced, 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 and eslint/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 extensions could not run locally because of the nested-checkout boundary guard; CI runs it.

node_modules/.bin/oxlint --tsconfig test/tsconfig/tsconfig.extensions.test.json $(git diff --name-only origin/main...HEAD -- extensions/codex)
node_modules/.bin/oxfmt --check $(git diff --name-only origin/main...HEAD -- extensions/codex)

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.js on 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.

/opt/homebrew/opt/node@24/bin/node .local/fleet-serve/run.mjs 200 pr-c-before-200 profile observation
/opt/homebrew/opt/node@24/bin/node .local/fleet-serve/run.mjs 200 pr-c-after-200 profile observation
200-agent measurement Before After
Codex registration 29.7914 s 12.2 ms
Roster buildSnapshot inclusive CPU samples 29.755 s Eager path removed
plugins.runtime-post-bind 30.7557 s 996.7 ms
/health answered during post-bind plugins 0/30 0/2
Peak RSS in post-bind plugins 958 MiB 944.8 MiB

The 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.ts only 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.

Counted lines Base Failed head Repaired
compact.ts 953 954 942
commands.test.ts 7188 7192 6600

The 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 against origin/main is scoped-clean at P1.

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 12:47 PM ET / 16:47 UTC (Revision 3).

ClawSweeper review

What this changes

Defers 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
Reviewed head: d142bf2a0d38679e6ac9abb848269baf77ed6530

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent repair with strong scoped runtime evidence, meaningful regression coverage, and no blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The recorded isolated Gateway run exercises actual Codex registration and shows the scoped improvement on the historical candidate; final-head build and regression results supplement it. The maintainer explicitly accepts this owner-level scope without another whole-fleet run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The recorded isolated Gateway run exercises actual Codex registration and shows the scoped improvement on the historical candidate; final-head build and regression results supplement it. The maintainer explicitly accepts this owner-level scope without another whole-fleet run.
Evidence reviewed 11 items Current main still contains the startup cost: The fetched main implementation calls buildSnapshot during resolver construction, projects every agent, and populates the separate connection-home map. Plugin registration constructs this resolver before the session-catalog enablement check, so disabling catalog presentation does not provide an equivalent repair.
Lazy discovery and cold recovery share one owner: The introduced resolver publishes through the existing plugin runtime store, caches directory facts by configuration generation, yields during discovery, and preserves the 100-host bound. Binding recovery selects a matching source fingerprint and rechecks both source generation and caller ownership before returning connection options.
Request ownership reaches dispatch: Native tools and diagnostics pass their current-owner checks through command RPC into the existing request owner. That owner rechecks after client acquisition and supplies the check to the final client request. Catalog operations retain their established captured-connection semantics after admission.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +161, Tests +419. Total +580 across 53 files.

View PR surface stats
Area Files Added Removed Net
Source 24 593 432 +161
Tests 29 1191 772 +419
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 53 1784 1204 +580

Review metrics

Metric Value Why it matters
Measured Codex registration 29.7914 s → 12.2 ms on 200 agents The historical production-path measurement isolates this startup owner without claiming whole-fleet recovery.
Production versus test growth Production +161 lines; tests/support +419 lines Production growth supports lazy discovery, cold binding recovery, and asynchronous ownership checks within the existing plugin.

Technical review

Best 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.

Labels

Label justifications:

  • P1: This repairs a measured multi-second registration stall in an active large-fleet Gateway availability regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The recorded isolated Gateway run exercises actual Codex registration and shows the scoped improvement on the historical candidate; final-head build and regression results supplement it. The maintainer explicitly accepts this owner-level scope without another whole-fleet run.
  • proof: sufficient: Contributor real behavior proof is sufficient. The recorded isolated Gateway run exercises actual Codex registration and shows the scoped improvement on the historical candidate; final-head build and regression results supplement it. The maintainer explicitly accepts this owner-level scope without another whole-fleet run.

Evidence

What I checked:

  • Current main still contains the startup cost: The fetched main implementation calls buildSnapshot during resolver construction, projects every agent, and populates the separate connection-home map. Plugin registration constructs this resolver before the session-catalog enablement check, so disabling catalog presentation does not provide an equivalent repair. (extensions/codex/src/session-catalog-homes.ts, 70747f3a8aeb)
  • Lazy discovery and cold recovery share one owner: The introduced resolver publishes through the existing plugin runtime store, caches directory facts by configuration generation, yields during discovery, and preserves the 100-host bound. Binding recovery selects a matching source fingerprint and rechecks both source generation and caller ownership before returning connection options. (extensions/codex/src/app-server/binding-connection.runtime.ts:45, d142bf2a0d38)
  • Request ownership reaches dispatch: Native tools and diagnostics pass their current-owner checks through command RPC into the existing request owner. That owner rechecks after client acquisition and supplies the check to the final client request. Catalog operations retain their established captured-connection semantics after admission. (extensions/codex/src/app-server/request.ts:364, d142bf2a0d38)
  • Focused regression coverage: Inspected coverage includes zero eager runtime preparation, replacement-generation progress during suspended discovery, warm requests without repeated directory polling, removed-agent rejection, bounded discovery, and primary/secondary-home recovery before catalog browsing. The supplied body reports 601 tests and the repaired build passing; this read-only review did not execute tests. (extensions/codex/src/session-catalog-homes.test.ts:15, d142bf2a0d38)
  • Recorded production-path measurement: The captured PR body at sourceRevision 302ad30bda55b19629f581568b360ed5eff06b31345453a181a4f750a4b158b9 records an isolated built Gateway with 200 product-bootstrapped agent databases: Codex registration decreased from 29.7914 seconds to 12.2 milliseconds. Measurements belong to candidate 3af0b2d, before the rebase and lazy-module repair; no final-head whole-boot measurement is claimed. (3af0b2dd23a6)
  • Maintainer confirms the bounded scope: The linked discussion explicitly separates this catalog-roster improvement from remaining model-runtime, maintenance, and native-memory work, and says the reporter need not rerun the fleet for this change alone: main (1611ca6d): Gateway reaches ready but never serves; every /health probe times out while the event loop is starved (632-agent fleet) #149538 (comment).

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • WhatsSkiLL: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-16T11:23:34.860Z sha 3af0b2d :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T11:39:11.557Z sha 03d40f6 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the upd/fleet-codex-catalog-homes branch from 03d40f6 to d142bf2 Compare September 16, 2026 16:39
@steipete
steipete merged commit 20e7001 into main Sep 16, 2026
102 of 103 checks passed
@steipete
steipete deleted the upd/fleet-codex-catalog-homes branch September 16, 2026 17:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant