Repository navigation
perf(auth): reuse readers for equivalent state roots - #167024
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: needs maintainer review before merge. Reviewed October 8, 2026, 3:31 AM ET / 07:31 UTC (Revision 2). ClawSweeper reviewWhat this changesThe branch resolves the effective state directory before comparing SQLite reader launch environments so equivalent roots reuse the existing child. Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful: current main still replaces readers for equivalent implicit and explicit state roots. No actionable defect was found, and the recorded native-worker benchmark supports the scoped performance benefit. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherOpenClaw reads stored authentication profiles through isolated SQLite child processes. A Gateway-owned scope reuses compatible children while each request retains its own database identity, admission, and cleanup checks. flowchart TD
A[Authentication profile read] --> B[Resolve effective state directory]
B --> C[Capture environment and process owner]
C --> D{Compatible scoped reader?}
D -->|Yes| E[Reuse child]
D -->|No| F[Close and replace child]
E --> G[Validate source and read fresh rows]
F --> G
Technical reviewBest possible solution: Keep state-directory normalization at the existing launch owner while preserving distinct-root replacement, fresh per-read admission, and joined shutdown. Do we have a high-confidence way to reproduce the issue? Yes: current main compares environment keys literally, so alternating an absent OPENCLAW_STATE_DIR with its resolved default replaces the reader. The body records the matching pre-fix real-child failure; this reviewer did not execute it. Is this the best way to solve the issue? Yes: using the existing state-directory resolver at launch capture repairs equivalence without adding a competing cache or weakening the other compatibility checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 939380f4920c. Provenance checked
TestingProof path: in-process harness. Added test files: 1. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests +9, Docs +3. Total +17 across 3 files. View PR surface stats
Review metrics
LabelsLabel changes: No label 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)
|
Backport main's lighter CLI imports, schema/proxy/temp-root boundaries, and reader identity normalization to the October release. Preserve the release Gateway request executor and strict malformed-PID cleanup behavior. Backport of #166657, #166722, and #167024 to release/2026.10.1. (cherry picked from commit 7875352) (cherry picked from commit 87f2a98) (cherry picked from commit a066127) Proof: 715 focused/sibling tests pass; one optional socat skip. The equivalent root regression fails against the original worker. Fresh P0-P2 review clean. No dependency, version, schema, permission, or performance-budget changes.
What Problem This Solves
Auth-profile reads can repeatedly restart their shared SQLite reader when one caller leaves the default state directory implicit and another explicitly pins that same directory.
User Impact
Repeated auth reads reuse the existing child across equivalent state-directory representations. Different roots, other environment changes, source changes, shutdown, and read admission retain their existing behavior. No schema, configuration, stored-format, or update migration changes.
Why This Change Was Made
The read-worker launch owner now captures the canonical effective state directory before comparing launch environments. Auth runtime and usage callers already pin this root; catalog callers can leave it implicit. Comparing those representations previously discarded the warm child and repeated process startup and imports. The query itself reads two keyed JSON blobs, without a table scan or decryption.
Production delta: +5 lines. This uses the existing state-directory resolver at the existing launch owner; the growth supplies the canonical launch fact needed for safe reuse. It adds no cache, fallback, export, or second lifecycle owner.
Evidence
Blacksmith Testbox, profile
openclaw-check, leasetbx_01m4cy7qhmpyff16d77q4qrkk7. Synthetic 20-profile WAL database, real source-mode SQLite reader and spawn broker, one cold warmup followed by ten measured reads:The affected warm-read case improves 516× and falls below the 10 ms target. Source-mode cold startup remains approximately 0.7–0.8 seconds; these are synthetic source-worker timings, not deployed Gateway latency or a claim that all auth reads become faster. Parent RSS at the end of the alternating case was 252.2 MB before and 251.9 MB after; no allocation reduction is claimed.
crabbox run --id tbx_01m4cy7qhmpyff16d77q4qrkk7 --timing-json -- bash -c <synthetic benchmark>: passed before and after (46.06 s and 22.67 s remote command time, including setup).node scripts/run-vitest.mjs src/infra/sqlite-readonly-worker.auth.test.ts -t 'reuses equivalent state roots' --maxWorkers=1failed at the expected assertion: two equivalent reads spawned two children instead of one.3d74794d863e7a9bce2846d6dd51a69f470b3a36and SHA-256 checks of all three patched files. The auth-worker file, transport/session/cwd/generation/retention/diagnostic/operation siblings, and remaining compile-cache/agent auth-store tests passed.src/infra/sqlite-readonly-worker.model-auth.test.tsreproduced on that unmodified base: WAL publication timestamps (shared and local), unchanged credentials with host/external rotation, and incognito cache reuse. The baseline file finished with the same five failures and 16 passes (440.47 s including cold compiled-subprocess preparation). These are recorded failures, not passing coverage./usr/bin/time -p pnpm test src/infra/sqlite-readonly-worker.auth.test.ts --maxWorkers=1passed all 18 tests in 215.19 s wall time on the shared rig, including cold compiled-subprocess preparation (80% of Vitest duration); test execution accounted for 18%. This existing file verifies real native/broker process reuse, revocation, bounded field transfer, and cleanup, which cannot be proved by a mocked launch comparison. The patch extends its existing lifecycle case rather than adding a new process fixture.nice -n 10 ionice -c3 node scripts/check-changed.mjs --stagedpassed, exit 0 (05:23–07:15 UTC, approximately 112 minutes).The reviewed patch was rebased onto current
mainbefore publication; all three changed file hashes are unchanged. CI run 37743569356 passed on the published head. In checks-node-changed-3, the changed auth-worker file passed all 18 tests in 64.41 s including wrapper/worker preparation (62.44 s Vitest duration; 70% transform, 28% tests). Both security-review gates passed. The PR merged asa06612710e674f493a3ae8fe1158f60bb56d3924.The Testbox's later sync timed out before sibling tests started. AWS and Hetzner allocation both returned the shared fleet's active-lease limit; neither created a lease. The Testbox lease was stopped and the authorized rig fallback was used.