Repository navigation
refactor: prepare conversation ownership off the Gateway thread - #168480
Conversation
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.
|
Landing with the operator-authorized relaxed CI policy and head-pinned REST fallback after native review/preparation exceeded ten minutes. The main merge preserves publication ordering and operation receipts, worker routing, and transcript effect checks. Native artifacts were completed for the integration head; the subsequent fixes received independent P0/P1 review. Focused integration proof: 65 tests across five files passed (run_7f5d524b1e4c083458b017fb5b22245d). CI exposed small await/type/mock fixture issues; these were corrected without weakening assertions. The follow-up run passed 90 tests and exposed one real, pre-existing cleanup defect: registry revocation could reject an ownership read after a native fork, before the retirement catch. The same failure reproduced on integrated main 48588a6 (run_4c44b05aaeb7cfcf8a420197648d8e96). The existing catch now covers that ownership read; all three rollback-revocation cases pass (run_aca45f3ded585d2296d1fc5ec058ec87). The final cleanup fix shrinks the code and preserves the existing identity and subscription assertions. Full required CI is not claimed green. The earlier exact-head failures were the corrected lint/types/mocks; this uses the approved small-fix/slow-CI exception. No CI jobs were rerun. No unresolved product regression is known in the tested paths. Published-driver update proof is reused from #168478 (driver 2026.9.9, candidate c5e53dc, run_3d6590a7c9c48b16a12382d7e111cda1). This PR adds runtime ownership reads and does not change the update path. |
#168480 reshaped the placement-session-runtime mock factory in apply-session-model-selection-placement.test.ts, so its grandfathered test-mock-exports baseline entry no longer matched and every pull request failed checks-fast-baseline-ratchets (main pushes skip that job). Mark the hand-built fixture as intentional isolation and prune the stale entry.
Keep the committed-observation cache lint clean and document the explicit Worker receiver used by the race fixture. Account exactly for the intended async approval/command and V2 conversation binding APIs from #168480 and #168483; retain their released compatibility contracts. Validation: exact core oxlint, core tsgo, export-name collision guard, SDK surface check, formatting and diff checks pass. Focused Node tests: 74 passed, one platform skip across six files (82.64s total); plugin-state comparison 14 passed in 21.52s including preparation. Codex review found no actionable issues.
…claw#168480) * 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. * test: bind native lease fixtures to V2 action authority * test: complete keyed state runtime fixture * refactor(plugin-state): separate offline migration entrypoints * refactor(codex): share binding helpers and contract fixtures * refactor: separate session row preparation and publications * 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 * 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 * test: run native row ownership with the host broker * fix(clickclack): fence discussion cleanup and reconciliation * test(clickclack): avoid shadowing store options * fix: align runtime ownership call and fixture contracts * fix(codex): retire fork client when ownership lookup rejects
openclaw#168480 reshaped the placement-session-runtime mock factory in apply-session-model-selection-placement.test.ts, so its grandfathered test-mock-exports baseline entry no longer matched and every pull request failed checks-fast-baseline-ratchets (main pushes skip that job). Mark the hand-built fixture as intentional isolation and prune the stale entry.
Keep the committed-observation cache lint clean and document the explicit Worker receiver used by the race fixture. Account exactly for the intended async approval/command and V2 conversation binding APIs from openclaw#168480 and openclaw#168483; retain their released compatibility contracts. Validation: exact core oxlint, core tsgo, export-name collision guard, SDK surface check, formatting and diff checks pass. Focused Node tests: 74 passed, one platform skip across six files (82.64s total); plugin-state comparison 14 passed in 21.52s including preparation. Codex review found no actionable issues.
The async approval/command migration is openclaw#168482 (36a5eef), correcting the preceding commit message reference to openclaw#168480. The conversation migration is openclaw#168483 (fe8bc06). Record both at their source-owned budgets.
What Problem This Solves
Conversation presentation and capture read native ownership on the Gateway thread even when their callers can await prepared facts.
User Impact
Session rows and conversation capture retain their existing meaning while ordinary ownership preparation runs through workers.
Conversation registration and session association remain with the existing agent-worker transaction owners. Existing final authority guards and the explicit unbound-incognito compatibility path remain. There is no new runtime freshness probe.
Why This Change Was Made
Migrates host consumers to prepared harness ownership, binds row projections to their exact keyed-state dependencies, and invalidates them from committed receipts or unknown outcomes. Pending writes do not change descriptive committed truth, and unrelated writes do not invalidate these rows. Conversation audit capture uses the worker read and existing fenced transcript operation. Removes the unreleased native conversation write wrapper.
This is part 3 of the nine-part S7 state/binding migration stack. Targets
dbasync/sw7b-2(parent PR); validation compares this part with its actual stack parent8a729050a0a2. The stack integrates pinned main413d5f9bb3f7.Evidence
Changed lines against the parent: production +867 / -318; tests and fixtures +324 / -79.
Focused integrated receipts cover prepared ownership, committed publication/invalidation, conversation capture/catalogue, and delivery admission: 160 passed, 0 skipped, mapped to 13/13 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 file spans total 139.866s. The standalone ownership replay took 106.363s wall time, including setup, and passed after database-worker routing was registered. File spans and invocation wall times are distinct; CI runner seconds were not measured.
Owner-reviewed native SDK digest:
2584df2f4d9a4f99e8371dbac772c1e6c33741f7f7323d55eedf613a54ef7cd7. Zero released export removals; the digest reconciles to this parent/head through the generated-only baseline change. Removed helpers are private registry wrappers, not released SDK exports.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.mjsandsrc/infra/sqlite-source-fence-admission.ts; the production export scan flagsPUBLIC_SESSION_ENTRY_SCRIPT; core lint has 10 unchanged max-lines findings; the environment-name count is 456/455, including unchangedOPENCLAW_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.
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
8a729050a0a2 → e19d2678d21e. 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.The original first-turn increase 2609→2623 (+14) triggered RAW TURN follow-up. Extra4 satisfies that follow-up: whole SQL 22004→21909 (−95), requests 3400→3396 (−4), wall 55.774→54.977 s, with no duration skew. Extra5 is also retained: first-turn SQL rises 2626→2650 while whole SQL falls 22094→22068 and requests fall 3404→3400. The cumulative five-pair first-turn and warmed medians both decrease, 2626→2623 and 1006.6→1005.2, and every other cumulative all-thread phase is equal or lower.
MAIN first-turn SQL still rises 94→103 and whole MAIN SQL 2546→2555; these are disclosed alongside the raw all-thread result. Acceptance is based on the retained RAW follow-up and final phase medians, without claiming that the lower totals are savings caused by this SDK change.
Actual correlated-reply capture entrypoint: three alternating pairs
The existing
conversation-turn-capture.test.tscase “consumes a correlated reply inline and persists only a side artifact” passed in three alternating parent/head pairs. The selected test body is byte-identical on both heads. A task-owned setup installs the repository's worker-preload support after normal isolation; product and test-body code are unchanged.SQL and product-request counts match across all three pairs; wall ratio 1.067 is valid. Host here means the test process, not Gateway MAIN. Counts include fixture setup, assertions and cleanup, and are not steady-state per-capture costs. The original host-only observation is retained separately and is not used as all-thread proof.
Product sends add 12 session-store targets, three session-entry reads, one cold-metadata read, one SQLite target and seven resource closes. One native
database.prepareWriterequest is replaced by onedatabase.domain.publish. Other product request types are unchanged. The observer also sees compiler transport: all genericreadonlycontexts are verified esbuild/tsx traffic; they remain visible in raw totals. The 32 shared Gateway request reports contain none of that traffic and need no correction.Direct capture stacks/ancestry account for 43 parent host SQL and nine head worker SQL, but queued callbacks lose their original ancestry. The head additionally has 26 SQL in the audit publication and 22 in its cold entry reader. The large host reduction includes lazy admission/schema/lease work. Neither the partial 43→9 bucket nor the whole-test −396 difference is presented as the complete cost or a steady-state saving for a single capture.
The published-driver × candidate update cell is pending (lander). No release, package publication or Plugin SDK major bump is included.