Repository navigation
perf: reduce repeated database work during Gateway startup - #174592
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f98ad8025
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "src/infra/gateway-owner-lease.ts", | ||
| [ | ||
| { | ||
| tier: "T2", | ||
| operations: ["acquireGatewayOwnerLease"], |
There was a problem hiding this comment.
Regenerate the worker-access inventory
This classification changes the generator output because the target source adds an executeSqliteQueryTakeFirstSync call under acquireGatewayOwnerLease, but docs/reference/database-schemas/worker-access-inventory.md still reports 2,312 calls and contains no T2 row for gateway-owner-lease.ts. Consequently, pnpm db:worker-inventory:check will report the committed artifact as stale and the published audit undercounts synchronous startup database access; regenerate and commit the inventory with this change.
AGENTS.md reference: scripts/AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
|
Codex review: blocked before merge. What this changesThis PR reduces repeated migration-receipt checks, Gateway lease statements, and staging-token probes during startup. Example: A Gateway restarts with a completed version-1 runtime-pin migration receipt.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep this useful, maintainer-directed optimization open; the generated inventory is stale and CI confirms an outdated maintenance-test expectation. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway startup uses shared-state leases for process ownership, a daemon-owned SQLite store for runtime intent, and SQLite staging tokens for temporary-copy custody. flowchart TD
A[Gateway startup] --> B[Physical state custody]
B --> C[Gateway owner lease]
C --> D[Worker heartbeat]
A --> E[Runtime pin migration receipt]
E --> F[Daemon service intent store]
A --> G[Staging token custody]
Technical reviewBest possible solution: Retain the focused optimization, repair its generated artifact and test expectation, and establish upgrade compatibility. Do we have a high-confidence way to reproduce the issue? Current-main source shows repeated pin-store admission, nested lease transaction work, and staging probes; CI independently demonstrates the introduced maintenance-test failure. Is this the best way to solve the issue? The optimization fits the existing owners and documented admission policy without adding a cache or changing persisted formats, but its integration repairs remain necessary. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 288e65080aaa. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +41, Tests +161, Other +12. Total +214 across 9 files. Added test files: 1. 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 16, 2026, 3:48 PM ET / 19:48 UTC. |
ab7642b to
db8a3e2
Compare
|
Merged via squash.
|
…174592) * perf: reduce repeated database work during Gateway startup * test: update maintenance custody statement expectations
What Problem This Solves
Gateway startup and restart repeat database admission and lease bookkeeping even after the relevant owner has already established the facts.
User Impact
Startup performs fewer SQL statements while preserving Gateway exclusivity, runtime-pin recovery, and rollback custody. There is no configuration, schema, stored-format, or SDK change.
Why This Change Was Made
Completed runtime-pin migration reads its versioned receipt directly; actual pin access retains its schema and integrity admission. Fresh initialization uses the existing admitted native read and inserts the completion receipt only if absent. The copied-to-complete receipt and target-first commit ordering remain unchanged, including PostgreSQL's local, directly complete receipt.
Gateway lease acquisition retains the previous-owner liveness/refusal check and replaces delete/delete/insert with a conditional upsert. It reuses the state owner's transaction and publishes listening state with an owner-qualified update. The lease table, row, payload, and PostgreSQL advisory-lock contract are unchanged.
Staging-token creation trusts the private empty file it just created. Existing tokens still validate journal mode and the durable retirement marker; native transactions retain admission and retirement exclusion.
Removed checks and accepted edges:
ON CONFLICT DO NOTHINGpreserves any receipt already published by another initializer.Quarantine header repetition is deferred: short-lived admission retires its facts on last close, so retaining those facts needs a lifecycle-owner change rather than another cache. Device pairing and schema changes are out of scope.
Evidence
Current head
db8a3e28d21is rebased without conflicts onto3e55551264e, including the Windows helper packaging fix. Both reviewed commits are patch-identical after the rebase (git range-diff). Two Codex review rounds completed with no actionable findings.Final-head CI 38968021545 passed all 55 selected jobs (26 skipped), including types, lint, source/export contracts, architecture/Madge and database ratchets. PostgreSQL conformance actually ran: 372 tests across 66 files passed, including all three maintenance-custody PostgreSQL cases, the corrected SQLite inspection expectation, nine Doctor migration cases and twelve port-recovery cases.
The published-driver update cell passed in one attempt: published
2026.10.4to candidatedb8a3e28d21, readiness HTTP 200, running version verified. The earlier missing-Windows-helper blocker is resolved. Package Acceptance's separate npm 12 installation succeeds but its installed-entry budget fails (47,789 > 47,500; below the shipped 50,000 updater cap). The same check failed on same-day main, 47,610 > 47,500, with the identical budget-checker blob. No exact current-base entry-count delta is claimed.Three alternating shared-harness-v3 pairs completed in order M1,C1,M2,C2,M3,C3, base
3e55551264eversus candidatedb8a3e28d21, through one ordinary proof slot. Every arm passed 14 turns and both shutdowns; Node 24.22.0, SQLite 3.54.0 and harness/native-library hashes stayed pinned.NODE_DISABLE_COMPILE_CACHE=1. Fixtures stayed below 5 GB and were removed after compaction. Counts only: no latency claim on the busy host (one-minute load snapshot 68.56 during M3).Values are median [min–max]. Boot/restart/whole use three runs per side; warm rows pool 30 turns per side. SQL includes all threads and helper processes; MAIN is Gateway main-thread SQL.
Warm non-regression: every paired causal warm operation group matches exactly: 688 SQL / 226 requests / 0 MAIN per ten-turn arm, with 619 normalized SQL groups and 182 request groups. Shared-family per-turn SQL/request medians are unchanged: exact-entry 0/0, actor hydration 0/0, entry-cache snapshots 0/0, row facts 2/2, watermark reads 0/0. Raw warm medians rise by 1 SQL and 0.5 requests because plugin startup, checkpoint, catalog and quarantine background work lands in different windows. The same plugin lifecycle operation executes exactly 13 MAIN statements in every whole workload; its warm-window allocation is 4→13, 4→13, and 13→4 across the three pairs. None of the four edited owners adds causal warm work.
The disjoint union of the four edited owner cohorts falls 264 [264–265] → 171 [171–171] SQL, with 17 [17–18] → 17 [17–17] requests and 102 → 53 MAIN across the whole workload. Whole raw request median 1021→1022 and fresh-boot request median 92→93 come from work outside those edited-owner cohorts; no request increase is attributed to the change. The baseline's extra snapshot request occurs only in M3. The overall 94-SQL median saving and the deterministic 93-SQL owner saving are reported separately.
Per-owner whole-workload SQL / request medians (overlapping stack cohorts; do not add):
The complete disjoint MAIN ledger below reconciles every fresh/restart statement in all six arms with zero unclassified groups. The targets below 50 fresh / 40 restart MAIN are not reached. Quarantine still costs 16 restart MAIN statements and requires lifecycle-owner work; device migration remains untouched. Candidate cold-open deadlines caused one extra timeout-reset statement in C1/C2, absent in C3.
Complete boot MAIN owner ledger (median [min–max])
Changed-file formatting, type-aware lint and
git diff --checkpass. The focused owner tests cover interrupted migration and SIGKILL recovery, stale/live-owner refusal, competing Gateway acquisition and staging retirement. The final-head local run passed all 69 tests across five owner files; the additional staging SIGKILL recovery case also passed. CI passes the changed tests.Change size: 10 files, +292/−80 lines (production +115/−74; tests +165/−6; inventory classification +12). No schema, SDK, dependency or persisted lease contract changes. The new inventory entry classifies only conditional lease acquisition as the existing synchronous process-lock exception; heartbeat renewal remains worker-owned. The native inventory reports owned-area T1 0 → 0, global T1 197 → 197, and T1-compat 10 → 10. Owned T2 changes 1 → 2 because the new conditional-acquire primitive is classified as the existing synchronous lock exception. The exact-base worker and dialect ratchets pass; changed-file engine-maintenance dialect matches fall 7 → 5. The final boot MAIN owner ledger is included above. The generated inventory Markdown refresh requested by the automated P2 review remains a follow-up.
Standalone Knip completed every scope: script exports pass; production has one and full-tree has six inherited findings, all matching the same rule/path/symbol on scheduled main. The finding-source blobs are identical on base, candidate and observed main. There are no candidate-only findings; this is an inherited-only failed scan, not a clean scan. Both inherited failures have been routed to the main-failure owners.