Conversation
Introduce a tab message channel (InitTab) and typed EvoluTabOutput to carry ConsoleEntry and EvoluError messages between the worker and the UI. createEvoluDeps now creates and exposes a read-only evoluError store, wires tab channel outputs into console logging and the evoluError store (including fallback wrapping for untyped console.error entries), and returns a disposable deps object that disposes used resources. The worker init was updated to queue and broadcast EvoluTabOutput values, and EvoluWorker/Worker input types were adjusted accordingly. Tests and a minimal playground example were updated to reflect the new InitTab flow and to assert evoluError behavior. Also removed the now-unused DisposableStackDep/AsyncDisposableStackDep interfaces from Types.ts.
Added a reusable microtask batching helper for coalescing queued items per tick. Added focused tests for coalescing, flushNow behavior, and reentrant pushes. Exported the new utility from common index.
Added a reusable reference counting helper for arbitrary keys. Added focused tests for increment/decrement behavior, key snapshots, clear, and object identity semantics. Exported the new utility from common index.
Added Evolu-to-worker mutation input contract and worker-side message handling scaffold. Implemented mutation dispatch flow in createEvolu with microtask batching and serialized mutate payloads. Expanded local-first mutation tests for insert/update/upsert dispatch, coalescing, ownerId, and onComplete callback IDs. Updated React web createEvoluDeps doc wording to match shared dependency semantics.
Added a reusable prompt that guides commit batching workflow with explicit approval gates for batch selection and commit message confirmation.
Added testCreateWorker in common worker abstractions and added coverage in the worker test suite for dedicated worker communication, message queueing, and disposal behavior.
Added DB worker dependency wiring to local-first core by introducing CreateDbWorker/DbWorkerInput types, invoking createDbWorker() in createEvolu, and sending { type: "init", name } to the DB worker. Updated local-first tests to provide a test DB worker and assert init messaging.
Updated web and React Native platform deps to provide createDbWorker, switched web shared-worker entry path to Shared.worker.js, renamed Worker.worker.ts to Shared.worker.ts, and added Db.worker.ts with TODO notes for DB-worker heartbeat based stale-leader detection and failover via SharedWorker.
Added cross-platform LeaderLock abstraction and dependency in common platform types. Introduced shared worker init deps (WorkerInitDep, WorkerDeps) and reused them in worker init tasks. Wired DB worker initialization to acquire leader lock before activation. Implemented web leaderLock and switched web worker entrypoints to createRun(createWorkerDeps()). Added React Native leaderLock, exported it, and wired RN shared deps to run initDbWorker/initSharedWorker with worker-side deps.
Added testName next to Name in common type definitions. Added testAppName next to AppName in local-first Evolu module. Established canonical source exports for shared test identifiers.
Renamed test helper module from _deps.nodejs.ts to _deps.ts. Updated common test imports to use the renamed module path. Switched shared test name/app name usage to canonical source exports. Removed stale _deps references from local-first test comments.
Added leaderLock tests for React Native platform behavior. Verified lock acquisition waits for prior lease disposal for same name. Verified independent lock acquisition for different names. Reused shared testName constant from @evolu/common.
Added browser-mode integration tests for web leaderLock behavior. Covers same-name serialization and different-name independent acquisition. Uses shared testName constant for stable lock naming.
Removed native console output from web createWorkerDeps. Kept console output routed through consoleStoreOutput only. Avoids duplicate logs when worker output is forwarded via shared worker.
Change the Run interface so the daemon property is typed as Run<D> rather than a function signature, and update createRunInternal to assign run.daemon = daemon ?? self instead of wrapping it in a lambda. This aligns the runtime assignment with the new type, removes an unnecessary closure, and resolves related typing mismatches.
Added deterministic test value exports to Test.ts (testEntropy32, testOwnerSecret, testAppOwner). Kept eager test values in the test utility module to avoid affecting runtime tree-shaking paths. Documented the rationale near the exports and placed them at the end of the file.
Configured the minimal playground to pass appOwner: Evolu.testAppOwner to createEvolu. Keeps owner identity stable across reloads for deterministic local behavior. Reuses shared test utility owner instead of ad-hoc inline owner creation.
Updated initDbWorker to return and manage AsyncDisposableStack directly without await using/move. Switched leader lock acquisition to run.daemon(...) and reused leaderLock from deps. Extracted initialization work into initializeDb(name) task and moved logging/TODO heartbeat note there.
Typed NativeMessagePort with input and output phantom types to make port transfer wiring type-safe across platforms. Updated platform worker adapters to preserve these types at boundaries.
Renamed init ports to port1 and port2, replaced broker naming with leader semantics, and scoped Evolu channel wiring for readability. Updated Db/Shared contracts and tests to match the clearer message flow.
Documented that Evolu instance communication is routed through SharedWorker as the central point for observability and resilience mechanisms such as retry and timeout.
Removed WorkerInitDep in favor of a single WorkerDeps contract, wired DbWorker console store output through the leader channel, and updated SharedWorker handling/tests to forward DbWorker console entries to tab outputs.
Added full DbWorker init inputs (consoleLevel, dbSchema, encryptionKey) and wired them from createEvolu through worker channels. Unified leader output typing with EvoluTabOutput, added typed EvoluError forwarding, and updated SharedWorker InitTab to receive/apply consoleLevel. Updated schema conversion typing to avoid external casts, wired sqlite driver in web Db worker run deps, and aligned SharedWorker tests with the new InitTab contract.
Updated React Native shared dependency creation to require and pass CreateSqliteDriverDep into worker runtime deps. Updated the Expo SQLite export to provide createExpoSqliteDriver when creating Evolu deps.
…storage boundaries - Removed SqliteError from SQLite public APIs and switched infra failure handling to throws - Kept Result for domain/protocol outcomes and mapped boundary failures to protocol-level errors - Added Sqlite.transaction overload for callbacks returning Result<T, E> or void - Simplified storage/query/schema/sync call sites and updated relay/client boundary behavior - Updated docs/changeset and tests across common, nodejs, and web to match new semantics - Follow-up cleanup removed redundant Result<void> leftovers in storage helpers (cherry picked from commit f94006d)
Add getOk to Result utilities to safely extract values from Result<T, never> with an assertion guard. Add tests covering getOk success path, type-level constraints, and runtime invariant violation. Include getOrNull tests to keep Result extraction helpers consistently covered. (cherry picked from commit b9fcb47)
Replace manual Result unwrapping with getOk in DB and relay SQLite initialization paths. Simplify dependent code by working with unwrapped sqlite values directly. Update shared test deps helper to align with the same unwrapping pattern. (cherry picked from commit af2e3f6)
…er and sync operations, and update dependencies.
(cherry picked from commit db759d4)
Removed WorkerInitDep in favor of a single WorkerDeps contract, wired DbWorker console store output through the leader channel, and updated SharedWorker handling/tests to forward DbWorker console entries to tab outputs. (cherry picked from commit 0bbef0a)
Added full DbWorker init inputs (consoleLevel, dbSchema, encryptionKey) and wired them from createEvolu through worker channels. Unified leader output typing with EvoluTabOutput, added typed EvoluError forwarding, and updated SharedWorker InitTab to receive/apply consoleLevel. Updated schema conversion typing to avoid external casts, wired sqlite driver in web Db worker run deps, and aligned SharedWorker tests with the new InitTab contract. (cherry picked from commit 57d2390)
📝 WalkthroughWalkthroughThis pull request implements a comprehensive refactoring to remove Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
Note 🎁 Summarized by CodeRabbit FreeThe PR author is not assigned a seat. To perform a comprehensive line-by-line review, please assign a seat to the pull request author through the subscription management page by visiting https://app.coderabbit.ai/login. Comment |
There was a problem hiding this comment.
Pull request overview
This PR performs a strict parity alignment pass against upstream/common-v8 for the local-first worker/DB orchestration flow, while preserving the fork’s Bun-first + Biome-first constraints and keeping fork-only protocol surface behind Experimental* aliases.
Changes:
- Refactors SQLite + storage APIs to “throw-first” semantics (removing
SqliteErrorfrom most result channels) and updates call sites/tests accordingly. - Introduces/aligns worker orchestration pieces (
Shared.ts, worker console forwarding, typedNativeMessagePortgenerics) and expands worker-related test utilities/coverage. - Adjusts public exports to preserve upstream
Dbexports while movingDbWorkerProtocolsurface behindExperimental*aliases; updates dependents and lock/config/docs.
Reviewed changes
Copilot reviewed 47 out of 48 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/web/test/Sqlite.test.ts | Updates tests for new throw-first SQLite exec/export return shapes. |
| packages/web/test/DbWorker.test.ts | Switches to ExperimentalDbWorker* protocol type aliases. |
| packages/web/src/local-first/Worker.worker.ts | Updates web worker bootstrap to use createWorkerRun + injected runDbWorkerPort. |
| packages/web/src/local-first/DbWorker.ts | Aligns web DB worker wiring with experimental protocol + console level plumb-through. |
| packages/web/src/Worker.ts | Tightens NativeMessagePort generic typing in wrapper. |
| packages/react-native/src/shared.ts | Requires createSqliteDriver dep for RN createEvoluDeps. |
| packages/react-native/src/exports/expo-sqlite.ts | Wires Expo sqlite driver into deps creation. |
| packages/react-native/src/exports/bare-op-sqlite.ts | Wires op-sqlite driver into deps creation. |
| packages/react-native/src/Worker.ts | Tightens NativeMessagePort generic typing in RN worker shims. |
| packages/nodejs/test/Sqlite.test.ts | Updates tests for new throw-first SQLite exec/export return shapes. |
| packages/nodejs/src/local-first/Relay.ts | Updates relay startup/storage init for throw-first SQLite and getOk usage. |
| packages/nodejs/src/Worker.ts | Tightens NativeMessagePort generic typing in wrapper. |
| packages/common/test/local-first/_utils.ts | Updates schema + exec handling for throw-first SQLite results. |
| packages/common/test/local-first/Worker.test.ts | Expands worker tests for console forwarding + updated InitTab/InitEvolu wiring. |
| packages/common/test/local-first/Storage.test.ts | Updates storage tests for new return types and simplified storage config. |
| packages/common/test/local-first/Shared.test.ts | Adds comprehensive tests for new initSharedWorker behavior. |
| packages/common/test/local-first/Schema.test.ts | Updates schema tests for new return types (getDbSchema, ensureDbSchema). |
| packages/common/test/local-first/Relay.test.ts | Updates relay storage tests for throw-first SQLite results and void-return APIs. |
| packages/common/test/local-first/Protocol.test.ts | Updates protocol tests for console dep and non-nullable joins. |
| packages/common/test/local-first/Evolu.test.ts | Adds mutation queue serialization test + updates InitEvolu channel payload. |
| packages/common/test/_deps.ts | Consolidates common test deps helpers (sqlite + relay storage) into one module. |
| packages/common/test/_deps.nodejs.ts | Keeps backward-compatible re-export shim to _deps.ts. |
| packages/common/test/Worker.test.ts | Adds tests for new in-memory worker/message channel test utilities. |
| packages/common/test/Sqlite.test.ts | Refactors transaction/export tests for throw-first semantics. |
| packages/common/test/Result.test.ts | Adds tests for new getOk and getOrNull. |
| packages/common/src/local-first/index.ts | Re-exports shared worker module and introduces ExperimentalDbWorker* aliases. |
| packages/common/src/local-first/Worker.ts | Adds console level plumbing + console store forwarding to tabs. |
| packages/common/src/local-first/Sync.ts | Refactors sync/storage flow to throw-first SQLite with explicit boundary handling. |
| packages/common/src/local-first/Storage.ts | Converts many storage ops from Result/null to throw/void and adjusts API contracts. |
| packages/common/src/local-first/Shared.ts | Adds platform-agnostic SharedWorker orchestration with mutation queue + retry/ack. |
| packages/common/src/local-first/Schema.ts | Converts schema helpers to throw-first, improves typing for schema validation. |
| packages/common/src/local-first/Relay.ts | Refactors relay sqlite storage to throw-first base storage and simplified error surface. |
| packages/common/src/local-first/Query.ts | Refactors query loading to return values directly (no Result). |
| packages/common/src/local-first/Protocol.ts | Adds console dep and guards around throw-capable storage operations. |
| packages/common/src/local-first/Evolu.ts | Updates worker init payload (console level, ports) + mutation queue serialization. |
| packages/common/src/local-first/Error.ts | Removes SqliteError from EvoluError union. |
| packages/common/src/local-first/Db.ts | Adds upstream-parity DB worker definitions and bootstrap/init flow. |
| packages/common/src/Worker.ts | Adds typed NativeMessagePort generics + in-memory worker/message test utilities. |
| packages/common/src/Type.ts | Adds deprecated Name alias for upstream parity. |
| packages/common/src/Sqlite.ts | Implements throw-first exec/export and overload-based transaction API. |
| packages/common/src/Result.ts | Adds getOk helper and updates docs/examples accordingly. |
| packages/bun/test/BunDbWorker.test.ts | Switches Bun DB worker tests to experimental protocol type aliases. |
| packages/bun/src/BunDbWorker.ts | Switches Bun DB worker implementation to experimental protocol type aliases. |
| bun.lock | Updates pinned tooling versions (Biome, Turbo, etc.). |
| biome.json | Updates schema version and promotes noImportCycles rule configuration. |
| .changeset/sqlite-refactor.md | Documents major SQLite API refactor and boundary handling rationale. |
| .ai/memory/user-preferences.md | Updates parity sync rules documentation. |
| .ai/knowledge/common-v8-parity-plan-2026-02-16.md | Adds parity tracking plan and status matrix snapshot. |
No changes needed - circular dependency already resolved
Summary
packages/common/src/local-first/Db.tsandpackages/common/src/local-first/Shared.tswith upstreamcommon-v8worker orchestration flowbun,biome) and avoid reintroducing pnpm/eslint/prettierExperimental*aliases while preserving upstreamDbexportsmerge -s ours upstream/common-v8) so next sync wave has explicit merge base.ai/knowledge/common-v8-parity-plan-2026-02-16.md)Validation
bun run verify:fastbunx vitest run packages/common/test/local-first/Shared.test.ts packages/common/test/local-first/Worker.test.ts packages/common/test/local-first/Evolu.test.tsbunx vitest run packages/web/test/DbWorker.test.tsbun test ./packages/bun/test/BunDbWorker.test.tsNotes
packages/common/src/local-first/Evolu.tsruntime queue path (Bun-first directDbWorkerClientqueue), API-compatible with upstreamcommon-v8.Summary by CodeRabbit
New Features
API Changes
Bug Fixes
Tests