Repository navigation
improve(gateway): avoid full database copies during startup checks - #147635
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 13, 2026, 9:42 PM ET / September 14, 2026, 01:42 UTC (Revision 3). ClawSweeper reviewWhat this changesGateway startup checks eligible agent databases directly in the existing read-only child process, avoiding full copies while preserving recovery snapshots and error details. Merge readiness✅ Ready for maintainer review This remains a useful optimization absent from inspected main. The supplied exact-head startup and upgrade evidence resolves the earlier proof request, and no actionable introduced defects were found. Priority: P2 Review scores
Verification
How this fits togetherGateway startup inspects stored agent databases before admitting migrations. These checks validate ownership, integrity, and schema compatibility, then allow startup or report a refusal. flowchart TD
A[Startup admission] --> B[Agent database family]
B --> C{Safe direct read?}
C -->|Yes| D[Read-only child transaction]
C -->|No| E[Private recovery snapshot]
D --> F[Ownership and integrity checks]
E --> F
F --> G[Wait for native close]
G --> H[Admit or report refusal]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +86, Tests +106, Docs +8. Total +200 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one readiness owner with fresh checks at both migration admissions and snapshots reserved for recovery or excluded sources. Do we have a high-confidence way to reproduce the issue? Yes: current main explicitly forces full readiness onto the snapshot path, and supplied before/after regression results exercise that condition. This read-only review did not execute tests. Is this the best way to solve the issue? Yes: extending the established inspector avoids a competing implementation while retaining fresh validation, native-close settlement, and recovery fallbacks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a7344f3d0355. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review The body now includes the completed exact-head build, package integrity, fresh-state startup, and published CI separately hit a three-second CLI fixture timeout in an unchanged test ( |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…penclaw#147635) Co-authored-by: VACInc <[email protected]>
Fleet database admission repeatedly started a schema-inspection process for every agent after #147635 enabled the heavier reader during Gateway startup. Reuse one reader in each of the existing two scheduler slots while preserving fresh reads, integrity and ownership checks, private-snapshot recovery, cancellation, and joined cleanup. Bootstrap tracing now records substeps, durations, repeated calls, and fleet counts. In the isolated 200-agent repeat boots, schema readers fall from 200 to two and database admission falls from 44.38s to 15.93s and 8.11s. Whole-startup timings remain variable; these measurements do not establish installed-updater compatibility or the reporter's 632-agent readiness target. No schema, configuration, backup, or rollback contract changes. Related: #148529, #149538. Thanks to @609NFT for the per-build fleet measurements and repeat-boot target. Validation: 41 focused tests, changed-file checks, build, scoped-clean Codex review, and isolated Gateway boots reaching readiness and exiting cleanly. Exact-head CI run 35177837447 is green for cb599c7. The published-driver upgrade proof and 632-agent whole-startup target remain explicit proof gaps under the maintainer disposition in the PR body.
) Fleet database admission repeatedly started a schema-inspection process for every agent after openclaw#147635 enabled the heavier reader during Gateway startup. Reuse one reader in each of the existing two scheduler slots while preserving fresh reads, integrity and ownership checks, private-snapshot recovery, cancellation, and joined cleanup. Bootstrap tracing now records substeps, durations, repeated calls, and fleet counts. In the isolated 200-agent repeat boots, schema readers fall from 200 to two and database admission falls from 44.38s to 15.93s and 8.11s. Whole-startup timings remain variable; these measurements do not establish installed-updater compatibility or the reporter's 632-agent readiness target. No schema, configuration, backup, or rollback contract changes. Related: openclaw#148529, openclaw#149538. Thanks to @609NFT for the per-build fleet measurements and repeat-boot target. Validation: 41 focused tests, changed-file checks, build, scoped-clean Codex review, and isolated Gateway boots reaching readiness and exiting cleanly. Exact-head CI run 35177837447 is green for cb599c7. The published-driver upgrade proof and 632-agent whole-startup target remain explicit proof gaps under the maintainer disposition in the PR body.
Summary
High Level TLDR
Avoid full agent-database copies for eligible Gateway startup checks while retaining both fresh integrity checks: initial admission and the reread under the migration lease.
What Problem This Solves
Gateway startup requests full migration readiness twice. Preflight excluded these requests from its existing direct-read child, so each admission copied the database family into a private snapshot before checking it. Large databases incurred repeated copying even when a read transaction was safe.
Root Cause
The preflight caller suppressed the existing direct-read owner when
requireStartupMigrationReadinesswas set. Startup readiness consequently took the snapshot path regardless of direct-read eligibility.User Impact
Eligible DELETE databases and complete WAL/SHM families avoid two logical database copies. Both passes still perform fresh integrity, foreign-key, ownership, schema, and canonical-readiness checks; results are not cached across the migration lease.
Closed/incomplete WAL families, hot journals, source exclusions, and canonical mutation scopes retain private snapshots. A source-reader lease lasts through native close, and cancellation joins closure. Native error details and legacy migration error identity survive child IPC; foreign secondary-agent isolation remains ahead of failure handling.
Why This Change Was Made
Extend the existing schema-inspection child rather than add another startup owner. Its timeout includes the database family size, and its bounded 64 MiB connection cache serves index-page revisits. No config option, schema migration, retention change, or weakened integrity policy is introduced.
Evidence
Real behavior proof
The original preflight fails the DELETE and complete-WAL regression cases when there is no room for a full snapshot. The candidate admits those databases through the real preflight entry point. Additional coverage verifies fresh rejection after foreign-key damage between passes, concurrent WAL writes, corrupt foreign secondary-agent isolation, error transport, recovery fallbacks, and cancellation.
On a synthetic 136,060,928-byte DELETE database, two admissions per sample took a median 1,044.39 ms before / 736.88 ms after (one warmup, three alternating pairs). Snapshot requests fell 2 to 0, avoiding 272,121,856 logical copied bytes per pair. These are warm-cache fixture results, not production startup latency or physical disk-I/O telemetry.
Verification
b9c61f816d92252ae628d23f25e82217721d7452. Package SHA-256:bb31208c657900d9081090c8782cede38e7d9cb5d853e4fa624a22987cb5bed7./healthzand/readyzboth returned HTTP 200. The initial shell probe expected curl, which the runner lacks; Node fetch independently verified both endpoints before the container was stopped.[email protected]updater to this exact packed candidate passed the canonical Dockersqlite-volumeupgrade-survivor scenario. Automatic migration, Doctor idempotence, health/readiness, history RPC, and restarted-state survival passed.Update behavior
The installed updater remains unchanged. Candidate startup selects the established direct-read or snapshot owner from current operator state; both migration admissions remain fresh. Recovery and integrity rejection behavior remains in place.
What was not tested
No live Gateway deployment or final large-production-state startup benchmark. Exact time savings and direct-read eligibility for every production startup family are not established. GitHub CI and ClawSweeper review are running for the published head.
Published-driver × candidate proof
The installed baseline updater performed the upgrade (
candidateInstallMode: updater,updateOutcome: success). Automatic migration was asserted before a standalone Doctor pass. The scenario retained 4,800 sessions, 23,890 events, and 2,200 cron jobs and verified history RPC for eight conversations across two agents before and after restart.Copied result:
This is synthetic compatibility proof, not a production performance comparison. The isolated run reused a runner built from the unchanged canonical
scripts/e2e/Dockerfilebare target.Maintainer regression proof
On the reviewed head
b9c61f816d92252ae628d23f25e82217721d7452, temporarily reversing the five production-file changes made the four DELETE/WAL startup regressions fail withNo space for a full agent database snapshot(4 failed, 5 passed). Restoring the reviewed production changes passed all 139 tests across nine suites:The native-reader consistency and lease-through-close cases passed on success, read failure, close failure, and cancellation. Those lifetime cases predate this PR and are preservation proof. No source changes were needed.
ClawSweeper review
The latest review of this exact head reports no actionable findings or before-merge items. Its earlier build and upgrade-proof request is resolved by the published evidence above; nothing remains to apply or skip. Production-scale performance remains unmeasured.
Release-note context and credit
Gateway startup no longer copies every eligible agent database twice while checking migration readiness; large installations start, and finish updates, faster with the same integrity checks.
Thanks @VACInc (#147635).