Repository navigation
refactor(state): run profile setters in the state worker - #162571
Conversation
Move the remaining Gateway email acquisition and canonical profile selection callers onto existing state worker operations. Retain request and profile authority across waits and recheck it before writes, network effects, and metadata publication. Remove the synchronous Gateway access helpers. Keep schemas, stored data, permissions, and update behavior unchanged. Remaining profile reads/setters and account stores follow in a second slice. Isolate session-catalog fixture writes from background reclamation so request cleanup assertions remain deterministic across the worker wait.
Profile acquisition now rejects discovery snapshots before model catalog loading. Preserve zero credential and HTTP effects while testing the direct handler rejection; WebSocket dispatch owns the error response.
Synchronize the concurrency fixture on all reader callbacks entering after asynchronous profile preparation. Preserve the original unrelated-creation, response, and cleanup assertions without timers or polling.
Infer shared-state worker command contracts from lazy per-domain handler tables. Migrate Web Push, APNs, worktree registry operations, and fleet registry while preserving the existing broker and transaction owners.
Keep the shared post-await authority assertion before catalog effects and the final publication check, without duplicate session path validation. Migrate authorization fixtures to the async profile owner contracts and remove their retired resolver mock. Existing real Gateway freshness budgets and permission assertions remain unchanged.
Move profile writer kernels behind the typed worker registry and route display-name and avatar RPCs through admitted worker writes. Recheck requester authority before refreshing connected profiles, use current committed display facts, and preserve committed self-merge responses. Keep role-policy reads as follow-up migration work; schemas and update behavior are unchanged.
…ync/profiles-2 # Conflicts: # src/fleet/registry.types.ts # src/fleet/registry.worker.ts # src/gateway/server-methods.authorization.test.ts # src/gateway/server-methods/chat-metadata-handler.test.ts # src/gateway/server-methods/users.test.ts # src/gateway/server-methods/users.ts # src/infra/push-web-store.worker.ts # src/state/openclaw-state-worker-registry.ts
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review blockedAutomated review did not run, so no review verdict was produced. Reason: The input-safety check rejected material in this revision. No detected value, path, or scanner output is reproduced here. Automatic review is on hold, including after source changes. Request a fresh re-review after resolving the failure; maintainers can also release the hold through an intentional scanner-policy update. Next step: If this is a genuine credential, remove and rotate it. If it is an intentional test fixture, a maintainer must review and qualify it. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: blocked before merge. Reviewed October 1, 2026, 7:41 AM ET / 11:41 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch moves profile name and avatar writes into the existing state worker, consolidates profile operation dispatch, preserves current display publication, and updates affected fixtures and tests. Merge readiness⛔ Blocked before merge - 2 items remain The PR remains useful: current main still executes profile name and avatar setters synchronously. No actionable introduced defect was found, and GitHub now reports the pinned head as mergeable, resolving the previous conflict blocker. Priority: P2 Review scores
Verification
How this fits togetherGateway profile RPCs authorize requests and submit mutations to OpenClaw’s shared-state worker. Committed SQLite results update the profile catalog, connected clients, and RPC responses. flowchart TD
A[Profile edit request] --> B[Gateway authorization]
B --> C[State worker broker]
C --> D[Transaction and commit admission]
D --> E[Profile SQLite mutation]
E --> F[Committed profile catalog]
F --> G[Connected clients and RPC response]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep profile mutations under the existing worker admission and commit-publication owner while preserving RPC results and current catalog displays. Do we have a high-confidence way to reproduce the issue? Not applicable as a new user-facing bug reproduction; source confirms the current-main setters perform synchronous SQL, and the PR supplies a focused handler-boundary negative control. Is this the best way to solve the issue? Yes: extending the existing admitted worker and migrating internal callers preserves one mutation owner without introducing another store, protocol, or public API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bb69e5fbb24d. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Preserve the UserProfile worker cutover alongside newly registered main domains and retain async session-metadata fixture cleanup.\n\nValidation: core types, zero import cycles, database-worker ratchet, 103 focused tests, and scoped autoreview.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…2571) * refactor(state): resolve Gateway profiles in state workers Move the remaining Gateway email acquisition and canonical profile selection callers onto existing state worker operations. Retain request and profile authority across waits and recheck it before writes, network effects, and metadata publication. Remove the synchronous Gateway access helpers. Keep schemas, stored data, permissions, and update behavior unchanged. Remaining profile reads/setters and account stores follow in a second slice. Isolate session-catalog fixture writes from background reclamation so request cleanup assertions remain deterministic across the worker wait. * test(gateway): assert snapshot rejection at handler boundary Profile acquisition now rejects discovery snapshots before model catalog loading. Preserve zero credential and HTTP effects while testing the direct handler rejection; WebSocket dispatch owns the error response. * test(gateway): await concurrent metadata reader admission Synchronize the concurrency fixture on all reader callbacks entering after asynchronous profile preparation. Preserve the original unrelated-creation, response, and cleanup assertions without timers or polling. * refactor(state): register worker operations once per domain Infer shared-state worker command contracts from lazy per-domain handler tables. Migrate Web Push, APNs, worktree registry operations, and fleet registry while preserving the existing broker and transaction owners. * fix(gateway): retain one catalog acquisition authority check Keep the shared post-await authority assertion before catalog effects and the final publication check, without duplicate session path validation. Migrate authorization fixtures to the async profile owner contracts and remove their retired resolver mock. Existing real Gateway freshness budgets and permission assertions remain unchanged. * refactor(state): run profile setters in state workers Move profile writer kernels behind the typed worker registry and route display-name and avatar RPCs through admitted worker writes. Recheck requester authority before refreshing connected profiles, use current committed display facts, and preserve committed self-merge responses. Keep role-policy reads as follow-up migration work; schemas and update behavior are unchanged. * refactor(state): let profile handlers own kernel dispatch * test(gateway): assemble synthetic question URL credentials * test(gateway): synchronize concurrent project discovery
Give fixtures owned private directories, resolved session-store paths, a valid runtime executable and explicit reply policy. Preserve real dispatch, lifecycle cleanup, negative cases and production path guards; use the existing npm JSON parser. Reuse the exact canonical memory admission, project-read coordination and enrollment retry fixture changes from ad183c8 (#162574), ed961d5 (#162571), and 178005d (#162721). Co-authored-by: Peter Steinberger <[email protected]>
Related: #162414, #162446
What Problem This Solves
Display-name and avatar RPCs still execute profile SQL on the Gateway thread.
Why This Change Was Made
Route both setters through the existing admitted state worker, and register the UserProfile domain through the typed operation registry. The domain handler table consumes synchronous writer kernels from the worker implementation; the old host setter exports and command guards/dispatchers are removed.
After awaiting a write, Gateway handlers recheck requester authority before refreshing connected profiles. Refreshes consume current committed catalog rows so a delayed result cannot replace a newer display. A committed self-merge still returns its receipt after revoking its own connection, while skipping an unauthorized refresh.
User Impact
Profile RPC shapes and stored values are unchanged. The real Gateway-handler test demonstrates zero calling-thread SQLite operations for display-name and avatar edits; before the cutover it observed 16
preparecalls.src/state/user-*.tsinventory: T1 90 → 79, T2 12 → 12, W 5 → 14.user-profiles.tsalone drops 16 → 5 T1 sites. These are static primitive-call counts, separate from the runtime proof.0e5da43ea5c3b5db7409eb1f9610351520384bab. Tests, test support, and docs are excluded.userProfilesregistry handlers, and then the synchronous worker kernels. Kernel exports have production consumers in that handler table; test fixtures also exercise their transaction semantics directly.Remainder:
getUserProfileRoleand the synchronous operator-role-policy fallback remain migration debt. Completing them requires carrying prepared role/catalog lifetimes through cold HTTP, cron, plugin, and retained policy guards, including the excluded GitHub/model-account owners. That work is estimated at roughly +120–200 net production lines and exceeds this lane's remaining allowance. Preferences and account-store runtime code are outside this PR.Evidence
node scripts/database-worker-inventory.mjs --json, filtered tosrc/state/user-*.ts, on the pinned base and integrated candidate: counts above.pnpm check:database-worker-ratchet --base e2e4a34c9828f1230d906567c0eacb7b1e1fe185: passed after merging main.node scripts/check-changed.mjs --base 0e5da43ea5c3b5db7409eb1f9610351520384bab: passed (all selected checks, including core/root/UI typechecks, lint, unused-export scans, docs, and ratchets).git diff --check: passed.The post-merge focused run passed 148 tests in 10 files. After the final handler-table ownership correction, this additional command passed 17 tests, wall 149.18s:
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test src/gateway/server-methods/users-enumeration.worker.test.ts src/state/user-profile-writes.role.test.ts src/state/user-profiles-multi-account.test.ts src/state/openclaw-state-worker-registry.test.ts --maxWorkers=1Coverage includes delayed writes, rejection, lost/current requester authority, newer committed display facts, worker routing, role settlement, aliases, and committed self-merge responses. The earlier broader focused proof passed 409 distinct tests across 17 files. Import-only fixture updates also passed the full core/root/UI typechecks; their remaining full suites were not rerun.
Measured test command wall times
Each row ran
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test <file> --maxWorkers=1.Post-merge focused proof:
src/gateway/server-methods/users.test.tssrc/gateway/server-methods/users-enumeration.worker.test.tssrc/state/user-profiles-multi-account.test.tssrc/gateway/server-methods.users-merge.test.tssrc/state/user-profile-writes.role.test.tssrc/state/user-profiles.test.tssrc/state/user-profile-aliases.test.tssrc/gateway/server-methods.authorization.test.tssrc/state/user-profiles.avatar-worker.test.tssrc/state/openclaw-state-worker-registry.test.tsAdditional sibling/fixture-extraction proof before the main merge:
src/gateway/server-methods/approval.test.tssrc/gateway/server-methods/themes.test.tssrc/gateway/server/plugins-http.runtime-scopes.test.tssrc/gateway/server/ws-connection/message-handler.post-connect-health.test.tssrc/gateway/sessions-history-http.test.tssrc/state/user-channel-identities.test.tssrc/gateway/github-user-identity.test.tsWall times include worker compilation/transforms on a heavily loaded host. Existing approval, theme, history, and identity suites retain their real persistence/lifecycle coverage; fixture extraction added no assertions or per-case boots. Five coherent fixture moves keep import changes within existing line caps. Existing coverage was preserved, and no baseline allowance was expanded. CI timing is unavailable at PR creation.
The line-cap gate initially rejected small import growth in oversized test files; existing fixtures were moved into test-support owners. The assertion-safety baseline shrank by one after removing the avatar MIME cast. The production unused-export gate then identified kernels exported only for tests; moving the handler table to the existing domain registry gave those exports real production consumers. Both production and full-tree unused-export scans now pass without exceptions.
Compatibility retained
No synchronous host compatibility shim was added.
setDisplayName,setAvatar,linkEmail,mergeProfiles,syncGitHubIdentity, andsetUserProfileRoleare removed from the host module and retained as synchronous worker kernels.isUserProfileCommand,executeUserProfileCommand, andisUserProfileWriteCommandare deleted. Existing synchronous schema/migration/boot owners retain their T2 contract; the unchanged role-policy reader is the explicit remainder above. Public RPC and plugin SDK contracts are preserved.Update behavior
No schema, stored-state format, retention, durability, configuration, or permission change. No updater/Doctor behavior or migration is added.
Scanner correction and main integration
The exact-review scanner includes both endpoint blobs and the complete diff, so fixing only the PR head left the synthetic URI visible in the merge-base file and a removed patch line. The fixture-only correction landed directly on main as
9ced5fc07daee9af43fa2a7542f7543bdd651648, then main was merged into this branch asb15d9dc7ca5c201816ddd9635d036ccb0bb23c96. The sole merge conflict retained every main worker domain alongside this branch's UserProfile registration.The runtime URL is byte-for-byte unchanged, with identical assertions. No scanner ignore/allow entry was added. The question fixture now matches main; this PR retains only its profile-kernel import change in that file.
Validation:
filesystem --results=verified,unknown,unverified --fail --fail-on-scan-errors --no-update --json --no-color --no-verification: zero findings in the corrected file and in the merged PR's complete source bundle (331 unique endpoint blobs plus raw diff and full binary patch, 333 inputs). Bundle endpoints were9ced5fc07daee9af43fa2a7542f7543bdd651648andb15d9dc7ca5c201816ddd9635d036ccb0bb23c96. This reproduces the source inputs that caused the refusal; hydrated GitHub prompt text was not regenerated locally.pnpm test src/gateway/server-methods/question.test.ts --maxWorkers=1: 30 passed, 47.79s wall on the final main candidate. Earlier runs before main advanced passed in 66.27s and 54.74s. One direct push was rejected because main advanced; the single local commit was rebased and retested before the successful fast-forward push.git diff --check: passed. Post-merge lint also covered the combined worker registry.OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test src/gateway/server-methods/users.test.ts src/gateway/server-methods/users-enumeration.worker.test.ts src/state/user-profiles-multi-account.test.ts src/gateway/server-methods.users-merge.test.ts src/state/user-profile-writes.role.test.ts src/state/user-profiles.test.ts src/state/user-profile-aliases.test.ts src/gateway/server-methods.authorization.test.ts src/state/user-profiles.avatar-worker.test.ts src/state/openclaw-state-worker-registry.test.ts src/gateway/server-methods/question.test.ts --maxWorkers=1pnpm check:madge-import-cycles: 0 cycles, 32.66s wall.pnpm check:database-worker-ratchet --base e2e4a34c9828f1230d906567c0eacb7b1e1fe185: passed, 9.73s wall.The direct-main fixture worktree and local branch were removed after verifying the commit on remote main. Production remains +633 / -628 / net +5 lines against the new merge base, excluding tests and test support.
CI project-discovery fixture repair
Repair commit:
a4587132c54e75de75b341032375f3bdad40f95c.The failed job 110326159434 failed
src/gateway/server-methods/projects.test.ts:87, testprojects.list coalesces concurrent observed Git discovery and refreshes later reads, with eight total Git launches versus a four-launch single-pass baseline. This is a total-work assertion, not the Git worker's process-concurrency limit.Classification: inherited scheduling-sensitive test fixture. The test and discovery implementation are identical on PR head
b15d9dc7ca5c201816ddd9635d036ccb0bb23c96and the comparison maind64730851269b8ca5e82d9778810aa0669eb2e3e. The test was introduced by703cbf2fdffc, before this PR. This request carries no profile identity and does not invoke the changed profile setters.projects.listindependently awaits registry and session SQLite preparation before identity discovery.git-read-cache.tsdeliberately shares only pending identity operations, deleting each entry on settlement so later discovery observes external Git changes. Starting ten RPCs withPromise.alldoes not guarantee their Git operations overlap. An early pass can finish before later RPCs reach discovery.The unmodified failure did not recur in three ordered six-file shard replays and three standalone project-file runs on either revision. A temporary promise-controlled diagnostic then held the last five discovery admissions until the first five settled. It reproduced exactly 8 > 4 on both PR and main, without sleeps, timers, assertion changes, or production changes. The diagnostic traces showed admissions 1–5, settlements 1–5, then admissions 6–10 and settlements 6–10. The original CI log has no equivalent admission trace; this proves the matching race mechanism, rather than claiming to reconstruct its exact scheduler interleaving.
The fixture now waits for all ten RPCs at the existing discovery-service boundary before calling through to the real implementation. The registered handler, cache, worker, Git processes, spawn assertion, and later remote-change/deleted-checkout assertions remain intact. Early RPC settlement releases the barrier so failures cannot strand other callers. The spy is restored before the later freshness checks. Only this test file changed: +19/-1 test lines, 0 production lines; no cap or assertion was changed.
The log was fetched once. Its six-file reported order was:
src/gateway/session-row-projection.invalidation.test.tssrc/gateway/server-methods/sessions-sharing.test.tssrc/gateway/server-methods/projects.test.tssrc/gateway/update-run-notice-target.test.tssrc/gateway/session-utils.queued-collector-narrow-abort.test.tssrc/gateway/session-delivery-clock-jump.integration.test.tsA temporary
BaseSequencerreplay config extendedtest/vitest/vitest.gateway-database-workers.config.ts, sorting these paths in that order with one worker. It was used equally on PR and main, outside the repository. The hosted shard config permitted two workers; local serial ordering explicitly exercised the preceding-file state. Local evidence is macOS arm64/Node 26.10.0; CI used Linux x64/Node 24.19.0. No remote CI jobs were rerun manually.Unchanged-source replay wall times (seconds):
All local test commands used
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000. Replays usednode scripts/run-vitest.mjs --config "$ORDERED_CONFIG" <paths in the order above> --maxWorkers=1, with the same command restricted toprojects.test.tsfor standalone runs. Concurrent validation commands used separateOPENCLAW_VITEST_FS_MODULE_CACHE_PATHdirectories.Post-fix validation:
pnpm test src/gateway/server-methods/projects.test.ts --maxWorkers=1: 20/20, 41.89s wall. The initial run spent about 18 seconds executing tests; wall time includes source transformation and worker preparation.node scripts/check-changed.mjs --base b15d9dc7ca5c201816ddd9635d036ccb0bb23c96 -- src/gateway/server-methods/projects.test.ts: passed, including the Gateway-methods typecheck, lint, formatting, applicable ratchets, and all unused-export scans (363.99s wall).pnpm check:madge-import-cycles: 0 cycles, 36.73s wall.pnpm check:database-worker-ratchet --base e2e4a34c9828f1230d906567c0eacb7b1e1fe185: passed, 12.50s wall.No runtime, schema, updater, permission, or scanner-policy change. The comparison worktree and temporary timing probes were removed. Post-fix CI timings are not yet available.