Repository navigation
perf(state): await existing-state source probes - #188386
Conversation
Move warm reader existence and queued identity probes off the main thread while retaining admission and checking live authority after each wait. Reject missing-source results when the owner closes during the probe. Keep native lease verification and quarantine admission outside this bounded change; their synchronous ownership checks need a separate complete cutover.
|
🦞👀 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 makes existing-state source existence and dispatch-time identity checks asynchronous while preserving admission and owner-lifetime checks. Example: A backup-history read encounters 20 ms filesystem latency on each source probe.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a current main-thread blocking path with a focused change, and no introduced production defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherShared-state callers submit typed reads to an operation owner, which checks source availability and admission before dispatching SQL work to the existing reader pool and returning results after cleanup. flowchart TD
A[Shared-state caller] --> B[Read operation owner]
B --> C[Await source existence]
C --> D[Admission and identity check]
D --> E[Existing reader worker]
E --> F[Result and cleanup]
Technical reviewBest possible solution: Keep both source probes asynchronous within the existing read owner, preserving missing-source behavior, dispatch-time identity validation, admission custody, and checks after waiting. Do we have a high-confidence way to reproduce the issue? Current main synchronously stats the source in both owning paths, corroborating the reported blocking mechanism; the supplied benchmark reports a base failure and candidate pass, but no target code was executed during this read-only review. Is this the best way to solve the issue? The invariant is nonblocking source inspection without weakening source identity or live admission, and replacing these probes through their existing owners is the smallest complete production fix. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against db5d331f07c6. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1, Tests +29, Docs +6, Other +76. Total +110 across 5 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 30, 2026, 10:01 AM ET / 14:01 UTC. |
|
The remaining PostgreSQL conformance (2/3) failure is inherited: The same test, error, and stack fail on main |
* perf(state): await existing-state source probes Move warm reader existence and queued identity probes off the main thread while retaining admission and checking live authority after each wait. Reject missing-source results when the owner closes during the probe. Keep native lease verification and quarantine admission outside this bounded change; their synchronous ownership checks need a separate complete cutover. * chore(perf): avoid shadowing the filesystem probe key
What Problem This Solves
Existing-state reads synchronously inspect the source database twice on the Gateway thread, so filesystem latency blocks unrelated requests even though SQLite reads already run in a worker.
User Impact
Source existence and queued file-identity checks now yield while waiting for the filesystem. Missing sources still avoid worker allocation, replacements still fail identity validation, and closing the owner during the probe rejects the read. There are no schema or configuration changes.
Why This Change Was Made
Use the existing asynchronous filesystem operation and identity predicate, hold the existing admission turn through dispatch preparation, and check live authority after waiting. This removes the nested dispatch callback and changes production code by −1 line (+19/−20). No cache or alternate fast path is introduced.
This is a bounded reader fix. Native state-lease verification and quarantine admission still perform synchronous work; this PR does not claim to remove their cost. The measured allocation increase below is the cost of making these source checks asynchronous.
Evidence
Real SQLite owner benchmark: 10,000 retained lease keys across 40 scopes, initialized quarantine store, 100 warmups, 2,000 reads per pass. CPU and sampled allocation use separate uninstrumented passes. The filesystem-count pass wraps exported synchronous
node:fsfunctions andrealpathSync.native. These are JavaScript filesystem counts, not native SQLite syscall tracing.Source-probe regression assertion fails on the base (4,000 calls) and passes on the candidate (zero). The reverse pair used the complete exported-sync-function instrumentation. Five synchronous quarantine-admission calls/read remain and are counted separately from the source probes.
Allocation rose approximately 7.3%. CPU initially rose 13.8% and 19.6%, but identical-source controls produced 1.892→1.499 s and 1.516→0.953 s (−20.8% and −37.2%), so CPU is inconclusive on this shared host, not a demonstrated improvement. One-minute host load was 84.8/86.5 in pair 1, 76.3/99.7 in the reverse pair, and 50.2–56.9 during controls. No whole-Gateway throughput claim is made.
Validation:
git diff --checkpassed.Reproduce using
scripts/perf/sqlite-native-lease-measure.mjs --existing-read --iterations 2000 --delay-source-only --assert-no-source-iowith the Node invocation in the script header.--owner-dirselects a sparse baseline source overlay; omit--delay-source-onlyto inject latency into the remaining measured host filesystem calls too.CI attribution
All completed checks outside PostgreSQL conformance shard 2 passed. That shard fails
src/infra/database-engine/archive-restore.postgres.test.ts, case “publishes recovered PostgreSQL and SQLite selection from a captured config alias last,” withConfigMutationConflictError: included config target changed since last loadatcaptureConfigFileWritePathProof(io.write-safety.ts:124).The identical test/error/stack also fails on unchanged main
f80ab2ad1c1a0d01ce5a73c39959c27daf425248: main job 124089262163, compared with PR job 124098389842. The failing test and config/backup stack files are identical between that main revision and this PR. No CI rerun was requested. This is an attributed inherited failure, not a passing check.