Repository navigation
perf(gateway): serve the listener before multi-gigabyte store validation and honor clean-close receipts at startup - #163690
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 October 2, 2026, 4:24 PM ET / 20:24 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR lets the Gateway serve while slow agent databases finish validation, reuses clean-close receipts without copying entire stores, adds startup diagnostics, and repairs affected test fixtures. Merge readiness✅ Ready for maintainer review The PR remains useful: current main still blocks startup on the long inspection budget and copies clean closed-WAL stores. No actionable introduced defect was found, and the supplied runtime comparison provides strong evidence for the improvement. Priority: P2 Review scores
Verification
How this fits togetherGateway startup validates stored agent data before permitting writes and inference. This change lets the HTTP listener and healthy agents become available while the existing admission owner finishes slower stores. flowchart TD
A[Gateway startup] --> B[Database admission owner]
B --> C[Receipt and integrity checks]
C --> D{Foreground work finished?}
D -->|Yes| E[Admitted agents]
D -->|No| F[Background validation with agent fenced]
F --> E
D --> G[Listener and readiness details]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +81, Tests +245, Docs +24. Total +350 across 25 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep database validation with the existing admission owner while allowing the listener to serve, with explicit pending-agent diagnostics and strict update-canary checks. Do we have a high-confidence way to reproduce the issue? Yes: current-main source establishes the long foreground wait and closed-WAL copy path, and the supplied controlled built-CLI comparison demonstrates their impact. This read-only review did not execute current main. Is this the best way to solve the issue? Yes: the patch repairs scheduling and receipt reuse in their existing owners, preserves full validation and agent fences, and avoids new configuration or persistence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b4d1a0efc8a9. LabelsLabel changes: No label changes. Label 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)
|
2e07394 to
12ab04a
Compare
12ab04a to
9fe7e61
Compare
Bound foreground agent inspection without shortening validation or weakening write admission. Reuse clean closed-WAL receipts without full-file copies, preserve pending admission across bootstrap, and expose startup phase timings. Normal readiness can serve while agents warm; update canaries retain strict validation. Testbox proof on a 28.1 GiB synthetic store with Node 26.10: clean readiness 365.10s to 9.94s; crash readiness 58.68s to 11.48s, with agent admission completing at 35.70s. Focused tests and regression negative controls passed. Independent review found no actionable P0-P2 issues. Final staged validation continues after the line-cap correction.
9fe7e61 to
1f52096
Compare
Join the first native age publication before releasing placement protection. Replace the host-only clock mock with a managed backdate through the existing entry writer, keeping all preservation and archive assertions intact.
* commit '79be075e5aa46be9e42dbd53ed6e30e81469210a': (33 commits) fix(ui): keep selected-text comment input readable while scrolling (#163772) test(memory): open corpus database explicitly fix: bound Doctor migration capture to plugin data (#163780) fix(ui): gate system information at the shared reader (#160982) chore(db): reclassify worker inventory sites with caller evidence (#163754) refactor(channels): deslop Slack and Matrix (#163740) fix(agents): reject empty sessions_search queries in the tool schema (#129120) perf(nodes): load only what a worker turn needs (#160442) test(cli): assert concise Gateway failure copy in CLI process tests (#163649) refactor(discord): deslop discord (#163728) fix(workboard): make Sessions boards work on multi-agent Gateways (#163761) test(gateway): add sustained heap retention diagnostics (#163764) test(ui): disambiguate session filter controls refactor(plugins): deslop imessage, mattermost, and voice-call (#163767) fix(qa): run Telegram plugin source in --source-gateway userbot runs (#163718) feat(macos): add a --no-activate launch flag for background automation (#163758) fix(agents): preserve host authority across module reloads (#163725) perf(gateway): serve the listener before multi-gigabyte store validation and honor clean-close receipts at startup (#163690) fix: keep video widgets scrollable and preload initial frames (#163762) feat(memory): add a provider-neutral memory provider runtime (#162175) ...
…ion and honor clean-close receipts at startup (openclaw#163690) * perf(gateway): defer slow agent admission past listener startup Bound foreground agent inspection without shortening validation or weakening write admission. Reuse clean closed-WAL receipts without full-file copies, preserve pending admission across bootstrap, and expose startup phase timings. Normal readiness can serve while agents warm; update canaries retain strict validation. Testbox proof on a 28.1 GiB synthetic store with Node 26.10: clean readiness 365.10s to 9.94s; crash readiness 58.68s to 11.48s, with agent admission completing at 35.70s. Focused tests and regression negative controls passed. Independent review found no actionable P0-P2 issues. Final staged validation continues after the line-cap correction. * perf(gateway): simplify startup admission and repair CI fixtures * test(gateway): invalidate worker age facts in placement maintenance Join the first native age publication before releasing placement protection. Replace the host-only clock mock with a managed backdate through the existing entry writer, keeping all preservation and archive assertions intact.
* commit '1fda703fb4d3630e4633461967b2a2186e8f15fd': (33 commits) fix(ui): keep selected-text comment input readable while scrolling (openclaw#163772) test(memory): open corpus database explicitly fix: bound Doctor migration capture to plugin data (openclaw#163780) fix(ui): gate system information at the shared reader (openclaw#160982) chore(db): reclassify worker inventory sites with caller evidence (openclaw#163754) refactor(channels): deslop Slack and Matrix (openclaw#163740) fix(agents): reject empty sessions_search queries in the tool schema (openclaw#129120) perf(nodes): load only what a worker turn needs (openclaw#160442) test(cli): assert concise Gateway failure copy in CLI process tests (openclaw#163649) refactor(discord): deslop discord (openclaw#163728) fix(workboard): make Sessions boards work on multi-agent Gateways (openclaw#163761) test(gateway): add sustained heap retention diagnostics (openclaw#163764) test(ui): disambiguate session filter controls refactor(plugins): deslop imessage, mattermost, and voice-call (openclaw#163767) fix(qa): run Telegram plugin source in --source-gateway userbot runs (openclaw#163718) feat(macos): add a --no-activate launch flag for background automation (openclaw#163758) fix(agents): preserve host authority across module reloads (openclaw#163725) perf(gateway): serve the listener before multi-gigabyte store validation and honor clean-close receipts at startup (openclaw#163690) fix: keep video widgets scrollable and preload initial frames (openclaw#163762) feat(memory): add a provider-neutral memory provider runtime (openclaw#162175) ...
What Problem This Solves
Gateway startup can spend minutes copying and validating a multi-gigabyte agent database before opening its listener, including after a clean shutdown.
User Impact
Normal Gateway starts can serve the Control UI and healthy agents while a slow agent finishes admission. Pending agents remain unavailable for writes and inference, and readiness exposes their pending admission details. Confirmed failures still fail readiness. Update canaries retain foreground validation and strict readiness. No schema or public configuration changes are required.
Why This Change Was Made
The foreground wait reused the full SQLite inspection deadline (about 48,940 seconds for 38 GiB), so ordinary slow scans never reached the existing background admission path. Agent inspections now share a five-second foreground budget, and the later schema preflight reuses the same owner's pending decisions instead of copying the pending store again. Unowned custom stores retain strict foreground inspection.
A clean closed WAL store normally has no WAL/SHM files. Its previous preflight path copied the entire database and could not reuse the source receipt. A matching clean-close receipt now permits SQLite's normal locked read-only source transaction, including creation of empty WAL sidecars. Inspection rechecks the receipt before skipping the scan; dirty, incomplete, revoked, changed-version, or nonmatching proof retains validation. Existing stale-lease and write-admission fences remain in force.
Default startup phase diagnostics identify CLI import/configuration preparation, database admission, listener binding, and readiness without requiring tracing to be enabled beforehand.
Evidence
Reported Team timeline: boot 1 started 07:59:27, first
loading configurationat 08:01:58 (151 seconds silent), agent database open 148,434 ms, listener 08:04:43, ready 08:04:48 (321 seconds total). Boot 2 started 08:30:30, first configuration log 08:34:00 (210 seconds silent), stale leaseowner-pid-dead, agent open 45,135 ms, ready 08:35:01 (271 seconds total). Agent store: 38 GB; shared state: 534 MB; Node 26.10.Controlled dist-CLI comparison on base
14fd53f8f69b, with and without this patch: providerblacksmith-testbox, profileopenclaw-check, leasetbx_01m3ynk19hgfeh9628d4k4h8j4(runner). Node 26.10.0, four effective CPUs, 16 GiB RAM, one 30,131,793,920-byte (28.1 GiB) valid synthetic agent database. Clean runs verified a genuineclean_close=1receipt; crash runs killed the fixture's admitted owner and verified dirty proof. The CLI wasnode dist/index.js gateway --port <isolated-port>, with noNODE_OPTIONS.Times run from child exec to the first successful HTTP probe, sampled every 100 ms. Both scenarios served the Control UI with HTTP 200. Candidate WebSocket upgrades completed at 9.12 s (clean) and 10.61 s (crash). After the crash, readiness reported the agent as inspection-pending; background admission completed at 35.70 s. Both Gateway runs then exited cleanly. The baseline clean boot took 359.40 s before
loading configuration; the earlier candidate repetition reached clean/crash readiness in 7.63/11.63 s, so the result is not dependent on one fast candidate sample.The full baseline
pnpm buildpassed (14m 28s). Runtime measurements used the repository'ssourcePerformancebuild profile plus Control UI assets. All selected candidate files were verified byte-for-byte before the final comparison. The later rebase onto4e3ab7babc2fwas patch-identical; these timing numbers remain evidence for the controlled base above.Regression negative controls restored the original scheduler and read-only inspection implementation: the five-second queue-budget test failed because foreground work remained pending, and the clean-WAL test failed because it still needed a full-file copy. Restoring the candidate passed the focused tests. The new test bodies took 8 ms and 689 ms in that negative-control run; compiler preparation dominated its 25.62 s wall time. CLI proof (
node scripts/run-vitest.mjs --config test/vitest/vitest.cli.config.ts src/cli/startup-trace.test.ts src/cli/run-main.gateway-startup.test.ts --maxWorkers=1) passed all 35 tests in 23.96 s. The final unit/Gateway command passed both shards in 87.99 s, including all 12 Gateway recovery/canary cases. Earlier receipt-policy, prepared-bootstrap, and readiness coverage also passed. These are single-worker wall/CI seconds, not CPU-time measurements.Independent Codex review returned scoped-clean at P0–P2. The first focused run found one stale queued-agent readiness expectation; it was updated to the new 200-with-pending-details behavior, and the rerun passed. The staged gate caught a redundant extra log line exceeding the CLI file's growth cap; that line was removed while retaining the owning phase diagnostics.
Final checks on rebased head
2e073945f8f1passed on leasetbx_01m3yt3xp0jw6hhzshy7amxqga(runner):node scripts/check-changed.mjs --staged --base HEAD^, including core typechecking, all 27 test typecheck graphs, lint, dead exports, and required guards; the CLI suite (35 tests, 27.36 s); the focused unit/Gateway command (both shards passed in 110.47 s, including 49 Gateway tests); andpnpm docs:list. Its source commit and all 21 changed files were verified before execution. The earlier lease ended after its measurements and focused tests; the initial leasetbx_01m3ymtsfszsntmm2qpm4tg51zwas stopped while still queued.Gap: this is a synthetic Linux store with small shared state, not live verification of Team's 38 GB btrfs store and 534 MB shared-state database. Deployment remains with the owning Team workflow.
Final CI repair and simplification
Current head:
d69022f4feb4. The final diff contains only this lane's startup changes and retained fixture repairs. Main's fixes for registry fixture drainage (49135a709150), Codex error-copy/lifecycle diagnostics (eb978fd65e31), and bundled-plugin warnings (fb419a46b1a2) were incorporated by rebase; their files are unchanged from main. No upstream fixes were cherry-picked or copied into lane commits.The scheduler owns one foreground timer for the fleet. Per-store timers, size reads, active-set bookkeeping, and the redundant path callback are deleted. Full inspection deadlines remain with the inspection owner; canaries and unowned stores stay strict. The retained CI repairs join asynchronous fixture owners before damaging startup-index files, establish the placement fixture's intended warm reader, and explicitly request snapshots in the snapshot-cleanup test. A later inherited maintenance fixture timeout is fixed by joining native age publication and using a real managed backdate instead of advancing only the host clock. All preservation, deletion, lineage, archive, identity, and timeout assertions remain.
Production LOC: +153/-72, net +81, reduced from +94. The scheduler itself is net -5. The growth exception is specific: +49 lines supply default startup phase diagnostics, including otherwise-silent entry imports; +12 preserve strict canary/unowned-store admission; +12 report pending stores without hiding confirmed readiness failures; +11 admit clean closed WAL files through receipt checks and ordinary SQLite locks; +2 reuse the startup owner's pending refusals during bootstrap. No new cache, configuration, schema, or competing owner is introduced. Measurement command:
git diff --stat origin/main...HEAD -- ':!*.test.ts' ':!*test-support*' ':!docs/*'.The original six failed jobs in run
37044412764were fetched once. Pinned-main proof reproduced the Codex, plugin-warning, placement, registry, and startup-index failures. The snapshot-cleanup failure was a fixture that no longer selected its intended private-snapshot operation after clean-close optimization. A subsequent run,37053386762at1f52096f8687, had one root failure: the host-clock maintenance fixture. Its published-driver update job passed. The final repair has a deterministic negative control and passing proof below; final-head CI is tracked separately.blacksmith-testbox,tbx_01m3ywzd28ym8r5amfn7vq7wnhnode scripts/run-vitest.mjs --config test/vitest/vitest.runtime-config.config.ts src/config/sessions/startup-migration.registry-recovery.test.ts --maxWorkers=1: main 4 failed / 10 passed (29.62 s); candidate 14 passed (36.42 s).node scripts/run-vitest.mjs --config test/vitest/vitest.infra.config.ts src/state/openclaw-database-preflight.startup-index.test.ts --maxWorkers=1: candidate 8 passed (19.98 s). Main reproduced two byte failures before a worker SIGKILL (54.56 s); remaining baseline cases did not finish.--maxWorkers=1.node scripts/check-changed.mjs --stagedpassed core types, all 27 test typecheck graphs, formatting, lint, exports, and required guards;pnpm docs:listpassed. Final focused-test/gate/docs payload exited 0 in 29m57s.blacksmith-testbox,tbx_01m3z038raz5bxtesmy1nw4h7kaws,cbx_6427129dab83node scripts/run-vitest.mjs --config test/vitest/vitest.gateway-database-workers.config.ts src/gateway/server-worker-placement-startup-maintenance.test.ts --maxWorkers=1: the ordering-controlled old-clock negative control hit the unchanged 120-second timeout after its worker-age and archive-wait markers (155.85 s wall). Final file: all 7 passed in 28.80 s wall / 4.25 s test time; dashboard case 997 ms.node scripts/check-changed.mjs --stagedpassed, including Gateway-server types (13.8 s), lint, exports, and guards. Full negative-control/test/check/cleanup payload exited 0 in 8m07s command time, 16m44s end-to-end.All 171 selected tests have passing proof across the unchanged implementation and scoped follow-ups. The complete staged gate is explicitly prior-head evidence: the 24 retained files before the final fixture correction are byte-identical to reviewed, fully checked
12ab04a68d2e; the final correction has its own staged gate and review. The rebases only retire duplicate fixes now on main. Both original candidate reviews and the final fixture review returned scoped-clean at P0–P2.Testbox used profile
openclaw-check, Node 24.19.0, and pnpm 12.5.1. Exact candidate bytes were SHA-256 verified in pinned detached checkouts. The generic test selector omitted the two storage suites, which were run with their owning configs. Runtime preparation passed on baseline, candidate, and rebased candidate (37.3 s, 34.4 s, 41.2 s). Native suites retain their real Gateway/process boundary because mock-only proof cannot establish physical exit and thread custody; exact foreground timing uses fake clocks.The initial lease
tbx_01m3ywv9c9vg36bq796nxdk06rwas stopped for the first rebase. The final fixture's Testbox leasetbx_01m3z1rnw399qx1phcgnr1gqbtqueued for 16 minutes and ended in hydration failure, so the updated provider fallback rule was used. AWS run:run_d17a37073114877d496a4e604f1efe5f. All owned leases are stopped/released and temporary remote proof worktrees removed. Initial tooling-only setup failures were corrected by pinning the proof checkout and installing its complete workspace dependencies; no checks or source guards were bypassed.Gap: the large-store timings above retain their original controlled Node 26 identity. This continuation does not claim a new 28 GiB benchmark or live Team verification.
Final-head GitHub CI: passed on
d69022f4feb4, run 37059478912. All 96 jobs completed with no failures, including the previously failing maintenance shard and the published-driver update check.