Repository navigation
perf(gateway): avoid copying sealed state during startup - #186176
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR reads sealed startup config-health and plugin metadata directly under existing physical custody instead of copying the database. Example: Start with a cleanly closed 135,950,336-byte shared-state database and a retained config backup.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes a concrete startup copy that remains on main, and source review found no actionable code defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway startup requests config-health and plugin metadata through the shared-state reader, which returns admitted rows from an isolated SQLite reader or a private snapshot. flowchart TD
A[Gateway startup] --> B[Shared state read owner]
B --> C[Isolated metadata reader]
C --> D[Verified live owner read]
C --> E[Custody and seal verification]
E --> F[Immutable checkpoint read]
B --> G[Private snapshot fallback]
Technical reviewBest possible solution: Reuse the existing isolated reader, seal verifier, and custody owner to eliminate sealed-state copies while preserving private recovery and current-admission checks. Do we have a high-confidence way to reproduce the issue? Current main sends sealed offline metadata reads through snapshot preparation; the PR reports a base-failing copy-count regression, but this read-only review executed no target code. Is this the best way to solve the issue? This is a focused extension of existing owners: direct reads remain isolated, seal verification occurs under custody, and unsealed or contended cases retain the established fallback. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ab3fab2c37cf. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +44, Tests 0, Docs +5, Other +26. Total +75 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 27, 2026, 1:58 PM ET / 17:58 UTC. |
Read startup config health and plugin metadata from the verified clean checkpoint under physical custody in the isolated reader. Keep unclean recovery, live-owner reads, schema checks, and source artifacts unchanged. Extend the restart benchmark with clean and owned-child crash modes.
68521ad to
4b40b62
Compare
|
Admin-merging over Reviewed: the parent's seal check is only a hint. The worker re-reads the seal under schema-maintenance custody ( |
…6176) * perf(gateway): avoid copying sealed state during startup Read startup config health and plugin metadata from the verified clean checkpoint under physical custody in the isolated reader. Keep unclean recovery, live-owner reads, schema checks, and source artifacts unchanged. Extend the restart benchmark with clean and owned-child crash modes. * perf(gateway): keep sealed metadata reader dependencies acyclic
What Problem This Solves
Gateway startup copies the entire shared-state database to read a few config-health or plugin-metadata rows, even after a verified clean close.
User Impact
Clean startup avoids that copy. Crash recovery, live-owner reads, source artifacts, integrity checks, and split-brain protection retain their existing behavior. No configuration, schema, durability, or retention changes.
Why This Change Was Made
The isolated reader acquires existing physical custody without waiting, rechecks the existing clean-close proof, reads the checkpoint immutably, and closes the native reader before releasing custody. Missing proof or contended acquisition retains the private-snapshot path. The parent seal check is only a hint; it cannot authorize the read across an awaited worker startup.
Production delta: +44 lines. The growth retains physical exclusion through native close; an unguarded seal shortcut before Gateway lock acquisition would weaken reader consistency. There is no new cache or persisted state.
Evidence
The regression replaces an ineffective staging spy with the actual snapshot-preparation boundary. It fails on main because a sealed config-health read makes one full-database copy; the candidate makes zero. Existing observation reuse, committed-write invalidation, and stale-update conflict assertions remain. Net test-line delta is zero; the existing over-ceiling tree is accepted by the unchanged ratchet.
Local macOS / Node 26.12.1 owner measurements use the existing
scripts/perf/config-health-read-measure.ts, a synthetic 138,113,024-byte shared database, and AB/BA order. Timing and 4 KiB allocation-sampling passes are separate; each arm has two first-read samples and two 3,000-iteration warm samples.These owner measurements were refreshed after the import-cycle correction on the final head. All eight outputs have the same semantic fingerprint. Mean cold source-run wall time was 7.99 → 7.95 s under host load 69–90, so no source-run wall-time improvement is claimed. Worker CPU/allocation and native buffers are outside the owner measurements.
Built Gateway proof used 10,000 sessions, eight agents, 44 startup plugins, and five clean plus five SIGKILL restarts per arm, in counterbalanced order. All 20 restarts and one overlapping restart per arm preserved config bytes, backup bytes, semantic health/plugin facts, readiness, and seeded-session access over WebSocket. The harness signals only its own recorded child PIDs. No Team access.
Clean health-read ranges were 415–777 → 379–600 ms; crash ranges 390–641 → 398–617 ms. These are small-sample startup measurements, not p99 estimates. Process-tree CPU excludes already-exited workers and is not main-thread CPU; heap at ready is not post-GC retained heap. Clean startup RSS rose 2.5% and ready heap rose 10.8%, with substantial per-run spread; crash RSS was flat. Overlapping-restart smoke also passed (health-read 394 → 333 ms). There is no demonstrated whole-Gateway retained-memory win.
The synthetic fixture did not reproduce either reported eight-second stall. Dead-owner detection already precedes lease expiry, and lock policy remains unchanged. This fixes the independently reproduced residual whole-database copy after clean close. Crash recovery remains intact. The 10-minute steady-state stress campaign is omitted under the scoped fast-path proof rule; no steady-state GC, allocation, event-loop p99, or sessions.list p99 claim is made.
The table above measures the initially reviewed implementation. CI then caught an import cycle through its general state-connection helper. The correction uses the native SQLite opener directly with the same admission, timeout, custody, and native-close rules; the cycle guard passes. The rebuilt final head passed an additional clean, SIGKILL, and overlapping restart, preserving all correctness checks. These are single-run smoke results under different host load, not a new A/B latency comparison:
Focused health-observation (32), Gateway owner-lease (45), and plugin-metadata-worker (15) tests passed. The final dependency correction reran the 47 health/plugin tests successfully. Changed-file formatting/lint and targeted core typecheck passed; baseline and candidate runtime builds passed. Existing lease tests prove dead owners are reclaimed before lease expiry and unverifiable/live owners remain protected. Lock polling and lease policy are unchanged.
Independent subagent review (autoreview route unavailable): no actionable P0/P1/P2 findings. The configured autoreview provider selector was refused; no operator configuration was changed. Final-head CI passes the architecture guard and all other substantive test/check jobs except PostgreSQL conformance (2/3); its aggregate CI gate is consequently red. Its one failure is the unpublished-schema deadline assertion in
state-read-admission-publication.postgres.test.ts: the facts relay reports a generic timeout instead of the expected missing-schema error. That fixture directly calls the PostgreSQL read-connection path, bypassing this changed startup metadata path. Attribution: the exact file passed 5/5 independent runs on the PR head and 5/5 on baseeb78444932faeff3e6ab23d082e6c02dc0ddcb2b(25 test cases per side), using the same pinned PostgreSQL image as CI,pgvector/pgvector@sha256:ac08538c6f8b9904c33c8224c5e5706dbe760aca29db1d096972b4052c22a75d. Base source equality was checked before testing; the reviewed patch was restored afterward. The fixture, PostgreSQL retry owner, and facts-relay owner are byte-for-byte unchanged by this PR. This meets the lane's unrelated-flake classification; it does not make CI green. No CI rerun, assertion relaxation, or baseline exemption was used.Focused reproduction command (one file only):
node scripts/test-database-conformance.mjs --engine postgres --connection <disposable-local-dsn> -- src/infra/database-engine/state-read-admission-publication.postgres.test.ts --maxWorkers=1.Remaining CI failure. The relay uses the PostgreSQL admission retry's remaining deadline; a late facts exchange can throw the generic transport timeout instead of retaining the original schema-admission error. Correcting that requires a separately typed timeout distinction to preserve cancellation and owner-loss precedence. It is outside this sealed-startup-read change. CI remains red for this unrelated flake; this PR is ready, open, and deliberately unmerged for the lead's review.
Benchmark base:
98a9fdeb40ceacbd1c8f7de13862ff5fc7d0c5bc; candidate: the reviewed patch on that base. The required pre-push rebases did not change these owners. Final PR head:4b40b625c5081889a5419c4d1c09e852d20a86ea.