Repository navigation
perf(state): reduce main-thread coordinator waits - #154244
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 September 20, 2026, 11:46 PM ET / September 21, 2026, 03:46 UTC (Revision 3). ClawSweeper reviewWhat this changesAvoids unnecessary profile write locks, batches command-authorization updates through the shared database worker, and adjusts diagnostics and test routing. Merge readiness✅ Ready for maintainer review This remains useful, maintainer-owned work: current main still contains the synchronous contention path. No blocking correctness findings remain, and the earlier migration-proof concern is not supported by the diff. Priority: P2 Review scores
Verification
How this fits togetherThe shared-state database stores user profiles and command-approval policy. Authentication and command execution consume that state; authorization updates must settle durably before execution checks current permission again. flowchart TD
A[Authentication requests] --> B[Read existing profile]
B --> C[Write only when needed]
D[Command authorization requests] --> E[Ordered database worker batch]
E --> F[Recheck policy and deletion fences]
F --> G[Durable settlement]
G --> H[Check current authority before launch]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +323, Tests +294, Docs +11. Total +628 across 19 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep hot-path state access responsive while preserving one canonical policy owner, durable settlement, and launch-time authorization. Do we have a high-confidence way to reproduce the issue? Yes: current main synchronously acquires writer admission on these paths, and the supplied contention benchmark demonstrates the resulting stalls. This review verified the source path without executing it. Is this the best way to solve the issue? Yes: the patch reuses the existing worker, transaction, serialization, and authorization owners while eliminating unnecessary writer admission; a new migration or configuration mode is unnecessary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9d13172225d5. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
9b77eb7 to
1bed149
Compare
Read existing profiles and initialized approvals without writer admission. Batch exec authorization commits through the shared-state worker while retaining policy, deletion-fence, and lifecycle checks through settlement. Contended-writer proof reduces mean main-thread delay from 330-331 ms to 0.37-0.63 ms. Validated on Blacksmith Testbox with focused regressions, typechecks, lint, storage guards, and independent review.
1bed149 to
3baedbb
Compare
|
Merged via squash.
|
* commit 'f76d38a4ac5e5f4e6c5a5320436db169e33d5c8a': (49 commits) fix(ci): remove duplicate database worker test entry fix(voice): keep audio flowing while the Gateway is busy (openclaw#154119) docs: reserve Team live updates for Night Watch (openclaw#154425) test(meeting-bot): control browser retry fixture clocks (openclaw#149174) fix(ui): use remote defaults for manual worktree creation (openclaw#154364) fix(proxy): keep WebChat and Codex loopback calls direct (openclaw#154013) fix(pr): revalidate head reads and reuse repository locators (openclaw#154212) fix(browser): start control when the Gateway has activated the plugin (openclaw#154255) improve: publish CI dependencies promptly and warm hosted JavaScript caches (openclaw#154156) improve: speed up streaming text with inline brackets (openclaw#154398) test: isolate historical Node runner policy from CI fix: refresh stale Gateway shutdown budgets during updates and Doctor (openclaw#153636) ci: use four Windows workers on the 16 class (openclaw#154261) feat: verify GitHub credit from trusted OIDC claims (openclaw#153940) feat(sessions): support explicit local placement for child sessions (openclaw#153912) fix(ui): prevent stale copies after text changes (openclaw#154259) perf(gateway): reuse session list candidates across viewers (openclaw#154003) perf(codex): bound progressive local catalog waits (openclaw#154362) docs: keep update requests owned through acceptance (openclaw#154111) perf(state): reduce main-thread coordinator waits (openclaw#154244) ...
* commit 'f76d38a4ac5e5f4e6c5a5320436db169e33d5c8a': (58 commits) fix(ci): remove duplicate database worker test entry fix(voice): keep audio flowing while the Gateway is busy (#154119) docs: reserve Team live updates for Night Watch (#154425) test(meeting-bot): control browser retry fixture clocks (#149174) fix(ui): use remote defaults for manual worktree creation (#154364) fix(proxy): keep WebChat and Codex loopback calls direct (#154013) fix(pr): revalidate head reads and reuse repository locators (#154212) fix(browser): start control when the Gateway has activated the plugin (#154255) improve: publish CI dependencies promptly and warm hosted JavaScript caches (#154156) improve: speed up streaming text with inline brackets (#154398) test: isolate historical Node runner policy from CI fix: refresh stale Gateway shutdown budgets during updates and Doctor (#153636) ci: use four Windows workers on the 16 class (#154261) feat: verify GitHub credit from trusted OIDC claims (#153940) feat(sessions): support explicit local placement for child sessions (#153912) fix(ui): prevent stale copies after text changes (#154259) perf(gateway): reuse session list candidates across viewers (#154003) perf(codex): bound progressive local catalog waits (#154362) docs: keep update requests owned through acceptance (#154111) perf(state): reduce main-thread coordinator waits (#154244) ...
* commit 'f76d38a4ac5e5f4e6c5a5320436db169e33d5c8a': (58 commits) fix(ci): remove duplicate database worker test entry fix(voice): keep audio flowing while the Gateway is busy (#154119) docs: reserve Team live updates for Night Watch (#154425) test(meeting-bot): control browser retry fixture clocks (#149174) fix(ui): use remote defaults for manual worktree creation (#154364) fix(proxy): keep WebChat and Codex loopback calls direct (#154013) fix(pr): revalidate head reads and reuse repository locators (#154212) fix(browser): start control when the Gateway has activated the plugin (#154255) improve: publish CI dependencies promptly and warm hosted JavaScript caches (#154156) improve: speed up streaming text with inline brackets (#154398) test: isolate historical Node runner policy from CI fix: refresh stale Gateway shutdown budgets during updates and Doctor (#153636) ci: use four Windows workers on the 16 class (#154261) feat: verify GitHub credit from trusted OIDC claims (#153940) feat(sessions): support explicit local placement for child sessions (#153912) fix(ui): prevent stale copies after text changes (#154259) perf(gateway): reuse session list candidates across viewers (#154003) perf(codex): bound progressive local catalog waits (#154362) docs: keep update requests owned through acceptance (#154111) perf(state): reduce main-thread coordinator waits (#154244) ...
* commit 'f76d38a4ac5e5f4e6c5a5320436db169e33d5c8a': (44 commits) fix(ci): remove duplicate database worker test entry fix(voice): keep audio flowing while the Gateway is busy (openclaw#154119) docs: reserve Team live updates for Night Watch (openclaw#154425) test(meeting-bot): control browser retry fixture clocks (openclaw#149174) fix(ui): use remote defaults for manual worktree creation (openclaw#154364) fix(proxy): keep WebChat and Codex loopback calls direct (openclaw#154013) fix(pr): revalidate head reads and reuse repository locators (openclaw#154212) fix(browser): start control when the Gateway has activated the plugin (openclaw#154255) improve: publish CI dependencies promptly and warm hosted JavaScript caches (openclaw#154156) improve: speed up streaming text with inline brackets (openclaw#154398) test: isolate historical Node runner policy from CI fix: refresh stale Gateway shutdown budgets during updates and Doctor (openclaw#153636) ci: use four Windows workers on the 16 class (openclaw#154261) feat: verify GitHub credit from trusted OIDC claims (openclaw#153940) feat(sessions): support explicit local placement for child sessions (openclaw#153912) fix(ui): prevent stale copies after text changes (openclaw#154259) perf(gateway): reuse session list candidates across viewers (openclaw#154003) perf(codex): bound progressive local catalog waits (openclaw#154362) docs: keep update requests owned through acceptance (openclaw#154111) perf(state): reduce main-thread coordinator waits (openclaw#154244) ...
Read existing profiles and initialized approvals without writer admission. Batch exec authorization commits through the shared-state worker while retaining policy, deletion-fence, and lifecycle checks through settlement. Contended-writer proof reduces mean main-thread delay from 330-331 ms to 0.37-0.63 ms. Validated on Blacksmith Testbox with focused regressions, typechecks, lint, storage guards, and independent review.
What Problem This Solves
Fixes Gateway event-loop stalls when frequently repeated profile ensures and exec authorization commits contend with shared-state worker writes.
User Impact
Warm authentication and exec authorization paths leave the main thread responsive during state-coordinator contention. Existing approval policy, deletion fences, durable settlement, and final execution-time authority checks remain enforced. No configuration, schema, migration, retention, or durability changes are required.
Why This Change Was Made
Existing profile rows were checked only after acquiring the exclusive lifecycle coordinator. The nominally asynchronous exec authorization commit also entered a synchronous write transaction on the main thread, even when it changed nothing.
Email, provider, Gateway-owner, display-name, and initialized approvals-socket ensures now read first. Missing or changed profile data rechecks inside the original transaction. Exec authorization commits use the existing shared-state worker, combine contiguous pending requests into bounded ordered batches, skip unchanged writes, and reread authoritative policy before changed batches commit. The existing transaction diagnostics logger reports remaining main-thread coordinator waits over 100 ms.
The shared authorization logic moves into one kernel used by both native and worker callers. Production growth is 323 net lines; the additional code covers batch settlement, captured database ownership, and maintenance drainage. Synchronous callback-based approvals APIs and cold schema initialization retain their existing contracts.
Evidence
Synthetic contention benchmark: four calls per case, with a second thread holding the real lifecycle coordinator for 250 ms before each call. Main-thread delay measures time until the next event-loop turn; the entry-point tests additionally assert zero native SQLite calls on the main thread for worker authorization commits.
Changed authorization still takes 333.63 ms to settle under contention; that wait happens on the worker. The measured main-thread delay drops by more than 99.8%. This is focused synthetic proof, not a new production CPU profile.
All heavy validation used provider
blacksmith-testbox, profileopenclaw-check, through the installed Crabbox CLI. Base:21f3d71a09d4356e2f9af53532ac5877136d0a0c.tbx_01m30kjgscy1z5vqgn32zabahv: baseline benchmark reproduced the stalls. The owner-profile zero-write regression failed on the old code with one write transaction, as intended. Dependencies were installed remotely after the initial benchmark could not resolvetsx; subsequent candidate sync attempts timed out before execution, and this lease was stopped.tbx_01m30n08c1gznynr3d99txrx5h: candidate benchmark above; five focused profile/approvals files passed 233 tests in 25.06 s, and owner/schema/migration siblings passed 43 tests in 5.87 s. After adding maintenance-drain coverage, all 47 approvals tests passed in 15.51 s. The default changed-file gate compared against a movingorigin/mainand included unrelated reverse differences, so the gate was pinned to the lane base. A later sync failed before that gate ran; this lease was stopped.tbx_01m30njpaep69j2ayay6harftg: the pinned changed-file gate passed core typing, all 24 core-test typing graphs (1,004.67 s), formatting, ratchets, dependency checks, and dead-export scans. Two compiler errors were corrected first; the remaining failure was variable-shadowing/parameter-reassignment lint, repaired with naming-only changes. A later sync timed out before the follow-up command could execute; the lease was stopped.tbx_01m30qrmdr8k2sg6p3cv98ph74: final lint passed with zero warnings/errors; fresh core typing and all remaining changed-file guards passed, including zero runtime import cycles. Final focused runs passed 74 tests in 20.34 s and 33 owner tests in 6.43 s. The complete command exited 0. All leases were stopped after their work.Focused commands:
Final serial test costs: profile tests 4.858 s, owner-profile tests 1.477 s, real-worker approvals tests 3.191 s, and authorization transaction tests 0.162 s. The socket-ensure assertion extends an existing approvals store test (35 ms in the preceding run). Focused command wall times above include compilation. Hosted job timings are available in the final exact-head CI run linked below.
Independent Codex review found no actionable P0–P2 findings in two passes. All selected changed-file checks passed across the gate and targeted completion commands; the completed core-test typing graphs were reused for the final naming-only lint cleanup. This PR does not deploy a Gateway; remaining synchronous state writers and cold first-use preparation are outside this optimization.
Landing repair and authorization
Peter (repository admin) explicitly directed on 2026-09-21: "override, I am admin, land as needed." This authorizes the native wrapper's supported admin/bypass route if an ownership or required-review gate blocks this PR; exact-head CI remains the landing gate.
The failed CI run at
9b77eb7b920c2f012d3c10d792794f3bdb8ee045exposed two related integration defects, not the known compact-shard flakes: authorization DTO imports created a static dependency cycle, and 27 execution suites still ran in Vitest threads after their commits moved to the host-owned state worker. The repair puts DTOs in the existing approvals contract and moves those suites to the existing infra process owner, preserving the production admission guard and prior watch routing.Pure main
894fb140a22246bc1574d5b29fe61e10f77036depassed the topology check and six representative execution suites (187 passed, three platform cases skipped; test command 53.31 s). On Blacksmith Testboxtbx_01m30xc1rn1m75wg13py709hmx, the repaired candidate passed zero static cycles, all 29 selected execution/worker files (579 passed, five platform cases skipped; 137.46 s), and three routing files (524 passed; 105.15 s). Total focused test command wall time was 244.84 s. No tests, typechecks, or builds ran on the saturated Mac.ClawSweeper's compatibility-proof item was reviewed and rejected as a data-model false positive: this change reuses the existing
exec_approvals_configrow format, readers/writers, schema versions, and legacy-migration gate. It changes scheduling and read-before-write admission without adding or changing a migration, schema, retention policy, or durability contract. The existing owner/schema/migration sibling proof is recorded above. Fresh independent review of the staged repair found no actionable P0–P2 findings.The repaired single commit was rebased onto
6bb897a7231a3cb681186b0645a9c1cdd1dcf3b3as1bed149c9a3697b50b3e77d1f94146382ad9748e, with the subject unchanged. The only conflict was the test-owner inventory; both main's new entry and this PR's execution entries were retained. Range-diff confirms that the rebase changed only that surrounding context.The next CI run exposed one additional real-exec consumer,
src/worker/worker.runtime.test.ts, still on a thread owner. It is now included in the same process-owner inventory (28 migrated execution suites total). Pure maind6b6253b965d39a94a23e4d3219c0fcec28008fapassed all 81 tests in 94.44 s wall; the repaired candidate passed the same 81 in 107.28 s ontbx_01m30zrs06dt2b6er74b3xv6fe. Fresh review of this final registration was clean through P2.The pinned changed-file gate passed on
tbx_01m30y9xrvntpqq7m5yvqhq131(core and core-test typechecks, formatting, lint, dead exports, dependency/import boundaries, schema and storage guards; 1,853.58 s remote command). Existing max-lines warnings remained non-fatal. A reused-lease sync had timed out before execution; the successful run used a fresh lease. All three task leases were stopped after their work.The preceding CI run also timed out in
test/scripts/release-check.test.ts/loads sparse release tooling and checks the target worker contractafter 120 s. The exact case passed independently on pure main in 11.69 s and on the candidate in 12.25 s. The timeout was not reproduced, and no fixture timeout or assertion was weakened.Final repaired head:
3baedbbbeaf7373db76389d2cdc225f76c2d799d, retaining one commit and the original subject. A Git merge-tree check against current main was clean before publication. Exact-head CI passed: CI run 35558085427. The native watcher returnedGREEN; the exact-headopenclaw/ci-gate, dependency-review, and security-sensitive-review statuses were all successful.Native review initialization encountered a GitHub API failure after changing its managed checkout. Only this run's retained operation lock was recovered, using the wrapper-printed exact token after verifying that its supervisor and process group had exited. The native review sequence then completed for the final head.