Skip to content

refactor: resolve persisted channel accounts asynchronously - #168481

Merged
steipete merged 57 commits into
mainfrom
dbasync/sw7b-4
Oct 10, 2026
Merged

steipete merged 57 commits into
mainfrom
dbasync/sw7b-4

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Channel account inspection, setup and status can read persisted plugin state synchronously on the Gateway thread.

User Impact

Channels can prepare saved-account state asynchronously without losing configured-account, saved-login or explicit report-scope behavior.

Existing config-only synchronous callbacks remain supported. The bundled Matrix build requires the matching V2 host. Official release sync owns the external plugin API floor; this PR does not claim Matrix package compatibility with pre-V2 hosts. Doctor, backup and recovery callers await repair completion.

Why This Change Was Made

Adds optional async companions for account, allowlist, DM-policy, auth-presence and setup/Doctor preparation, and migrates the host callers. Matrix state and credentials use worker-owned stores. Plugin reports intersect effective IDs with the caller's explicit normalized scope, including an empty scope.

This is part 4 of the nine-part S7 state/binding migration stack. Targets dbasync/sw7b-3 (parent PR); validation compares this part with its actual stack parent e19d2678d21e. The stack integrates pinned main 413d5f9bb3f7.

Evidence

Changed lines against the parent: production +921 / -485; tests and fixtures +513 / -375.

Focused integrated receipts cover persisted Matrix credentials, account discovery/status, and outbound target resolution: 625 passed, 0 skipped, mapped to 32/32 changed test files. These are recorded integrated file versions, not independent runs of every prefix; per-part counts are not additive. Stack totals are 3,296 passing receipts, 3,295 after removing one known relocation duplicate, and three skipped cases across 177 files; no required focused file remains missing.

Recorded JSON file spans total 97.963s. The relevant repaired integration batch took 496.047s wall time for 22 files; that is not a standalone timing for this part. File spans and invocation wall times are distinct; CI runner seconds were not measured.

Owner-reviewed native SDK digest: 39859ef4a47d91cbebde6060de71fa2d256a8e7966fe7cc9ec299c15c268476c. Zero released export removals; the digest reconciles to this parent/head through the generated-only baseline change. Optional async account hooks and separate async adapter types preserve existing callbacks.

The S7 family audit at c3667d2 resolved 18,862 inputs, 1,766 calls, 521 imports and 78 member references: 153 explicitly classified retained edges, zero unknown edges or async-contract errors. The publisher repair changed five scanned modules containing none of those captured family edges; retained-edge sources stayed unchanged. Final source differs from the passing repair head only by its generated assertion baseline. This preserves the original scan provenance rather than claiming a new full scan.

Core and extension production typechecks passed for all nine source prefixes; the final generated-only assertion-baseline adjustment does not change their code. The selected check-changed commands were executed, with the inherited failures below preserved.

Inherited failures remain explicit: Knip flags .github/actions/setup-release-harness/narrow-lockfile.mjs and src/infra/sqlite-source-fence-admission.ts; the production export scan flags PUBLIC_SESSION_ENTRY_SCRIPT; core lint has 10 unchanged max-lines findings; the environment-name count is 456/455, including unchanged OPENCLAW_PITCH. Relevant source/config blobs equal the pinned base. No blanket check-changed-green claim is made.

Three scoped review rounds completed. Accepted correctness findings were repaired; remaining scoped follow-ups are recorded in the relevant PR descriptions.

Final repair checks passed at 4b7d96b620ea: scoped lint (30.02 s), affected test types (342.12 s), import-cycle guard (23.46 s), and Madge (14.91 s).

Exact-final remote pnpm build passed in 369.642s. The qualified Matrix cold-import snapshot measured 104.992 MiB peak RSS, +58.199 MiB versus the empty baseline, and 383.791ms process CPU. Child/process-group cleanup and temporary-home removal were verified. This is a cold-import snapshot; the dependency closure is not attested. Statement-gate evidence follows separately; the update cell remains pending for the lander.

pnpm test src/commands/onboard-channels.e2e.test.ts --maxWorkers=1 passed 11/11 at the final source. Displayed file time was 2.932 s (JSON span 2.921 s), native Vitest wall time 38.76 s, and full invocation 417.725 s including artifact preparation. The earlier local attempt stopped at the managed-artifact isolation guard before tests; the successful proof used the remote isolated checkout.

Paired statement and request evidence

SQL statement gate

The native measurement group completed with exit 0. Its outer wrapper later returned 7 while reporting terminal telemetry; native completion receipts were reconciled, and the workload was not rerun merely for that reporting failure.

Accepted for e19d2678d21e → 3abbba26c39e. Same synthetic workload, ten warmed turns per run; three original alternating pairs followed by two extra pairs. All five pairs are retained. Adjacent-prefix comparisons in this PR stack share intermediate samples; each filtered base/head sequence remains alternating. Values below are base→head medians; warmed SQL/requests are per turn, while warmed wall time covers all ten turns. MAIN is Gateway-main-thread SQL. Wall ratio is head/base; no duration skew.

Phase All-thread SQL MAIN SQL Worker requests Wall seconds (ratio)
Boot 2320→2321 1933→1933 59→59 10.428→10.461 (1.0032×)
Connect 1173→1287 126→129 49→52 1.212→1.207 (0.9959×)
First turn 2623→2391 103→97 361→358 8.652→8.549 (0.9881×)
Warmed mean/turn 1005.2→1006.6 6.9→6.9 195.2→195.4 18.728→18.727 (0.9999×)
Second session 3853→3861 117→117 660→661 7.683→7.615 (0.9911×)
Control plane 33→33 0→0 5→5 1.106→1.107 (1.0009×)
Cron 1371→1376 53→53 210→210 5.461→5.449 (0.9978×)
Compaction 402→402 25→25 83→83 1.418→1.393 (0.9824×)
Shutdown 195→195 129→129 14→14 0.688→0.664 (0.9651×)
Whole workload 21942→21961 2555→2560 3396→3399 55.391→55.190 (0.9964×)
Chronology First-turn SQL Warmed SQL/turn Whole SQL Whole requests Whole wall ratio
Primary3 2623→2373 1005.2→1006.6 21942→21961 3389→3399 0.9944×
Extra4 2350→2391 1005→1006.2 21909→21928 3396→3391 1.0039×
Cumulative4 2511.5→2382 1005.1→1006.4 21925.5→21944.5 3392.5→3395 0.9969×
Extra5 2650→2636 1006.2→1007.2 22068→22112 3400→3413 0.9962×
Cumulative5 2623→2391 1005.2→1006.6 21942→21961 3396→3399 0.9964×

The warmed increase is +1.4 SQL/turn (+0.1393%), within the ≤0.5% unchanged-owner tolerance. Every warmed native SQL stack and sender stack across all five pairs was checked against this PR's changed files; none intersects them. MAIN remains 6.9 SQL/turn. The exact total-median samples are run 1 on both sides, for both primary3 and cumulative5.

Existing owner/operation SQL delta over ten warmed turns Exact source
Background session-row facts +14 Two BEGIN, two COMMIT, four version observations, two node-row reads, two transcript-watermark reads, one schema-meta read, one participant read
Shared row/ACP facts +10 Six ACP queries, two content-version reads, two version observations
Outbound recovery sweep +4 One existing recovery request moves into the warmed phase
Placement/attribution reads +2 One version read each
Other existing reads −16 Auth −9, maintenance −4, skill library −2, mentions −1
Total +14 10052→10066 SQL

Row/shared-fact requests rise 64→66: exact-entry refreshes remain ten, background refreshes rise 54→56 through the unchanged refreshBatch → drain owner. Row-request counts across the five runs are base [64,65,66,64,66], head [66,64,66,65,66]; the variation remains inside the baseline range. Outbound recovery comes through drainPendingDeliveriesCore; every full workload has exactly nine such requests, so its warmed increase is phase redistribution. Every warmed window retains 110 patch commits, ten turn commits, ten lifecycle projections and 50 domain publications.

The connect increase 1173→1287 (+9.72%) is assessed with the permitted combined startup window, not ordinary phase tolerance. Memory schema.admit performs exactly one request / 128 SQL in every run, moving between connect and first turn through the unchanged MemoryIndexDatabase.retryPublication owner. Its binding/close work and existing delivery/bootstrap/generated-HTML maintenance also move across that boundary.

Boot + connect + first turn Base runs Head runs Median
Original three pairs [6002,6047,6118] [6103,5999,6021] 6047→6021
All five pairs [6002,6047,6118,5992,6143] [6103,5999,6021,5999,6120] 6047→6021

Second-session +8 SQL and cron +5 stay within ten statements. These come from existing projection/schema validation and cron recovery/identity-evidence validation, with unchanged mutation counts. The first-turn median decreases; the warmed increase is accepted specifically as attributed unchanged-owner variation. Whole-workload SQL remains 21942→21961 (+19); extra4 is +19 SQL with five fewer requests, and extra5 is +44 SQL with 13 more requests. Those positive pairs are retained, not relabeled as lower-whole-workload RAW follow-ups or product savings.

The published-driver × candidate update cell is pending (lander). No release, package publication or Plugin SDK major bump is included.

Plugin state callbacks can perform SQLite work on the Gateway thread, including APIs that return a Promise.

Plugin authors gain a versioned worker-owned keyed store; existing synchronous and callback APIs keep their completion semantics through the current Plugin SDK major.
Native session bindings still expose host-thread persistence and synchronous preparation through harness adapters.

Native binding preparation and ordinary lifecycle mutations can complete through the worker while released synchronous integrations remain supported.
Conversation presentation and capture read native ownership on the Gateway thread even when their callers can await prepared facts.

Session rows and conversation capture retain their existing meaning while ordinary ownership preparation runs through workers.
Channel account inspection, setup and status can read persisted plugin state synchronously on the Gateway thread.

Channels can prepare saved-account state asynchronously without losing configured-account, saved-login or explicit report-scope behavior.
@steipete

Copy link
Copy Markdown
Contributor Author

Landing under Peter's relaxed landing v4 and native-stall exception. Final head: 0804ef8.

Merged current main, preserving the earlier stack repairs and async channel account/credential hooks. The SDK surface check exposed one extra public alias; removed that unused newly introduced alias while preserving the existing ChannelApprovalAdapter.nativeAsync contract. Independent P0/P1 review of this one-line fix is scoped-clean. The public-export budget remains unchanged at 3656.

Reuse published-driver 2026.9.9 × candidate update proof from #168478, run_3d6590a7c9c48b16a12382d7e111cda1, per the stack instruction. Exact-head SDK surface result is recorded below before submission. Required CI was still pending at the last observation; no green CI claim. Native review traversal exceeded ten minutes, encountered damaged worktree metadata, then needed refresh after the small fix; using the explicitly authorized head-pinned REST squash route. No pending native merge request was submitted. Other non-data/security/money review findings remain follow-ups under v4.

Exact-head remote check passed: pnpm plugin-sdk:surface:check, AWS Crabbox run_0942d511bf8cb2a30c74ea42d8da2403, 13.7s command time. Public exports: 3656; shipped v2026.9.9 API compatibility: no unauthorized removals.

@steipete
steipete merged commit 5c70041 into main Oct 10, 2026
130 of 136 checks passed
@steipete
steipete deleted the dbasync/sw7b-4 branch October 10, 2026 22:22
steipete added a commit that referenced this pull request Oct 10, 2026
#168481 added an async resolveChannelDmPolicy to account-resolution.ts next
to the SDK-exported resolveChannelDmPolicy in dm-access.ts, so
check-source-contracts failed on every pull request with an export-name
collision (main pushes skip that job). Rename the internal plugin-facing
resolver to resolvePluginDmPolicy, the alias channel-pairing already used.
steipete added a commit that referenced this pull request Oct 11, 2026
Finish the failures reported by scheduled run 38095292949 after the async
channel-account, approval, and plugin-state campaigns (#168481, #168482,
forwarding to its receiver, and supply the async status report in the
install compensation fixture. Preserve the separately landed core DM
resolver and observation-cache lint fixes when rebasing onto current main.

Remove unused new async exports and duplicate broad-barrel re-exports.
Migrate bundled consumers to the existing narrow SDK entrypoints and keep
Discord's plugin-local async binding lookup out of its runtime API.

The remaining five callable/export budget additions are intentional
sync-to-async replacement pairs, retaining each shipped sync contract:
- inspectConversationBinding -> inspectConversationBindingAsync: permit
  inspection of worker-owned binding state.
- resolveCommandAuthorization -> resolveCommandAuthorizationAsync: await
  persisted account authorization in Discord, Slack, and Telegram.
- createApproverRestrictedNativeApprovalCapability -> Async: await native
  approval eligibility through the narrow approval delivery entrypoint.
- createChannelApprovalNativeRuntimeAdapter -> Async: support Matrix's
  async eligibility callbacks without changing the sync adapter contract.
- createLazyChannelApprovalNativeRuntimeAdapter -> Async: preserve lazy
  Matrix approval loading with the same async callback contract.

Document the replacements and retain four deprecated synchronous
conversation contracts until the next Plugin SDK major. Reduce the broad
SDK budget to the actual retained surface instead of absorbing unused
exports. No shipped SDK export is removed.

Validation: export-name collision guard; type-aware core, script, and
extension oxlint; Knip exported-type check; SDK surface check; exact
runtime API guardrail, SDK surface, and install-compensation tests.
The two changed test suites passed 23 tests in 255.16s with maxWorkers=1;
no tests or CI test seconds are added. Command authorization, DM-policy
audit, and Feishu binding tests also passed. Codex P1 review is clean.
Runtime/plugin bundles and native load guards passed. The broader package
declaration build and optional Gateway/channel smoke attempts did not
complete; no assertion failure was reported in those attempts.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…#168481)

* refactor(plugin-sdk): share legacy persistence warning budgets

* feat(plugin-sdk): add worker-owned keyed state

Plugin state callbacks can perform SQLite work on the Gateway thread, including APIs that return a Promise.

Plugin authors gain a versioned worker-owned keyed store; existing synchronous and callback APIs keep their completion semantics through the current Plugin SDK major.

* refactor: move native binding preparation to workers

Native session bindings still expose host-thread persistence and synchronous preparation through harness adapters.

Native binding preparation and ordinary lifecycle mutations can complete through the worker while released synchronous integrations remain supported.

* refactor: prepare conversation ownership off the Gateway thread

Conversation presentation and capture read native ownership on the Gateway thread even when their callers can await prepared facts.

Session rows and conversation capture retain their existing meaning while ordinary ownership preparation runs through workers.

* refactor: resolve persisted channel accounts asynchronously

Channel account inspection, setup and status can read persisted plugin state synchronously on the Gateway thread.

Channels can prepare saved-account state asynchronously without losing configured-account, saved-login or explicit report-scope behavior.

* test: bind native lease fixtures to V2 action authority

* test: await channel setup registry fixtures

* test: complete keyed state runtime fixture

* test: align Matrix recovery and channel target fixtures

* refactor(plugin-state): separate offline migration entrypoints

* refactor(codex): share binding helpers and contract fixtures

* refactor: separate session row preparation and publications

* refactor: share channel lifecycle and test helpers

* test: retain async status discovery arguments

* test(codex): model current conversation inspection boundary

* test(facetime): bind persistence barriers before runtime startup

* docs: explain validated discussion account config

* test: exercise native binding lifecycle through worker settlement

* test: document isolated runtime dependencies

* test: document isolated runtime dependencies

* fix: preserve native binding method receivers

* fix: bind model preparation authority to its reader

* chore: regenerate worker and test guard baselines

* chore: regenerate worker and test guard baselines

* chore: reconcile worker migration baselines

* test: run native row ownership with the host broker

* fix(clickclack): fence discussion cleanup and reconciliation

* test(clickclack): avoid shadowing store options

* refactor: keep async approval adapter within existing SDK contract
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
openclaw#168481 added an async resolveChannelDmPolicy to account-resolution.ts next
to the SDK-exported resolveChannelDmPolicy in dm-access.ts, so
check-source-contracts failed on every pull request with an export-name
collision (main pushes skip that job). Rename the internal plugin-facing
resolver to resolvePluginDmPolicy, the alias channel-pairing already used.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
Finish the failures reported by scheduled run 38095292949 after the async
channel-account, approval, and plugin-state campaigns (openclaw#168481, openclaw#168482,
forwarding to its receiver, and supply the async status report in the
install compensation fixture. Preserve the separately landed core DM
resolver and observation-cache lint fixes when rebasing onto current main.

Remove unused new async exports and duplicate broad-barrel re-exports.
Migrate bundled consumers to the existing narrow SDK entrypoints and keep
Discord's plugin-local async binding lookup out of its runtime API.

The remaining five callable/export budget additions are intentional
sync-to-async replacement pairs, retaining each shipped sync contract:
- inspectConversationBinding -> inspectConversationBindingAsync: permit
  inspection of worker-owned binding state.
- resolveCommandAuthorization -> resolveCommandAuthorizationAsync: await
  persisted account authorization in Discord, Slack, and Telegram.
- createApproverRestrictedNativeApprovalCapability -> Async: await native
  approval eligibility through the narrow approval delivery entrypoint.
- createChannelApprovalNativeRuntimeAdapter -> Async: support Matrix's
  async eligibility callbacks without changing the sync adapter contract.
- createLazyChannelApprovalNativeRuntimeAdapter -> Async: preserve lazy
  Matrix approval loading with the same async callback contract.

Document the replacements and retain four deprecated synchronous
conversation contracts until the next Plugin SDK major. Reduce the broad
SDK budget to the actual retained surface instead of absorbing unused
exports. No shipped SDK export is removed.

Validation: export-name collision guard; type-aware core, script, and
extension oxlint; Knip exported-type check; SDK surface check; exact
runtime API guardrail, SDK surface, and install-compensation tests.
The two changed test suites passed 23 tests in 255.16s with maxWorkers=1;
no tests or CI test seconds are added. Command authorization, DM-policy
audit, and Feishu binding tests also passed. Codex P1 review is clean.
Runtime/plugin bundles and native load guards passed. The broader package
declaration build and optional Gateway/channel smoke attempts did not
complete; no assertion failure was reported in those attempts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: matrix Channel integration: matrix cli CLI command changes commands Command implementations docs Improvements or additions to documentation extensions: qa-lab gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant