Repository navigation
perf(sqlite): avoid redundant path checks in database admission - #169740
Conversation
Keep the worker dispatch access check at operation admission. Reuse the captured physical identity for existing-file writer checks; preserve first-open path resolution and replacement detection.
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR replaces repeated existing-file path resolution with physical-identity checks and removes a duplicate worker-dispatch access check. Example: An agent writes repeatedly through a directory symlink to agent.sqlite.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it makes a focused, useful performance improvement, resolves the earlier diagnostic finding, and introduces no concrete bug found in this review. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherAgent writes enter the shared FIFO admission queue; worker requests then obtain live database authority before native SQLite operations. flowchart LR
A[Agent write] --> B[Captured database identity]
B --> C[FIFO admission]
C --> D[Worker dispatch]
D --> E[Live native grants]
E --> F[SQLite operation]
Technical reviewBest possible solution: Retain this bounded optimization with physical replacement detection, first-open alias convergence, and live authority owned by operation admission. Do we have a high-confidence way to reproduce the issue? Current-main source shows repeated canonical-path resolution and duplicate dispatch access validation; the PR supplies comparative runtime measurements, and this review ran no target code. Is this the best way to solve the issue? The change reuses existing identity and authority owners without adding a cache, parallel admission path, or persisted format. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2b4c2a10bb41. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -5, Tests +34. Total +29 across 3 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 HistoryReview history (1 earlier review cycle)
Reviewed October 12, 2026, 4:30 AM ET / 08:30 UTC (Revision 2). |
|
The final-head CI failure is inherited from the tested main parent, not from this PR's SQLite change. CI run https://github.com/openclaw/openclaw/actions/runs/38222451435 tested merge I reproduced the identical 19-versus-18 failure on a clean checkout of that main parent with The patch's 33 writer tests and 11 broker tests pass locally; changed-file formatting/lint and independent P0–P2 review are clean. The first-head diagnostic regression was fixed and its four alias-retarget cases now pass. Landing the exact final head under the inherited-failure exception. Benchmark gains and the unresolved exact-final-source SQLite-contention gap are recorded in the PR body. Merged as |
…claw#169740) * perf(sqlite): avoid redundant path checks in database admission Keep the worker dispatch access check at operation admission. Reuse the captured physical identity for existing-file writer checks; preserve first-open path resolution and replacement detection. * fix(sqlite): preserve write admission diagnostics
What Problem This Solves
SQLite writer admission repeatedly resolves the same existing-file path, and worker dispatch verifies the same database access twice before posting its request.
User Impact
Reduces synchronous filesystem work on the Gateway thread while retaining replacement-file detection, FIFO write admission, current authority at dispatch/native grants, and the original writer diagnostic. No schema, configuration, migration, or update behavior changes.
Why This Change Was Made
Writer reservations already capture physical identity and a canonical queue path. Existing-file rechecks now use the existing device/inode/birthtime assertion, translating refusal back to the caller's diagnostic with the original cause. First-open reservations retain missing-path resolution so creation and alias convergence keep their contract.
Worker operation-admission preparation remains the owner of the dispatch access check; actor-context preparation now only carries context. Live transaction/commit checks remain. Production LOC: 8 additions, 13 deletions, net −5. Related: #169701.
Evidence
Fresh isolated Linux rig, Node 26.8.1, seven samples of 10,000 operations after warmup, through the actual queued writer entry point. Measurements compare source
9a1b712a9b80a86d124a417301b2328405a31a98with this patch's exact two production files, including the diagnostic correction:The matched 20-session tool-heavy profile pair passed strictly with 100/100 independently verified turns on each side: 20 agents, five turns each, 24 plugins, real read/write/exec tools, workspace fanout, two history clients, four subscribers, and control-plane probes. SELF values are exclusive native leaf sample time weighted by
timeDelta, with idle/program/profiler frames excluded; they are sampled elapsed time, not exact syscall CPU counters.Within those buckets, native realpath SELF under writer rechecks fell 2,068 → 0 ms/1,000 turns (0.1110% → 0%), and actor-context preparation fell 3,019 → 0 (0.1620% → 0%). These selected stacks overlap the aggregate buckets and must not be added to them. Whole-Gateway turn time was 195.20 → 195.56 s (+0.18%); no throughput improvement is established. Directory-observation fs-safe calls dominate and remain outside this bounded patch.
The successful profile pair preceded only the catch restoring the caller's error message. Exact-final-source micros above passed, but its separate Gateway run failed with SQLite lock contention in a native shared-state
state.writeBEGIN (20 launched, zero verified, no CPU export). This is an unresolved synthetic-runtime failure, not a successful exact-final-source profile or proven attribution to this patch. Earlier 240-session attempts are excluded: baseline verified all turns but failed diagnostics teardown; candidate hit worker capacity during setup. The rig runs measurements only.Changed-file oxfmt and repo lint passed. Focused local proof:
pnpm test src/state/openclaw-agent-write-admission.test.ts src/state/openclaw-agent-db-write.test.ts --maxWorkers=1: 33 passed, 109.22 s including cold compiler preparation.pnpm test src/state/openclaw-agent-write-admission.test.ts src/infra/sqlite-worker-broker.test.ts --maxWorkers=1: 27 passed, 91.99 s including cold compiler preparation. The changed writer file took 4.95 s, about 1.2 s of tests.The first PR CI run caught four alias-retarget diagnostic expectations in
openclaw-agent-db-write.test.ts; those failures were caused by this patch and are now fixed without weakening the tests. Final-head PR CI owns typechecks and broad gates. No Testbox/Crabbox leases were allocated. Shared-host CPU contention limits whole-Gateway timing claims.