Repository navigation
refactor(auth): prepare runtime profile reads asynchronously - #149309
Conversation
Keep runtime discovery read-only through the canonical SQLite worker owners. Preserve captured profile paths and environment, host selection and migration diagnostics, cleanup failures, and caller authority across model preparation. Retain the public synchronous SDK reader for compatibility.
|
🦞👀 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 18, 2026, 10:30 AM ET / 14:30 UTC (Revision 16). ClawSweeper reviewWhat this changesMoves persisted authentication-profile reads during model preparation into asynchronous SQLite readers while preserving credential selection and synchronous SDK access. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 3 items remain This remains useful work: current main still reads authentication profiles synchronously during dynamic model resolution. No actionable correctness defect was found, but the required comparative performance evidence remains outstanding. Priority: P2 Review scores
Verification
How this fits togetherModel preparation combines configured model choices with stored authentication profiles before invoking provider hooks. This change moves database reads into isolated readers and returns prepared credential facts to the existing selection owner. flowchart TD
A[Model preparation request] --> B[Capture credential scope]
B --> C{Credential owner}
C --> D[Agent database read-only child]
C --> E[Shared-state worker]
D --> F[Join cleanup and recheck authority]
E --> F
F --> G[Apply overlays and select profile]
G --> H[Prepare provider model]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1237, Tests +710, Docs +12, Other +4. Total +1963 across 67 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the existing credential and lifecycle owners while demonstrating that asynchronous reads improve responsiveness at an acceptable measured latency and memory cost. Do we have a high-confidence way to reproduce the issue? Not applicable to a discrete bug report: this is a performance refactor, and source confirms the synchronous reads it replaces; no timed Gateway stall was reproduced during this read-only review. Is this the best way to solve the issue? Unclear overall: the design reuses the appropriate storage owners and preserves existing contracts, but its end-to-end performance benefit still needs comparative measurements. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 014d72f106f5. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (15 earlier review cycles; latest 8 shown)
|
Keep runtime profile reads on the existing SQLite worker owners while retaining current inherited-refusal, model transport, and lifecycle behavior. Recheck captured legacy candidates after awaited reads using persisted prepared facts. Keep the required worker ABI as a transparent export from the SQLite owner, without changing the duplicate-export guard or adding an exception.
Keep read payload and command types with the existing auth data contracts so worker contracts do not depend on storage implementations. Preserve emitted runtime behavior and the existing worker ABI. Run real async-reader fixtures through the canonical fork owner, including full-suite exclusions and watch/shuffle routing. Give the image fixture the matching async auth entry backed by its existing profile data.
Normally compose the accepted shared catalog ancestor with exact main 543e8ce. Preserve the canonical required early-retention callback and both complementary existing regressions unchanged. The only main-relative delta is the retained after-credentials real-worker regression.
|
Merged via squash.
|
…w#149309) Runtime model preparation now awaits isolated authentication-profile reads, avoiding synchronous SQLite work on the Gateway event loop and competition with memory's agent-database writer. Relocated shared credentials and personal accounts retain the existing shared-state owner; synchronous SDK readers and credential writes remain compatible. The readonly child and synchronous reader share a narrow JSON inspection kernel. Auth reads keep captured admission through native cleanup, carry complete rows in framed IPC, and preserve selected-owner errors and recorded inherited-source refusal. Canonical consolidated snapshots remain supported by one protocol parser. Validation: 153 focused Auth, readonly-worker, consolidated-state/preflight and catalog tests; core types; independent P0–P2 review; normal build; compiled Node and Bun probes returning the complete 10.8 MB envelope without changing database bytes. Exact-head CI passed 142 jobs with 14 skips, including the required gate: https://github.com/openclaw/openclaw/actions/runs/35353298957. Inherited planner and catalog-count assertions were reproduced and reconciled with canonical source. Live provider sign-in was not exercised. No operator migration is required.
…52286) * refactor(auth): prepare bounded shared auth scopes asynchronously Read shared ownership and portable credentials through the existing state worker before entering bounded CLI and provider-setup auth scopes. Resolve paths before awaiting and recheck admission and ownership before entry. Preserve local overrides, OAuth refresh ownership, and personal-account isolation. Record the cold-worker latency and memory tradeoff in PR evidence. Related: #149309 * fix(test): await scoped auth while staging live fixtures Wait for the portable auth view and target persistence before fixture installation continues. Drain the CLI's existing maintenance owner before exit and run direct helper tests through the host database-worker lane. * test(auth): include cacheability in scoped read fixtures * test(auth): align cancellation fixture with current row metadata * test(outbound): clean up ACK fixtures with their owner (cherry picked from commit 4681239)
…enclaw#152286) * refactor(auth): prepare bounded shared auth scopes asynchronously Read shared ownership and portable credentials through the existing state worker before entering bounded CLI and provider-setup auth scopes. Resolve paths before awaiting and recheck admission and ownership before entry. Preserve local overrides, OAuth refresh ownership, and personal-account isolation. Record the cold-worker latency and memory tradeoff in PR evidence. Related: openclaw#149309 * fix(test): await scoped auth while staging live fixtures Wait for the portable auth view and target persistence before fixture installation continues. Drain the CLI's existing maintenance owner before exit and run direct helper tests through the host database-worker lane. * test(auth): include cacheability in scoped read fixtures * test(auth): align cancellation fixture with current row metadata * test(outbound): clean up ACK fixtures with their owner (cherry picked from commit 4681239)
What Problem This Solves
Runtime model preparation reads persisted authentication profiles synchronously, allowing SQLite work to block the Gateway's main event loop. Assigning those reads a separate broker backend also conflicts with memory publication when both use the same agent database.
User Impact
Model preparation now awaits isolated profile reads while preserving profile selection, configured transport, unavailable-model handling, and deferred provider preparation. Existing databases and configuration remain compatible; no operator migration is required.
Why This Change Was Made
Agent-local and legacy shared credentials use the existing isolated read-only child. The child runs the auth owner's fixed row query without competing for the agent's writer backend. Source-exclusion scopes supply their owned private snapshot. Captured agent/root admission remains live through cleanup, and the child independently retains source admission through native close. Existing bounded frames carry complete credential rows without an aggregate size limit.
Relocated shared credentials and selected personal accounts remain with the canonical shared-state actor. Credential mutations, FIFO ordering, postcommit publication, and synchronous SDK readers retain their existing owners. Selected-owner errors stay visible; inherited-owner refusal follows the existing decision. Final currentness and legacy-file checks run after cleanup using prepared persisted rows, so inherited or external profiles cannot conceal an unmigrated local source.
The read-only child and synchronous persistence reader share the same narrow table and JSON inspection kernel. The child no longer imports the writable auth runtime, and the extracted wrapper inventory includes its five required source dependencies.
The superseded auth broker entry is removed. Protocol types belong to their existing pure owners, and the unchanged duplicate-export guard passes without an exception. The earlier CI repair retains canonical fork routing and the image suite's equivalent asynchronous auth fixture.
Evidence
Final integration
667b9d54b534carries canonical maincecf47a2d92e. The existing protocol owner handles main's new consolidated SQLite mode; no second parser is restored. Auth rows still use a dedicated child with the captured environment, complete framed transfer, current admission, and awaited native cleanup. Canonical catalog retention and shared-state operations remain intact.All 153 selected Auth, readonly-worker, consolidated-state/preflight, and catalog-performance cases pass, together with core types, formatting, and fresh independent P0–P2 review. The normal build passed on the final source tree in 6 minutes 38 seconds. Fresh compiled Node and Bun probes each returned the exact 10,800,214-byte envelope, preserved source database bytes, and exited naturally.
Two inherited test expectations surfaced during integration. The planner correction was absorbed by canonical #151427, preserving its exact file and expanded host coverage. The catalog SQL assertion expected 20 reads per resident list, while identical query traces on baseline main and the executed PR merge showed 18: three bindings each perform one freshness read, four schema-admission reads, and one authority read. The test now requires exactly 18 and retains every functional, CPU, authority, and zero-I/O assertion. Its full real-store flow, selected changed checks, and independent P0–P2 review pass. This is not an Auth performance claim.
Predecessor CI 35331313677 passed on
9d950dd94a30. CI 35343981196 failed only the planner shard and aggregate gate. CI 35349142581 passed 141 jobs and skipped 14; only the catalog-count shard and aggregate gate failed. Final-head CI 35353298957 passed on667b9d54b534: 142 successful jobs and 14 skipped, including the requiredopenclaw/ci-gate. Native review, preparation, merge verification, and cleanup completed; landed as 1d4202ddbc05.Post-merge performance comparison
Collected after the merge on September 18, 2026; these measurements were not available to the earlier merge decision. Compared the actual pre-merge parent
29e0ca0509c5with reviewed head667b9d54b534, using clean pinned checkouts, the same compiled runtime build profile, and Node 24.21.0 on a shared Apple M3 Ultra host (32 logical CPUs, 512 GiB RAM).The real
resolveModelAsyncpath read persisted synthetic profiles and called a local-only dynamic-provider hook. No auth reader was mocked and no live credentials/provider requests were used. Initial imports and separate fixture writes were outside timing; scoped preparation, child acquisition, transfer, and awaited cleanup were included. Each revision/size used three fresh processes with one first preparation and four warmed calls each. All 60 complete normalized model outputs and profile/mode assertions agreed. Every measurement process exited naturally with no remaining descendants.The serialized stores were 158 bytes and 683,601 bytes. RSS values are medians of per-process observed preparation peaks, using parent endpoint readings and process-group samples at roughly 30–33 ms median intervals. Summed RSS double-counts shared pages and can miss short transient peaks; it is not unique memory/PSS. First preparation means after entry-module imports, not process startup or cold OS caches. These are small, shared-host synthetic samples, not a full Gateway benchmark.
Child isolation adds preparation time and approximately 77–90 MiB of observed summed RSS in these fixtures. A 1 ms timer made progress during candidate preparations (warm median 129/134 ticks versus zero for baseline), showing yielding during child waits; this does not establish an end-to-end latency or throughput improvement. No latency or memory reduction is claimed.
Storage compatibility: the table/schema versions, keys, and serialized credential formats are unchanged; the inspection kernel was extracted and reused. No database migration is introduced.
This evidence does not claim live provider/sign-in testing or that every SQLite operation in runtime preparation has moved off the parent thread.