Repository navigation
perf(sqlite): prevent runtime lease checks from stalling Gateway requests - #184586
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 real behavior proof before merge. What this changesThis PR moves runtime lease verification and cleanup identity checks off the Gateway thread while preserving final ownership guards. Example: Update an MCP server's tool selection while ownership filesystem reads are slow.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep open: this maintainer-directed follow-up addresses remaining synchronous ownership checks on main, and no definite introduced code defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway operations enter the shared-state lease and SQLite admission owners, which authorize credential, config, export, and cleanup effects and retain accepted writes through settlement. flowchart TD
A[Gateway operation] --> B[Captured state context]
B --> C[Async lease verification]
C --> D[Current owner guard]
D --> E[Filesystem or SQLite effect]
E --> F[Native settlement and cleanup]
Technical reviewBest possible solution: Retain the existing async lease owners, per-client physical identity binding, and separate settlement authority. Do we have a high-confidence way to reproduce the issue? Main still routes the migrated callers through native lease verification; source and the submitted baseline regression establish the blocking path, but no target code was executed during this read-only review. Is this the best way to solve the issue? Reusing existing async lease, heartbeat, and admission owners is a coherent fix that preserves synchronous SDK contracts and avoids a competing cache or ownership manager. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9302c1147252. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: No concrete bypass was established, but composed authority evidence for outbound personal-token rotation remains incomplete. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +238, Tests +515, Docs +16, Other +248. Total +1017 across 55 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 26, 2026, 8:14 AM ET / 12:14 UTC. |
76b398d to
027d437
Compare
Move MCP mutations, personal GitHub credential publication, transcript exports, recovery cleanup, and borrowed cleanup identity checks through existing async owners. Preserve original custody, physical identity and birthtime, final publication guards, and accepted-write settlement. Resolve runtime owner paths and close-checkpoint diagnostics asynchronously. Follow-up to #184275. Five alternating 2,000-check owner samples reduced total process CPU by 62% and sampled allocation by 62%; injected slow filesystem heartbeat delay fell from 491 ms to 0.095 ms. Focused behavior, core typecheck, lint, closure checks, and independent review passed.
Retain the same cancellation predicate in synchronous and awaited MCP fixture checks. Expect the broker physical-identity refusal after lease cleanup moved to its existing admission owner, preserving the original database lease-row assertion.
027d437 to
474b1f2
Compare
…ests (openclaw#184586) * perf(sqlite): keep runtime lease checks off the Gateway main thread Move MCP mutations, personal GitHub credential publication, transcript exports, recovery cleanup, and borrowed cleanup identity checks through existing async owners. Preserve original custody, physical identity and birthtime, final publication guards, and accepted-write settlement. Resolve runtime owner paths and close-checkpoint diagnostics asynchronously. Follow-up to openclaw#184275. Five alternating 2,000-check owner samples reduced total process CPU by 62% and sampled allocation by 62%; injected slow filesystem heartbeat delay fell from 491 ms to 0.095 ms. Focused behavior, core typecheck, lint, closure checks, and independent review passed. * test(sqlite): align lease fixtures with current ownership guards Retain the same cancellation predicate in synchronous and awaited MCP fixture checks. Expect the broker physical-identity refusal after lease cleanup moved to its existing admission owner, preserving the original database lease-row assertion. * fix(sqlite): preserve physical custody through async lease checks * fix(sqlite): scope captured identity to its admitted lifetime * fix(sqlite): publish observed heartbeat loss before returning * test(sqlite): prepare MCP authorization subprocess before its deadline
What Problem This Solves
Fixes Gateway stalls during disk writeback when MCP config changes, personal GitHub credential updates, transcript exports, recovery cleanup, or periodic WAL maintenance verify SQLite ownership. Follow-up to #184275: these callers still used native lease verification, and cleanup-client opening and worker publication repeated synchronous identity checks.
User Impact
Slow SQLite ownership filesystem reads no longer block unrelated Gateway requests in these flows. Original ownership loss still refuses new effects; accepted writes retain settlement authority. No schema, configuration, or public SDK changes.
Why This Change Was Made
Migrate runtime callers to the existing async lease and heartbeat owners, retaining original context through staging and final publication. Resolve runtime ownership paths asynchronously. Cleanup and lease requests carry their original file identity and birthtime to the existing worker guard, including identity published by cold acquisition. Conflicting bindings refuse; accepted settlement and sibling clients sharing an actor remain intact.
The heartbeat retains its original Gateway owner and freshly verifies custody within the existing request deadline. Its worker verifies the original database before verification, renewal, and contention fallback. Close-checkpoint diagnostics await filesystem inspection and recheck original cleanup authority before publication. Periodic WAL carries identity through existing-only opening and execution; warm descriptor retention and worker publication reuse existing admitted facts. Cold alias reconciliation and native bootstrap/CLI/SDK contracts remain.
Plugin/package and project/worktree runtime callers are separate follow-ups. This PR does not claim to eliminate every synchronous filesystem operation in the Gateway.
Evidence
Predeclared owner benchmark: 10,000 retained lease keys across 40 synthetic scopes; 2,000 warmed effect checks per arm, five alternating native/async pairs. CPU and sampled allocation use separate unwrapped passes; counts and the injected 20 ms filesystem-delay probe are separate. Final measurements include all ownership fixes. One-minute host load ranged 16.2–19.3.
All five pairs reduce main-thread CPU and allocation, and all five increase total process CPU. The process CPU cost is about 76 µs/check: fresh verification moves to workers while retaining fail-closed ownership. This is an explicitly requested responsiveness repair, not a throughput improvement. Under injected storage delay, unrelated main-thread work proceeds without waiting for filesystem verification. Earlier measurements that omitted the final authority checks are superseded.
This measures verification inside a held lease, not capture/release or whole-Gateway throughput. The real MCP regression separately covers acquisition, staging, publication, and release; it failed on the base with 20 host owner-file reads. Additional regressions failed before the final owner fixes: cold database replacement was accepted, held Gateway replacement allowed an effect, warm retains performed two stats, and periodic WAL repeated host identity reads. The fixed tests cover zero host WAL identity reads, physical replacement, deadline cancellation with no late dispatch, accepted settlement, sibling reuse, and cold alias reconciliation. Close-checkpoint fault injection covers delayed inspection, file replacement, and revoked cleanup custody.
Reproduce:
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/sqlite-native-lease-measure.mjs [--baseline] --iterations 2000 --delay-ms 20.No Team or production server was used. This follows the requested owner fast path; no whole-Gateway p99, GC, RSS, or stress result is claimed.
Runtime production delta: +697/−309, net +388 lines. Necessary growth preserves existing authority across asynchronous boundaries, deadline/cancellation, and per-client physical binding. Migrated callers remove their native runtime lease path; no new cache or parallel fast path. Benchmark tooling adds 248 lines separately. The simplification retains existing admission, heartbeat, and settlement owners; synchronous public/native callers retain their existing contract.
Focused validation: the final consumer run passed 121 tests in 5 files (read admission, WAL, MCP, GitHub OAuth, transcripts); heartbeat proof passed 37 tests in 4 files; the preceding WAL/admission/async-lease run passed 45 tests in 3 files. Earlier runtime/cleanup/close-checkpoint proof passed 240 tests in 15 files, with additional focused OAuth/identity coverage. Targeted core typecheck, scoped lint/format, one-page MDX sanity, and diff checks passed. Both import-closure files passed (26 tests).
Independent subagent review (autoreview route unavailable), including the final physical binding, heartbeat deadline, and cold-alias corrections, found no remaining actionable P0–P2 issues. A too-broad early identity gate blocked settlement; the final boundary checks new effects while permitting accepted work to settle. No schema or retention changes.
CI and follow-up validation
CI run
40341514714on027d43735fede8fc6e7f0d2ce4be92776383e788completed with 71 successful jobs, 24 skipped jobs, and three failed test jobs plus the aggregate gate. All prior admission, retained-read, alias lifecycle, typed lease-loss, and profiler failures passed; all PostgreSQL conformance shards passed. Earlier CI exposed real physical-binding and lease-loss notification-order defects, which are repaired and covered by focused regressions. The original Doctor SHM checksum failure reproduced on unchanged main in the earlier run and did not recur here.Remaining failures in that run were the mocked-UI group-defaults focus assertion, an MCP authorization child exceeding 30 seconds, and update-resume returning a Doctor warning. The exact CI base
8f737e10ef62f393697c72bd605a51941485e26aand candidate each passed the complete MCP file (12 tests) and update-resume file (9 tests). The UI case passed five times on each revision; its mocked Gateway does not load this PR's SQLite/runtime code. The process tests do reach changed code, so passing replays are not claimed as inherited-failure proof or a fix.The MCP fixture bypassed the existing compiled-child owner and cold-loaded raw TypeScript with
tsxinside its 30-second deadline. It now declares and resolves the same production authorization entry through the existing prepared-module owner. The cross-process lifetime, disposal, error/exit assertions, and deadline remain unchanged. On this Mac the case fell from 10.977 s to 2.697 s; this measures removed fixture work, not proof of the CI timeout's cause. Failure diagnostics retain synthetic child stdout, and the update harness now includes its complete synthetic result when its unchanged success assertion fails. The Doctor warning remains unclassified.After this fixture repair, both complete process files pass (21 tests), both import-closure files pass (26 tests), and scoped lint/format pass. Independent subagent review (autoreview route unavailable) is clean. No CI reruns, deadline increases, assertion relaxations, or Team operations were used. Final exact-head CI is recorded below.
Current reviewed head:
474b1f278e76f276996283833eb6e42261cfd479, rebased onto5089aa71b681. All 75 code/docs/test files are byte-identical to reviewed pre-rebase source; the mock-export baseline also retains upstream removals. Run40349088993completed successfully on this exact head: 77 successful jobs and 24 skipped, including all PostgreSQL shards, all UI shards, and the previously failing MCP/update-resume jobs. The exact-run watcher exited 0. Earlier unexplained intermittent failures are retained above; this passing run is not claimed as a diagnosis of them.