Repository navigation
refactor: migrate Reef trust and state to workers - #168486
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.
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.
Command authorization and approval routing can force channel persistence reads onto the Gateway thread. Command and approval preparation can await persisted channel state while retaining current authorization at dispatch and delivery.
Conversation binding APIs include synchronous writes and reads that prune state, and existing async methods can fall back to synchronous adapters. Plugin authors gain a V2 binding contract with required async operations and coherent source assertions; released structural adapters remain compatible.
Message-action discovery and Matrix binding lookups can synchronously load persisted state, while queued snapshots can overwrite newer binding changes. Saved-login Matrix accounts retain their actions and capabilities; binding activity and shutdown persistence remain correct with worker-owned storage.
Reef trust, registration, audit and replay flows depend on synchronous keyed-state callbacks. Reef persists ordinary state through worker-owned operations while preserving conditional trust decisions and recovery behavior.
|
Landing under Peter's relaxed landing v4 at exact head e2b707d. Main was merged while preserving its atomic Reef trust/receipt owners and the remaining registration/replay migration. The missing-catchup question is resolved in the PR body: the equivalent main and candidate paths both perform the memory transcript-statistics read; no omitted Reef catchup or claimed receipt-based saving remains. AWS Crabbox run_74a21172f5a661e71d4aa52ce00fb12f passed all 513 selected Reef/startup-catchup tests and the published-driver 2026.9.9 × candidate update cell. That tested head was 4404d37. The only later change is test-fixture type annotations, so those proofs are reused under the approved test-only rule. The final-head extension test typecheck passed in run_9a02a7d707dc0a809a06b560bc90788b. The scoped P0/P1 review of the annotation fix is clean. The first integration CI attempt found five TS7006 fixture errors; one correction push fixed them, and the exact affected typecheck now passes. Final-head required CI remains pending at last observation; no CI-green claim is made. The earlier SDK export-budget and inherited environment/Gateway follow-ups remain recorded, with no limits raised. Native review initialization could not obtain the managed worktree allocation lease for more than ten minutes. The owned attempt was stopped before any merge submission, its lock was recovered, and no auto-merge request remained. Using the explicitly authorized head-pinned REST squash fallback. |
* 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. * refactor: prepare command and approval eligibility asynchronously Command authorization and approval routing can force channel persistence reads onto the Gateway thread. Command and approval preparation can await persisted channel state while retaining current authorization at dispatch and delivery. * feat(plugin-sdk): add worker-owned conversation binding APIs Conversation binding APIs include synchronous writes and reads that prune state, and existing async methods can fall back to synchronous adapters. Plugin authors gain a V2 binding contract with required async operations and coherent source assertions; released structural adapters remain compatible. * refactor: move Matrix bindings and action discovery to workers Message-action discovery and Matrix binding lookups can synchronously load persisted state, while queued snapshots can overwrite newer binding changes. Saved-login Matrix accounts retain their actions and capabilities; binding activity and shutdown persistence remain correct with worker-owned storage. * refactor: migrate Reef trust and state to workers Reef trust, registration, audit and replay flows depend on synchronous keyed-state callbacks. Reef persists ordinary state through worker-owned operations while preserving conditional trust decisions and recovery behavior. * fix(matrix): encode targeted binding activity before worker persistence * 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 * test: retain approval replay subscriber across async eligibility * test: implement async listing in ACP binding fixture * test: specify manual Matrix binding removal * test: type Reef flow fixture authority receiver * 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 * refactor: colocate approval expiry observation * refactor(slack): colocate action summary formatting * test: synchronize approval client startup race * refactor: prepare message action discovery asynchronously * refactor(matrix): separate session binding adapter * test: retain async status discovery arguments * test(codex): model current conversation inspection boundary * test(facetime): bind persistence barriers before runtime startup * fix(slack): resolve bound parent before thread fallback * test(reef): use live trust fixture for startup cancellation * test(reef): route trust fixtures through worker-enabled lane * docs: explain validated discussion account config * test: exercise native binding lifecycle through worker settlement * test: document isolated runtime dependencies * test: document isolated runtime dependencies * test: document isolated runtime dependencies * test: document isolated runtime dependencies * test: document isolated runtime dependencies * fix: preserve native binding method receivers * fix: bind model preparation authority to its reader * style: resolve approval runtime lint findings * style: avoid mutating action discovery entries * style: keep Discord route reassignment local * fix(matrix): preserve binding reconciliation error cause * fix(reef): retain peer authority store receiver * chore: regenerate worker and test guard baselines * chore: regenerate worker and test guard baselines * chore: reconcile worker migration baselines * chore: reconcile async approval SDK baselines * chore: record versioned binding SDK surface * chore: prune migrated discovery mocks * chore: prune migrated Matrix binding mock * test: run native row ownership with the host broker * fix: include async approval caller in its migration * fix(plugin-sdk): preserve synchronous approval publication Add an awaited publisher companion while preserving numeric synchronous delivery and legacy publisher objects. Refuse async-only eligibility before legacy delivery and keep rejected preparation observed. Bundled approval dispatch selects the new method before publication. * chore: regenerate approval assertion baseline * fix(clickclack): fence discussion cleanup and reconciliation * test(clickclack): avoid shadowing store options * test(reef): type fixture state authority callbacks
What Problem This Solves
Reef trust, registration, audit and replay flows depend on synchronous keyed-state callbacks.
User Impact
Reef persists ordinary state through worker-owned operations while preserving conditional trust decisions and recovery behavior.
The final native peer-authority lookup remains immediately before delivery effects. Missing keys retain their existing ENOENT contract. This does not change persistent schema, durability or retention policy.
Why This Change Was Made
Migrates Reef state and trust to observe/compare-and-apply operations and propagates async completion through friendship, flow, notices and channel adapters. Cross-row observations prevent delivery or rejection-notice writes after peer revocation, and action authority is rechecked at worker admission.
This is part 9 of the nine-part S7 state/binding migration stack, now targeting main after parent PR merged. The original measurements below compare this part with stack parent
bbcd292f840eon pinned main413d5f9bb3f7; final landing evidence is recorded separately below.Evidence
Changed lines against the parent: production +668 / -548; tests and fixtures +829 / -626.
Focused integrated receipts cover Reef trust revocation/concurrency, state, replay, friendships, and channel flows: 196 passed, 0 skipped, mapped to 12/12 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 49.539s. 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:
ff7b090f43d2d90e4cd883d95840d6b752475a7a1769e295fb4cbb558a6ffb64. Zero released export removals; the digest reconciles to this parent/head through the generated-only baseline change. The canonical SDK diff is empty.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; final landing update proof is recorded below.
Statement gate: original pairs, required whole-workload check and bounded startup diagnostic
The primary series contains three alternating parent/head pairs on the same host; all phase durations are valid. The warmed median rises 1006.8→1021.5 (+1.46%), so unchanged-owner attribution alone was not accepted. The table reports those primary medians and preserves the later ordinary fourth pair and cumulative results.
The first P4 workload completed successfully but initially lacked an aggregation helper. Restoring that existing helper reproduced the same summary hash without rerunning the workload. The controller was later stopped before P6's fifth workload; already completed P4/P5 fifth samples remain separate incidental evidence.
In the exact primary warmed-median samples, total SQL across ten turns is 10068→10215 (+147). Existing memory domain execute/bind/close contributes +90; workspace-lock compare-delete/update/observe contributes +55; memory-open native SQL contributes +10; other reads net −8. The native +10 is precisely two each of BEGIN, ROLLBACK, busy_timeout=0 and sqlite_schema lease checks, plus one memory metadata and one vector-rebuild table lookup. No native SQL or sender stack across all four ordinary pairs intersects a file changed by this part. Positive non-turn primary medians are boot +3 and cron +4, both existing metadata/checkpoint/recovery work within the ten-statement tolerance.
The required ordinary fourth pair records 22226→22247 SQL (+21), 3428→3425 requests (−3) and 56.466→56.530s. It did not clear the SQL total condition. Its exact SQL difference is:
There is no DML increase (timestamp literals were normalized only to compare identical UPDATE shapes). A cold-admission listing appears only in the candidate, while a baseline memory catchup statistics read is absent in the candidate. The queue's recorded sender stack cannot identify that listing's original semantic caller.
After this attribution, one bounded diagnostic pair added identical observational probes to four otherwise byte-identical common modules in separate copies of the same two heads. Both copies were built with the canonical qaRuntime build. The probes retain the pre-queue caller and record catchup branch flags/counts; they add no await, timer, database query or policy change. This is separate instrumented evidence, not pooled into the ordinary medians.
The diagnostic meets the numeric RAW follow-up condition: −16 SQL, −5 requests, valid 1.0100× whole duration, and every phase duration ratio below 1.5. Native execution passed; the outer wrapper's exit 7 was terminal telemetry. Both event streams were complete (29/32 events, zero dropped, no flush warning), and the ordinary harness was restored afterward.
The extra diagnostic listing is restart-aborted main-session recovery, through
runRecovery → runRecoveryRetries → runRecoveryAttempt → recoverRestartAbortedMainSessions → recoverStore → readSessionEntrySummariesInWorker; the other listings are registry maintenance and cron reaping. These owners are unchanged by this PR. Both diagnostic catchup paths remained enabled/open, discovered one eligible SQLite transcript and returned one statistics result.Limits: the earlier absent catchup read did not recur and remains retrospectively unexplained. The diagnostic's extra recovery list occurs in first turn; the old fourth-pair list was in connect. This does not prove the old missing semantic ancestry, a product fix, literal redistribution of every statement, or a steady-state saving. The original positive pair and cumulative medians remain above. Acceptance combines exact changed-path attribution with the qualified lower-total diagnostic; no shipping code was changed to obtain it.
The published-driver × candidate update cell passed on AWS Crabbox: published driver
2026.9.9, candidate4404d37977386531f5a2cf49363887b27b35f69b, runrun_74a21172f5a661e71d4aa52ce00fb12f. The final head differs only by test-fixture type annotations, so the pass is reused under the approved test-only rule. No release, package publication or Plugin SDK major bump is included.Landing investigation: startup catchup
The earlier missing-catchup observation was not reproduced: identical diagnostics on P8 and P9 both issued a one-scope transcript-stat request and returned one result. The equivalent main path performs the same read. This is the memory startup transcript-statistics path, not an omitted Reef trust-state catchup. No receipt substitutes for this read, and the aggregate-count difference is not claimed as a catchup saving. The final integration preserves main’s closing-aware cancellation, buffered-inbox catchup ordering, and current trust revalidation immediately before transport fetch.
Final integration head
4404d37977386531f5a2cf49363887b27b35f69bpreserves main’s newer atomic Reef trust/receipt owners. The remaining registration/replay migration and regression fixtures use the V2 state interface. The final-send revocation regression asserts that no transport fetch occurs.Final landing proof
AWS Crabbox run
run_74a21172f5a661e71d4aa52ce00fb12fpassed all 513 selected tests across Reef and memory startup catchup (two shards, 333.68 seconds), then passed the published-driver update cell. The final heade2b707defce831fb8f2979e4327d3cfe7e918eb7adds only explicit optional authority types to five test-fixture callbacks after CI reported TS7006; the scoped P0/P1 review is clean. Production behavior and test assertions are unchanged.Final-head extension test typecheck passed on AWS Crabbox (
pnpm tsgo:extensions:test, runrun_9a02a7d707dc0a809a06b560bc90788b, 35.323s command). This closes the five TS7006 fixture errors observed on the integration head.