Repository navigation
feat(plugin-sdk): add worker-owned keyed state - #168478
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.
|
🦞👀 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 real behavior proof before merge. What this changesAdds lifecycle-bound V2 keyed-state stores and migrates bundled consumers while preserving released legacy APIs. Example: A plugin increments the stored counter "counter" from 7 to 8.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep this maintainer-directed PR open: it provides a distinct worker-owned SDK capability, and the earlier correctness findings remain repaired. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherPlugin runtime factories bind plugin identity and current authority to keyed-state operations; the shared SQLite worker commits mutations and publishes their results back to callers. flowchart LR
Plugin[Plugin caller] --> Runtime[Runtime V2 factory]
Runtime --> Authority[Runtime and action authority]
Authority --> Worker[Shared state worker]
Worker --> SQLite[Plugin state SQLite]
SQLite --> Facts[Committed facts]
Facts --> Plugin
Technical reviewBest possible solution: Complete the V2 cutover through the existing worker owner while retaining released completion contracts and validating existing-state upgrades. Do we have a high-confidence way to reproduce the issue? Source confirms that legacy awaited update/deleteIf methods invoke synchronous native callbacks; no target code or tests were executed during this review. Is this the best way to solve the issue? The versioned data-only store reuses the existing worker and comparison owners, preserves legacy contracts, and avoids replaying failed worker operations through synchronous storage. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7e23f938f805. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: Source contains final-effect authority checks, but their denial behavior remains unverified. EvidenceWhat I checked:
Likely related people:
PR surfacePR surface statistics unavailable: the file list is incomplete. LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed October 10, 2026, 3:46 PM ET / 19:46 UTC (Revision 6). |
|
Landing stopped at this first PR; no branch updates or merges were performed. The completed ClawSweeper review of
Source inspection confirms that Exact-head CI also confirms a separate production regression: run 38059495815, job 114234998635, Other failures remain unqualified, not waived: the Zalouser Doctor case reaches an unconfigured V2 store mock; the iMessage current-message integration has modern and legacy-path failures; memory cold-rebuild reports The published-driver × candidate update cell remains pending. It was not run against a head blocked on production repair. No remote lease was allocated. Later stack PRs were not retargeted or modified; the final Reef catchup-read question remains pending before its eventual landing. |
|
Fixed the two confirmed ClickClack lifecycle races in Binding cleanup and metadata reconciliation now use the worker's atomic comparison against their captured owner. Cleanup cannot delete or replace a successor, and a late metadata response leaves the replacement attachment unchanged. A subsequent reconciliation applies the replacement session's metadata. The repair also covers a successor that keeps the same channel: cleanup revocations carry their captured binding, and conditional writes preserve newer revocation evidence. Legacy and quarantine tombstones remain unconditional. This preserves revoke-before-delete crash ordering without disabling a successor. New-channel publication requires the binding to remain absent; an obsolete remote candidate stays quarantined. The deterministic regressions hold revocation, deletion, and final publication and install successors on the same or a different channel. The late-reconciliation test holds the remote response while the session attachment is replaced. No sleeps were added. An additional boundary test preserves unconditional quarantine precedence. Validation ran on one remote AWS lease after Testbox did not assign a runner, under the campaign remote lease gate. The exact CI failure from run 38059495815 / job 114234998635 was reproduced on pristine The repaired source passed 204 tests across 13 files, including the worker prepared-state suite and ClickClack lifecycle, persistence, inbound routing, retention, registration, and tool-policy suites. All used the repository runner with
These are remote proof measurements; new GitHub CI seconds are not yet measured. Cold worker preparation accounts for much of the command wall time. Before/after file hashes matched the reviewed repair. Final independent review is clean for actionable P0/P1 findings. The native
The fixture's Repair delta: production +229/−56 lines, tests/support +294/−56, documentation +13. No released SDK export, SQLite schema, dependency, lockfile, or generated-baseline changes. The original stack's SQL and SDK evidence remains prior-head evidence; this bounded race repair did not rerun the full statement workload or SDK measurement. Propagated through all eight later stack branches with clean merges and verified identical ClickClack source. No main integration or unrelated fixes were added.
The update cell remains pending (lander). No PRs merged. Stopping here for the stack lander to resume. |
|
Landing repair at
Focused proof: |
|
Stopping this stack at #168478, current head The V2 fixture cutover and FaceTime observer-order repairs passed independent P0/P1 review and all 13 focused tests across three files. Current-head CI still fails in job 114263711619, run 38069343924:
That test and its runtime implementation are unchanged by this PR. A verified isolated run on main baseline The published-driver The final Reef catchup-read gate has not been cleared; it still must be resolved before #168486 can land. |
Restore the immediate initial read for ordinary host-owned sessions so the existing admission check rejects replacements made while work is queued. Keep bound incognito reads asynchronous and retain the existing session-replacement regression.
# Conflicts: # src/plugin-sdk/plugin-state-test-runtime.ts # src/plugin-state/plugin-state-store.comparison.ts # src/plugin-state/plugin-state-store.ts # src/plugin-state/plugin-state-store.types.ts # src/plugins/registry-runtime.ts
|
Landing proof for The published |
|
Merged via squash.
|
* 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. * test: complete keyed state runtime fixture * refactor(plugin-state): separate offline migration entrypoints * test(facetime): bind persistence barriers before runtime startup * docs: explain validated discussion account config * fix(clickclack): fence discussion cleanup and reconciliation * test(clickclack): avoid shadowing store options * test(plugins): migrate integration fixtures to worker state * test(facetime): observe deletion before runtime captures store methods * fix(plugins): capture native session identity before admission awaits Restore the immediate initial read for ordinary host-owned sessions so the existing admission check rejects replacements made while work is queued. Keep bound incognito reads asynchronous and retain the existing session-replacement regression.
What Problem This Solves
Plugin state callbacks can perform SQLite work on the Gateway thread, including APIs that return a Promise.
User Impact
Plugin authors gain a versioned worker-owned keyed store; existing synchronous and callback APIs keep their completion semantics through the current Plugin SDK major.
Legacy forms warn on actual use and name their replacement and removal in the next Plugin SDK major. FaceTime retains its declared >=2026.9.4 support by selecting the available API before any operation; it never retries a failed V2 operation through native storage. Final synchronous authority guards remain until the later guard cutover. CAS compares observed contents and timestamps; it does not claim monotonic incarnation or equal-byte ABA protection.
Why This Change Was Made
Adds
api.runtime.state.openKeyedStoreV2and the matching SDK factory, using the existing worker store and observe/compare-and-apply operations. Runtime stores capture plugin identity and lifetime. Bundled state consumers migrate together, including ClickClack, iMessage, Signal, FaceTime, Zalouser and core caches. All deprecations reuse the shared warning owner.This is part 1 of the nine-part S7 state/binding migration stack. Targets
main; validation compares this part with its actual stack parent413d5f9bb3f7. The stack integrates pinned main413d5f9bb3f7.Known follow-up: a released synchronous SDK writer can replace a ClickClack binding while old-room revocation awaits; cleanup can then delete the successor association. Ordinary same-service callers are serialized and remote room data remains intact. A follow-up should condition cleanup on the expected room identity.
Evidence
Changed lines against the parent: production +809 / -592; tests and fixtures +786 / -503.
Focused integrated receipts cover keyed-state worker operations, released SDK compatibility, runtime factories, and bundled persistence: 468 passed, 3 skipped, mapped to 33/33 changed test files. The shared released fixture includes one publisher case added in part 5; this prefix originally had three fixture cases. 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 135.675s. 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:
da8e6642534379647d22726554472fb7a09502b89d32731468780857f2cf5e40. Zero released export removals; the digest reconciles to this parent/head through the generated-only baseline change. Compatible keyed-state additions retain the released callback forms.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
Accepted for
413d5f9bb3f7 → 5915284db816. Same synthetic workload, ten warmed turns per run; three original alternating pairs followed by two extra pairs. All five pairs are retained. 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 2587→2605 and warmed increase 1006.4→1006.9 triggered RAW TURN follow-up. Extra4 remained +72 whole SQL/+17 requests; extra5 remained +112/+3. The cumulative five-pair first/warmed increases are +213/+2.8, with whole workload +112/+3. None of those positive results is discarded or described as a saving.
Exact changed-function attribution found six SQL/stack signatures across the 48 changed production TypeScript paths, all through
observePluginStateEntryandcompareAndApplyPluginStateEntry. The former is byte-identical; the latter differs only by the new optional conditions loop, which this workload never executes. Async keyed-store observe/entries, quarantine-list functions and the memory provenance read are also byte-identical. Request/SQL counts for the relevant plugin-state operations are:observecompareUpdatecompareDeleteentriessweepCells are whole-workload requests / SQL. Extra4 contains two additional first-turn memory workspace-lock cycles (+56 SQL), from one additional indexed source's embedding-cache persistence and chunk writes; these producing functions are unchanged. This identifies the extra work, not why that source was scheduled. Warmed observe/update/delete counts match within every original pair; entries shift between phases while whole-workload totals remain equal. No extra5 SQL/request stack reaches the new provenance write/clear, synchronous warning or runtime-health-clear paths.
Separate diagnostic6 RAW follow-up: both sides use the same additional diagnostic instrumentation; it is not pooled into the original five pairs. Whole SQL 22515→22325, requests 3476→3442, and wall 67.645→67.402 s satisfy the recorded follow-up condition. First-turn SQL is 2553→2418 and warmed SQL 1059.3→1030.1. This is not a product performance improvement: lower totals include omitted existing startup cleanup/recovery work.
The head captures a missing database before awaiting writer admission, then sees the newly created file and rejects cleanup with
SQLite lifecycle cleanup database owner changed; the base retains an existing file identity and completes cleanup. The base also discovers a newly created empty database and performs restart-recovery listing; the head has no corresponding recovery frames or list. The leaf-only observer does not identify the exact parent-directory guard behind that omission. These owners are byte-identical. The retry lies outside the workload window. Diagnostic6 demonstrates that mechanism, but the lost extra5 warning prevents assigning the same exact exception to extra5. The unchanged cleanup/admission race remains an explicit follow-up outside this change; the remaining whole-workload delta is not wholly attributed to those three startup operations. Diagnostic plugin-state counts andsource.replace(1 request / 21 SQL per side) are equal.Separate diagnostic6 phase values (not pooled)
The published-driver × candidate update cell is pending (lander). No release, package publication or Plugin SDK major bump is included.