Repository navigation
fix(update): reduce CPU time in repeated ownership checks - #156757
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: blocked before merge. Reviewed September 24, 2026, 1:08 AM ET / 05:08 UTC (Revision 7). ClawSweeper reviewWhat this changesThe branch reuses a read-only SQLite connection and prepared lease queries during update ownership checks, with integrity and lifecycle tests. Merge readiness⛔ Blocked before merge - 2 items remain Keep open. Current main still has the repeated-reader cost, and the reviewed authority path has no actionable defect. The exact-head published-updater compatibility run remains in progress. Priority: P2 Review scores
Verification
How this fits togetherThe update executor checks a managed SQLite lease before continuing work or handing it to a child process. The lease store supplies current ownership facts, while the executor decides whether work may proceed. flowchart LR
A[Update command] --> B[Executor admission]
B --> C[Managed lease database]
C --> D[Retained read connection]
D --> E{File lease and process current?}
E -->|Yes| F[Continue update work]
E -->|No| G[Refuse and settle]
F --> H[Close reader at settlement]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +121, Tests +608. Total +729 across 8 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep per-fence physical, lease, and process checks with bounded reader lifetime, then ship once the exact-head published-updater upgrade cell passes. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source opens a reader on each lease observation, and the captured PR evidence records a matched workload with 281,956 checks; this read-only review did not execute that workload. Is this the best way to solve the issue? Yes. Reusing connection and query setup while refreshing physical and lease authority on each check addresses the measured cost without changing the lease contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6c2ebd8cd4ce. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
…/updater-lease-reader-20260923
…/updater-lease-reader-20260923
|
Merged via squash.
|
…56757) * fix(update): reduce CPU time in repeated ownership checks * test(update): repair native Windows executor fixtures * test(update): respect Windows SQLite sharing in reader fixtures * test(update): preserve reader fixture failure provenance * test(update): assert exact Windows sharing failures
Related: #155977, #156227.
What Problem This Solves
Fixes excessive CPU time in update preparation when large installations require hundreds of thousands of live ownership checks.
User Impact
Large updates spend less CPU time checking their current owner without weakening revocation, database integrity, or cleanup guarantees. No configuration, schema, permission, or retention changes. The improvement applies once the installed updater contains this fix; it cannot speed up an older updater installing it.
Why This Change Was Made
Keep one read-only SQLite connection and reusable query handles for the admitted executor lifetime instead of reopening and reconstructing them for every check. Each check still revalidates the physical store, schema, lease row, and process identity. Each snapshot ends before returning, so other writers are not excluded between checks; readers close after direct/delegated settlement and preflight handoff.
Only connection and query setup are reused, not authority, database pages, schema decisions, or trusted SQLite bytecode. Before each retained read, SQLite discards cached pages and resets its schema with schema writing disabled. This preserves fresh-reader refusal even when in-place corruption leaves the inode, file size, and SQLite change counters unchanged. The existing one-shot writer admission and recovery policies remain in place.
Evidence
TS2532test error was repaired by explicitly asserting the retained reader exists. Type-aware lint, line-cap, and diff checks pass; independent review approved the exact fixture-only changes. Production code is unchanged by this follow-up. Hosted test-type gates passed at15bf31fa8186; the strict Windows rerun exposed a second native sharing fixture issue, corrected below.withholds candidate input when the original owner changes before process bindingwarms the admitted reader, replaces its owner before subprocess input, proves the real child never writes its effect, preserves the replacement owner, and releases the candidate owner. This passed in Windows run 35918366544; that overall run failed separate fixture cases, not this behavior.ffe22849076preserves all cases: Windows SQLite denies renaming an open file, so replacement attempts must prove their exact native sharing code (EBUSY for source rename; EPERM for replacement), unchanged bytes, and still-current original authority; platforms permitting replacement must still reject the changed authority. Admission uses a real hard-link violation on every platform. Leak assertions remain mandatory, with cleanup afterward to prevent contaminating later tests. 27/27 reader tests pass on macOS, plus type-aware lint, line-cap, max-lines, assertion-safety and diff checks. Full-file independent API review is scoped-clean P0–P2.28e154b611b2c6af05676b72d05d6070d1e1504aincorporates maind3e8af2843c2, including the delivered Workshop clock and Factory-disposal test prerequisites. Production, dependency inputs, and reviewed behavior are unchanged by the merge. At that exact head, native macOS passed 157/157 cases across five files in 69.15s. Strict Windows run 35930572881 passed 150 cases, with six existing platform skips and one remaining missing-file rename fixture failure. Reader-only Windows diagnosis proved the one remaining failure was the fixture expecting EPERM while source rename correctly returned EBUSY. Reviewed fixture headf214d48d9b79f32390bc47a1df378e366727c2beasserts exact per-operation codes and preserves original assertion failures instead of masking them. The full-file API review remains scoped-clean P0–P2; Final strict Windows qualification passed all five files: 151 passed, six existing platform skips, 127.60s on native Windows 10.0.26100 x64 / Node 24.18.1 / pinned pnpm 12.4.2. The workflow verifies exact source/dependency binding and ordered project completion. The warm-owner real-child no-effect test passed again at this exact final head. Ephemeral runner teardown owns the retained temp namespaces; the harness did not separately attest non-group descendant cleanup. Ordinary CI has a Codex settlement hook failure, tracked separately below.[email protected]updater and a package built fromf214d48d9b79f32390bc47a1df378e366727c2be. The package SHA-256 isf8dfd8456696b932e2c30508081656b1e60486c3d2213ba36b109cebbfd58c5c; trusted workflow0bdab89c20155was called by the temporary, unmerged proof carrier7a8d3c885427. Frozen admission receipts and the authenticated consumer artifact10785710938bind these identities. The recorded build changed from published2026.9.5-release-ec9c1a13db89to candidate2026.9.5-f214d48d9b79. Thebasescenario passed through the installed updater in 330.434 seconds, then verified migration, state survival, dependency cleanup, manual Gateway startup,/healthz,/readyz, and status. The complete lane took 640 seconds and recorded joined cleanup. These compatibility timings are separate from the matched-tree performance measurements above.b2d942247040are preserved. This failure now maps to the delivered fix in perf(state): remove schema probes from warm session reads #156817 (d1a3a33acc1ca10d2e8f4cb3bf4a24a3d104ab18): releasing the held writer with fake timers installed stranded a coordinator wait and blocked teardown. That prerequisite passed exact-head CI run 35935966059, including the same extension shard; no blind rerun was used.429b78030ad89bcff98c6e08118053afd4357a49merges pinned main5fca488821d4e5e9a5b5f754f9ccadb9a8eda60f. All eight PR-owned files and dependency inputs are byte-identical to the previous8719a7fbcandidate; the retained native Windows evidence remains source-bound, not relabeled as a new-head run. The refresh includes landed path-index fix(update): shorten preparation for large dependency trees #156748, ACP migration canonicalization, and the direct-main maintenance shutdown fixture repair441c3df8. That fixture repair replaces polling with actual startup/disposal signals and prepares cleanup release before scheduling, preserving abort/disposal/lane assertions. Its recorded original-order shard passed 447 tests across 26 files and standalone file passed 22 cases. The old CI35953027851 remains a failed historical run; fresh exact-head CI35956677247 passed all145 jobs, including the aggregate gate. Current-head security and dependency checks also passed.8719a7fb8ea7991836b569a68709496842a7a843: published2026.9.5 first hop, candidate-driven second hop with legacy chunks removed, and original-candidate base survivor/manual restart, each on attempt1 with joined cleanup. Package SHA2567681ce436cc5366eeb72dec5abb565a2fd812ed7303d9bba790df9b2f9e2253f. First-hop625s; survivor654s. This is systemctl-shim service control and mock model traffic, not native systemd, live inference, full rollback or newer-write preservation. The new composition passed fresh exact-head Package Acceptance 35957254000: source and workflow429b78030ad89bcff98c6e08118053afd4357a49, package build2026.9.5-429b78030ad8-2026-09-24T04-51-17.127Z, tarball SHA-25615f450f37058ff693343fc9fb0f8a24b7424d72af9c47414b8109bb1edf2b7ea, artifact10791067183. Package integrity, npm 12 installation, source admission and final verification passed. Published-upgrade survivor passed in 461 seconds; first/second-hop compatibility passed in 528 seconds. Both were attempt 1, without timeout, and recorded joined cleanup. Frozen admission and both report artifacts were independently read and their ZIP digests verified in memory. Survivor verified automatic migration before standalone Doctor, unavailable-plugin configuration preservation, selected state survival, dependency repair, and manual Gateway readiness. The systemctl-shim/mock-traffic and rollback/newer-write limits above remain; no native-systemd or live-inference claim is made. Historical proof is not relabeled as new-head execution.429b7803passed 147 tests across seven files with one existing Bun-only skip in 62.90 seconds, combining the five lease/authority suites with the landed path-index and scaled-tree suites. All handoff stores resolve to private fixture paths, including delegated helpers. Fresh API-only independent review against pinned main5fca4888is scoped-clean P0–P2. No PR-owned source/test files changed or tests were pruned; the existing whole-file audits and native Windows proof remain source-bound. The consumed 177 MiB compiler cache was removed after all runners joined. No operator Gateway was updated or restarted.Focused commands, measured test cost, and whole-file audit
The five-file affected run took 45.78s wall. The final reader + settlement rerun took 35.17s wall, including 20.52s of shared native-fixture compilation; its native child/crash fixtures protect cross-process disposal and recovery-byte preservation that mocked SQLite cannot establish. CI timing will be added once available.
Audited all four touched test/support files in full: executor reader, executor settlement, executor behavior, and the registered roots helper, including setup, helpers, assertions, skipped cases, mocks, and cleanup. The reader file covers 512 real checks, bounded handle setup, competing writers, failure/handoff disposal, real delegated children, revocation, physical replacement, corruption, permission/link changes, WAL transitions, and hot journals. The settlement file preserves all 20 distinct direct/delegated lifecycle, timeout, cleanup, lineage, and error-provenance cases while checking reader disposal.
All 46 existing executor cases remain. The replaced-preflight-owner case moved into the existing roots registration to respect the source line cap; its refusal and the existing service-owner refusal are now captured and asserted after executor settlement so cleanup cannot swallow assertion failures. No cases were removed, skipped, weakened, or given longer timeouts. The earlier truncating-corruption case remains distinct from the three new nontruncating cases. Negative tests capture actual product errors and assert them outside executor settlement. Every real fixture and delegated helper uses an explicitly private handoff SQLite path; the deterministic settlement mock never opens a database. Temporary paths and child processes are owned and cleaned, and mocks/environment state are restored.