Repository navigation
fix: keep startup credential preparation off the main thread - #180154
Conversation
Use the existing credential worker for startup custody admission and return its admitted receipt postimage instead of rereading the migration receipt. Keep app custody authoritative and complete required migrations before serving. Return migration-required as preparation data across the worker boundary. The startup regression fails on the original path with 12 main-thread prepare calls and passes with zero across preparation and restart. Preserve the migration, refusal, remount, and identity continuity coverage from #178998. Co-authored-by: Jason (Json) <[email protected]>
|
🦞👀 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: blocked before merge. What this changesThis PR moves normal startup credential preparation into the existing credential worker and reuses its admitted receipt. Example: Gateway startup opens ~/.openclaw/client/credentials.sqlite.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this maintainer-authored PR addresses synchronous credential preparation still present on main, and no definite introduced defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherStartup checks credential readiness before serving; app IPC or exclusive local custody supplies readiness, and required recovery remains with Doctor maintenance. flowchart TD
A[Gateway startup] --> B[Credential preparation]
B --> C[Existing app IPC]
B --> D[Credential worker]
D --> E[Local SQLite custody]
E --> F[Readiness result]
C --> F
F --> G[Doctor maintenance when required]
F --> H[Continue startup]
G --> H
Technical reviewBest possible solution: Use the existing credential worker for admission and receipt reuse while preserving app custody, automatic migration, and credential continuity. Do we have a high-confidence way to reproduce the issue? Current main directly performs credential custody admission and a receipt read on the startup caller thread; the PR reports a failing baseline regression, but this read-only review executed no target code. Is this the best way to solve the issue? The change is a focused repair using existing execution and storage owners, with a justified typed result preserving migration-required behavior across worker error transport. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f7c9c5f23266. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +52, Tests +18, Docs +8. Total +78 across 7 files. Added test files: 0. View PR surface stats
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 21, 2026, 10:09 PM ET / October 22, 2026, 02:09 UTC. |
…aw#180154) Run normal startup credential custody admission in the existing credential worker before serving, and reuse the admitted receipt postimage instead of reading it again. Preserve migration-required handling, app custody, port rebinding, security checks, and once-per-process admission. The frozen workload removes 20 credential SQL statements and all 31 credential MAIN statements across boot/restart, with two additional worker requests. Warm SQL/request medians remain 45/11 and warm MAIN remains zero. Builds on openclaw#178998. Co-authored-by: Jason (Json) <[email protected]>
What Problem This Solves
Startup credential preparation runs SQLite admission on the Gateway main thread. The recent workload census attributed 16 main-thread statements at boot and 15 at restart to this path, including an unnecessary receipt reread on each preparation.
User Impact
The Gateway keeps automatic credential migration and refusal behavior while performing normal credential preparation in its existing worker before serving.
Why This Change Was Made
The credential worker now handles startup preparation under the existing app/native custody and admission rules. Admission returns its receipt postimage, so preparation can decide whether metadata needs upgrading without reading the receipt again. A typed preparation result carries migration-required across the worker boundary; required migrations still run under maintenance ownership and finish before startup continues.
The synchronous normal-startup path is removed. Native schema, integrity, permissions, source binding, commit authority, and once-per-process admission remain owned by the existing credential implementation. No schema or public IPC protocol changes. The implementation adds 52 net production lines and 18 regression-test lines to preserve those ownership boundaries.
Builds on #178998; original author Jason (Json), @fuller-stack-dev, is credited in the commit.
Evidence
preparecalls. The candidate records zero main-thread SQL during preparation and restart.Native proof encountered three timeout classes: updater recovery (200 seconds), Gateway bootstrap/restart (120 seconds), and interactive setup waiting for child authentication (60 seconds). A read-only sample showed filesystem rename waits; the runner had defaulted Bun's compiler cache to the external worktree. With explicit internal caches, the updater replay passed in 55.4 seconds; the isolated Gateway case passed in 24.2 seconds. Interactive setup passed on Testbox in 17.5 seconds. No source, assertions, or timeout limits changed. These passes do not prove a product fix or establish one cause for every failed attempt. The first Testbox filter accidentally skipped four interactive cases; a corrected filter ran exactly those four and passed.
Measured result
One frozen v3.1.4 M1/C1 pair completed on base
b98018c4433de6a471c7b9376156193debd91af9and candidate172040713d8e3077f3b502243f5fc8125503752a. All 36 frozen hashes matched. Both real workloads completed all 14 turns, child and cron flows, compaction, shutdown and restart. Preflight load was 54.94 with 112.90 GiB internal free space; arm loads were 41.44/39.28. Temporary runtime state was on internal storage. These are counts, not latency measurements; candidate build packaging encountered substantial external-volume I/O waits.The credential owner removes 20 statements and all 31 MAIN statements, at the cost of two worker requests. Nine schema/integrity admission shapes occur twice rather than four times (18 statements removed); both post-admission receipt SELECTs disappear. The receipt UPSERT moves into the worker. Remaining MAIN includes one additional boot
PRAGMA busy_timeout = 5000in the existing desktop-pairing migration's cold-open path (openclaw-state-db.ts:430); it is outside credential preparation. The fenced cron MAIN read remains one in each arm.Across ten causally attributed warm turns, SQL median/range is 45 [45–48] → 45 [45–52], requests 11 [11–12] → 11 [11–13], MAIN 0 [0–0] → 0 [0–0]. Means are 45.3 → 46 SQL and 11.1 → 11.3 requests. All seven extra warm statements and two requests are accounted for by an auth-profile helper read (four SQL/one request) and session-entry patch (three SQL/one request) occurring in warm turn 6 instead of the second-session phase. Whole-workload counts for those owners are identical: 8 SQL/2 requests and 168 SQL/39 requests.
Shared read families are counted using captured SELECT stacks across all operations, not only top-level owner labels. Exact-entry facts 19→19, actor hydration 10→10, entry-cache snapshot loads 7→7, row-facts SELECTs 15→15. SELECTs containing transcript rewrite watermarks are 49→50, from one additional background usage-cost read. Every shared family is 0→0 per causal warm turn. Automation jobs outside the cron phase are 52 SQL/13 requests/0 MAIN → 56/14/0; the difference is one background compaction poll (BEGIN, two config-machine-state reads, COMMIT). All other automation-job phases are identical, with no separate automation-runs operation observed. Outside the cron phase, statements touching
cron_jobsare 17→17 and those touchingcron_run_receiptsare 5→5; their execution phases shift, but the work does not increase. These background increases are retained in the raw whole-workload totals, not subtracted from the result.Exact serial PostgreSQL command and environment
Homebrew PostgreSQL 17; fresh UTF-8
en_US.UTF-8cluster withvector,pg_trgm, andunaccent; throwaway HOME/TMPDIR on internal storage. Default pinned Bun runtime. The 37 selected cases comprise 14 credential migration/update/port cases and 23 related cases across the other nine files.Remote remainder: Blacksmith Testbox
tbx_01m5h16mshfqtcx38q46s868mr, Actions 39728047378, requested 16-class, observed 4 CPUs and 15,788 MiB total memory. Exact candidate tree0b5ce786cb34a80240726a95e035cb9f5c6b2c4dwas verified before execution. Image:pgvector/pgvector:pg18@sha256:2358fcba361ed2233a5ed81b5fe4ca779ccb304120ce531a3bf51c0ed7e2bc11; temporary HOME/TMPDIR and explicit Bun/Vitest caches; default pinned Bun,LC_ALL=en_US.UTF-8. The same conformance runner selected port credentials and offline authentication (9 passes), then only the omitted interactive cases (4 passes):The native setup attribution used base
b98018c4433de6a471c7b9376156193debd91af9then candidate172040713d8e3077f3b502243f5fc8125503752a, sequentially with fresh en_US.UTF-8 PostgreSQL 17 clusters, internal HOME/TMPDIR/Bun/Vitest caches, default pinned Bun, and unchanged assertions/timeouts. Identical temporary output-only observers recorded the following; the observers were removed after proof. Build/transform time is excluded from these timestamps.runtime.earlycompletedBoth passed. This bounded comparison did not reproduce added startup latency; host/cache variation prevents treating the difference as a general speedup. The native filter was
postgres interactive setup.*setup saves interactive setup and releases ownership for a Gateway. The remote lease is stopped, its Actions run completed/cancelled after successful commands, and its campaign slot released.