Skip to content

perf(gateway): move fleet skills discovery past readiness - #170933

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-startup-readiness-budget-20260919
Oct 13, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-startup-readiness-budget-20260919

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway startup waits for a fleet-wide skills scan even though workspace-scoped reads already prepare their own discovery, and early config selection imports the broader config facade for one snapshot read.

User Impact

Skills listeners register during startup; the initial fleet scan runs in the existing tracked post-ready maintenance task. On-demand workspace reads still await discovery. Main-session and subagent restart recovery remain intact, including interrupted turns. No config option, schema change, migration, or operator action is introduced; update/canary suppression and cleanup remain intact.

The early-runtime phase became much shorter, but overall readiness is neutral within observed variation. The <5-second readiness target is not met. Immediate agent acceptance and first replies remained below 10 seconds in all six synthetic runs. These measurements do not certify production timing.

Why This Change Was Made

Use the config IO factory directly with the same isolated environment, core-only validation, and observation policy. Keep recovery on its separate freshly cloned environment and retain future-version, reset, selection-hop, and drift checks. Register the skills listener before readiness, then join the initial scan inside the existing maintenance owner. Check closing after imports and after discovery so shutdown cannot start maintenance timers. Remove the unnecessary async import wrapper.

Production LOC delta: -1 (+19/-20, excluding tests, docs, and the generated mock ledger). No competing fast path, cache, or new lifecycle owner is added. The admission state snapshot stays unchanged: it binds recovery, schema admission, and plugin config to one generation. Removing it based on the earlier live-owner probe would weaken that contract.

Evidence

Three before and three after runs in an isolated Linux benchmark sandbox, restricted to CPU cores 64–127, 64 GiB, nice/idle I/O priority. Every command used the sandbox scope; no production database/config was read or copied. Synthetic fixture: 12 agent databases/workspaces, 6,000 sessions, 120,000 transcript events, 100,000 audit rows (half retained), 2,400 workspace files, config backup, bundled startup plugins, and a loopback mock inference provider. Gateways and mock providers bound only loopback ports >=40000. No Testbox/Crabbox allocation: focused local proof and PR CI follow the current validation rule.

Measurement (ms) Before runs 1 / 2 / 3 After runs 1 / 2 / 3
/readyz 200 15208 / 13928 / 20141 15466 / 12410 / 14920
Agent accepted after ready, including fresh connection 336 / 719 / 780 694 / 306 / 330
First mock reply after ready 5356 / 5541 / 7182 7208 / 6656 / 5820
Select environment 1728 / 1406 / 1536 1836 / 1381 / 1803
Pre-bootstrap 811 / 840 / 1227 851 / 804 / 1082
Admission state snapshot 1211 / 1186 / 1572 1492 / 1160 / 1448
Process bootstrap 5554 / 5095 / 6497 6441 / 4945 / 6318
Session admission 1684 / 1614 / 2250 1657 / 1587 / 2372
Session projection 939 / 947 / 1319 1070 / 891 / 931
Early runtime 3409 / 3138 / 5400 29 / 24 / 28
Skills listener 3390 / 3119 / 5379 6 / 6 / 8
Post-bind plugins 390 / 345 / 1022 844 / 686 / 687
Main-session recovery 639 / 580 / 1588 578 / 502 / 504
Plugin services 796 / 474 / 524 934 / 710 / 629
Subagent recovery 210 / 109 / 260 655 / 1019 / 1119
Sidecars total 1467 / 1047 / 1333 1795 / 1383 / 1276
Post-ready transcript maintenance 2368 / 2478 / 12312 12868 / 3069 / 2406

Readiness median: 15.21 → 14.92 seconds (neutral, -1.9%). Early-runtime median: 3409 → 28 ms. Acceptance median: 719 → 330 ms. First-reply median: 5.54 → 6.66 seconds; ranges overlap (5.36–7.18 vs 5.82–7.21 seconds), so this is not a first-reply speedup claim. Bootstrap/snapshot, session admission/projection, and remaining runtime/plugin work still dominate total readiness. Phases overlap, so table durations must not be summed; transcript maintenance stays post-ready and is not a readiness gate. Snapshot and recovery phases were investigated, not bypassed. The after measurements precede only deletion of the equivalent async import wrapper; PR CI builds the final source.

Validation:

  • oxfmt on all seven changed files: passed.
  • Repository oxlint on the six changed TypeScript files: passed; repeated for the final import-wrapper deletion.
  • pnpm test src/gateway/server-startup-early.test.ts src/cli/gateway-cli/pre-bootstrap.reset-invalid-config.test.ts src/cli/gateway-cli/run.option-collisions.test.ts --maxWorkers=1: 63 tests passed, 207.34 s wall time including cold worker-fixture compilation.
  • pnpm test src/gateway/server-startup-early.test.ts --maxWorkers=1 after closing-guard change: 15 tests passed, 76.85 s wall time (65.31 s Vitest duration, primarily fixture compilation).
  • pnpm test src/cli/gateway-cli/pre-bootstrap.process.test.ts --maxWorkers=1: 17 tests passed, 114.91 s wall time. Actual environment/recovery/selection flow proves unchanged state artifacts with and without backups, dotenv trust, reset/future-config safety, and authored drift refusal.
  • Benchmark runtime builds with the repository cliStartup profile: passed before and after. Full typecheck, suites, and E2E are delegated to PR CI.
  • git diff --check: passed.
  • Independent subagent review (autoreview route unavailable): clean after reviewing the diff, config IO parity, skills discovery, tracked maintenance, shutdown owner, and final import simplification. Autoreview refused before launch because the selected provider did not match operator configuration; no configuration was changed.

The skills regression proves early startup completes without waiting for a blocked scan, maintenance joins the scan, and closing fences the scan/timers. A pre-change execution of that regression was not run. Existing lifecycle coverage checks listener notifications and watcher shutdown. Initial CI run 38381004830 passed the selected typechecks, lint, security, E2E, and the remaining changed test lanes. It failed the mock-export ratchet because two synthetic config factories lacked isolation comments (now added), plus four process-wide timer-count assertions in startup-config-preflight.recovery.test.ts (24.52 s CI test duration). The unchanged recovery file passed all nine tests locally (89.62 s wall time).

The recovery proof now observes the exact acquired startup migration lease: after refusal, advance fake time by one minute and verify no further heartbeat calls. Existing refusal, authority, unchanged config, and no backup repair checks stay intact, including the distinction between stale and replacement leases. This scopes proof to startup renewal shutdown; it does not claim process-wide timer cleanup or identify CI's extra timer. The revised full file passed nine tests locally (130.39 s wall, 118.66 s Vitest duration). Final source: pnpm test src/commands/startup-config-preflight.recovery.test.ts --maxWorkers=1 -t 'refuses changed|does not restore a backup': four passed, five intentionally unselected, 80.24 s wall (65.86 s Vitest duration). CI run 38383349493 took 600 s elapsed and passed all 37 selected code-validation jobs, including recovery tests, types, lint, security, and E2E. Only the mock ledger ratchet failed: it required removing the two obsolete allowances for the removed facade mock and explicitly isolated factory. The canonical pnpm check:test-mock-exports --base origin/main --prune generated exactly those two deletions (9709 → 9707 entries), reviewed independently; no allowances were added. Final CI run 38384962387, head ad034ea5fc84f6229f241dfe68ebb0f76bbacf68: success, 42 executed jobs passed, no failures; 733 s elapsed including runner queues. Selected changed lanes, typechecks, lint, guards, docs, security, and E2E passed. No CI rerun or inherited-failure waiver was used. Independent subagent review of this CI repair found no actionable issues.

@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: S labels Oct 13, 2026
@steipete
steipete marked this pull request as ready for review October 13, 2026 10:05
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T10:30:22.932178Z 5439e01 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Oct 13, 2026
@steipete
steipete merged commit 21b0c8b into main Oct 13, 2026
124 checks passed
@steipete
steipete deleted the steipete/perf-micro-startup-readiness-budget-20260919 branch October 13, 2026 10:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…70933)

* perf(gateway): move fleet skills discovery past readiness

* test(gateway): prove startup renewal stops after refusal

* test(gateway): prune retired config mock allowances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant