Skip to content

improve(gateway): avoid redundant startup preflight work - #147285

Merged
steipete merged 2 commits into
mainfrom
codex/gateway-startup-preflight
Sep 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/gateway-startup-preflight

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #147165

What Problem This Solves

Gateway startup repeats plugin discovery and SQLite schema inspection before it can become ready.

User Impact

The measured warm-filesystem readiness median fell from 11.37 to 10.32 seconds (about 9%) on Windows with an isolated synthetic configuration. These are small-sample measurements, not a cold-start guarantee. No configuration or database migration is required.

Why This Change Was Made

Early proxy/diagnostics config reads now use the existing core-only policy; full plugin validation still runs during startup admission. The two schema policies reuse the existing table reader within the same private or immutable snapshot, while later admissions continue to read fresh facts.

Evidence

  • Same base, Node 26.8.2, runtime build profile, isolated state/free ports, asynchronous HTTP probes, one discarded warmup and three measured fresh processes. Readiness samples: before 11.106/11.365/12.714 s; after 10.268/10.324/10.444 s.
  • Warmup caveat: the first after-run exceeded the unchanged 60-second probe limit; an identical retry discarded a 38.257-second warmup before the stable measured samples. Unchanged early phases were also anomalously slow; the cause is not established.
  • Existing three-case Gateway invocation regression failed before the fix and passes afterward. Linux validation passed all 284 selected CLI/config/artifact tests. Windows validation passed 406 tests with one skipped; all 11 failures reproduce on the original code and the corresponding Linux suites pass.
  • Full build and matching runtime-only build passed, including bundled plugins, bootstrap checks, SDK exports, and UI. Complete changed-file checks passed, including production/test typechecks, lint, formatting, and storage/import guards.
  • Independent review completed with no blocking findings. A diagnostic profile shows two metadata loads instead of three and less duplicate snapshot inspection. Worker experiments remain outside this patch.
  • CI exposed an inherited QA workflow routing assertion that omitted the newly added qa-profile-run-status test. The expected target list now includes that test; routing and exact assertions are unchanged. The original failure reproduced locally before the correction; all 639 routing/QA tests and the complete selected static checks passed afterward. A fresh four-file independent review found no blocking issues.

@clawsweeper

clawsweeper Bot commented Sep 13, 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.

@steipete
steipete marked this pull request as ready for review September 13, 2026 18:48
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS maintainer Maintainer-authored PR labels Sep 13, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 3:18 PM ET / 19:18 UTC (Revision 2).

ClawSweeper review

What this changes

The PR reduces Gateway startup work by avoiding early plugin discovery, sharing SQLite schema inspection within one snapshot, and updating CLI and test-routing expectations.

Merge readiness

✅ Ready for maintainer review

Keep open as a useful, bounded optimization with no blocking findings. Current main still performs the redundant work, and the maintainer explicitly accepted the earlier measurement limitation.

Priority: P3
Reviewed head: 9e117789b5bea774cece9655eb2c9e45ab50060a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization using established contracts, supported by relevant real startup measurements and reported regression validation.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied body records real Windows Gateway launches through HTTP readiness probes after the CLI and snapshot-inspection changes, with lower measured warm-start times and fewer metadata loads. The disclosed warmup anomalies limit performance generalization and were explicitly accepted by the maintainer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied body records real Windows Gateway launches through HTTP readiness probes after the CLI and snapshot-inspection changes, with lower measured warm-start times and fewer metadata loads. The disclosed warmup anomalies limit performance generalization and were explicitly accepted by the maintainer.
Evidence reviewed 10 items Current main still contains the redundant work: Fetched main retains the early skipPluginValidation policy and independently collects table contracts for both schema policies; the proposed optimization remains distinct.
Existing core-only policy preserves the intended boundary: Core-only validation avoids manifest discovery during materialization. The early configuration result feeds proxy and diagnostics setup; Gateway startup separately reads a full configuration snapshot with plugin metadata.
Full Gateway configuration validation remains: readGatewayStartupConfig calls readConfigFileSnapshotWithPluginMetadata without the core-only override, retaining the later plugin-aware startup read.
Findings None None.
Security None None.

How this fits together

Gateway startup reads configuration and checks stored databases before admitting the runtime. This change reduces repeated preparation while preserving full plugin validation and database compatibility checks.

flowchart TD
  A[Gateway command] --> B[Early core configuration read]
  B --> C[Proxy and diagnostics setup]
  C --> D[Full startup validation]
  E[Private database snapshot] --> F[Shared table inspection]
  F --> D
  D --> G[Gateway ready or startup error]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests +1. Total +6 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 6 1 +5
Tests 2 3 2 +1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 9 3 +6

Review metrics

Metric Value Why it matters
Observed warm startup Median 11.365 → 10.324 seconds; 3 samples per version The reported improvement is about 9%, with explicitly disclosed warmup anomalies and no cold-start guarantee.

Technical review

Best possible solution:

Reuse existing validation and snapshot-local inspection contracts while keeping full startup admission and fresh checks on later opens.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a functional bug reproduction: this is a performance optimization, supported by source-visible duplicate work and reported before/after Gateway readiness measurements.

Is this the best way to solve the issue?

Yes. The patch reuses existing owners, keeps caching within an unchanged snapshot, and leaves full plugin admission and persisted formats unchanged.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 38a482832a67.

Labels

Label justifications:

  • P3: This is a bounded startup efficiency improvement with no demonstrated broken user workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 supplied body records real Windows Gateway launches through HTTP readiness probes after the CLI and snapshot-inspection changes, with lower measured warm-start times and fewer metadata loads. The disclosed warmup anomalies limit performance generalization and were explicitly accepted by the maintainer.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied body records real Windows Gateway launches through HTTP readiness probes after the CLI and snapshot-inspection changes, with lower measured warm-start times and fewer metadata loads. The disclosed warmup anomalies limit performance generalization and were explicitly accepted by the maintainer.

Evidence

What I checked:

  • Current main still contains the redundant work: Fetched main retains the early skipPluginValidation policy and independently collects table contracts for both schema policies; the proposed optimization remains distinct. (src/cli/run-main.ts:1224, 38a482832a67)
  • Existing core-only policy preserves the intended boundary: Core-only validation avoids manifest discovery during materialization. The early configuration result feeds proxy and diagnostics setup; Gateway startup separately reads a full configuration snapshot with plugin metadata. (src/config/validation.ts:237, 9e117789b5be)
  • Full Gateway configuration validation remains: readGatewayStartupConfig calls readConfigFileSnapshotWithPluginMetadata without the core-only override, retaining the later plugin-aware startup read. (src/cli/gateway-cli/run.ts:262, 9e117789b5be)
  • Schema cache stays within one inspection: The reader is created inside inspectCurrentStateStartupSchema and shared only between its two synchronous comparisons. Callers use private or immutable snapshots; subsequent preflights create new readers. Ownership, integrity, version checks, and compatibility policies remain intact. (src/state/openclaw-database-preflight.ts:219, 9e117789b5be)
  • Existing compatibility regression coverage: The database tests exercise both explicit preflight and Gateway admission against legacy additive columns and genuine schema drift, checking that source artifacts remain unchanged. The CLI regression retains all three Gateway invocation cases. (src/state/openclaw-database-preflight.test.ts:303, 9e117789b5be)
  • QA routing expectation matches its consumer: The added expected target directly reads qa-profile-evidence.yml. The patch updates the exact expected target list without changing routing implementation or weakening assertions. (test/scripts/qa-profile-run-status.test.ts:20, 9e117789b5be)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vito Cappello: 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 (1 earlier review cycle)
  • reviewed 2026-09-13T18:56:28.294Z sha 400e0c3ec580bbd95f6432e94caf9da2557a1ec9 :: blocked before merge. :: none

@steipete
steipete force-pushed the codex/gateway-startup-preflight branch from 400e0c3 to 9e11778 Compare September 13, 2026 19:10
@steipete

Copy link
Copy Markdown
Contributor Author

Reviewed the remaining measurement-risk note. The PR claims only the observed warm-filesystem result from three samples per version; it retains the failed warmup and the 38.257-second discarded warmup in its evidence and makes no cold-start guarantee. The optimization removes source-visible duplicate work through existing core-only config and snapshot-local schema-reader contracts. Full plugin admission and fresh checks on subsequent database opens remain intact. This limitation is acceptable for landing the bounded change.

The refreshed head also corrects the inherited QA workflow routing assertion exposed by CI. All 639 routing/QA tests and the complete selected static checks pass, and a fresh four-file independent review found no blocking issues. Required hosted CI for the repaired head is still pending.

@steipete
steipete merged commit ac59d5e into main Sep 13, 2026
194 of 195 checks passed
@steipete
steipete deleted the codex/gateway-startup-preflight branch September 13, 2026 19:29
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit 'ac59d5e09eb468dc23cf95e447608b57e71b52af': (176 commits)
  improve(gateway): avoid redundant startup preflight work (#147285)
  test(macos): observe readiness cancellation and deadline ownership (#145056)
  fix(ci): route QA Profile Evidence to its run-status owner test (#147293)
  fix(install): preserve runtime links when Node validation fails (#147221)
  test(auto-reply): reuse memory session fixtures (#147262)
  fix: hide subagent sessions from Activity (#147253)
  ci: record resources for slow runtime test commands (#147254)
  fix(update): recognize FreeBSD boot identities in triage leases (#147243)
  refactor(active-memory): share closing tag line scan (#147031)
  fix: resume Settings autosave after Reload Config (#147136)
  fix(cli): keep conversation context after cancellation (#147139)
  fix(channels): make system-agent approval cards actionable (#147152)
  refactor: retain shared database handles until their last worker closes (#147246)
  refactor(slack): share workspace-qualified target resolution (#147024)
  refactor(msteams): remove duplicate quoted-table test (#147270)
  fix(qa): bind coverage IDs to producer assertions (#144000)
  fix(linux): explain FreeBSD desktop setup prerequisites (#147211)
  fix(memory): split embedding batches rejected for an input array item cap (#139541)
  test: isolate timing metadata persistence from inherited settings (#147112)
  refactor(status): retire test-only helper publication (#147071)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
…7285)

* improve(gateway): avoid redundant startup preflight work

* test(ci): include QA profile status in workflow routing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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