Skip to content

chore: migrate persistence to async SQLDelight on JS [WPB-23964]#3982

Open
Garzas wants to merge 8 commits into
developfrom
chore/sqldelight-js-async-migration
Open

chore: migrate persistence to async SQLDelight on JS [WPB-23964]#3982
Garzas wants to merge 8 commits into
developfrom
chore/sqldelight-js-async-migration

Conversation

@Garzas
Copy link
Copy Markdown
Contributor

@Garzas Garzas commented Mar 19, 2026

https://wearezeta.atlassian.net/browse/WPB-23964


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

Issues

  • Kalium JS persistence was using SQLDelight’s official web-worker-driver, but the persistence layer still assumed synchronous generated SQLDelight APIs.
  • This caused runtime failures on Kotlin/JS with the async driver, including IllegalStateException: The driver used with SQLDelight is asynchronous, so SQLDelight should be configured for asynchronous usage.
  • Enabling generateAsync = true for Kalium databases caused broad compile fallout because DAO, bootstrap, paging, migration, and helper code still depended on synchronous query access patterns.
  • Some JS persistence tests exposed SQL.js/runtime differences around boolean mapping, empty query results, schema initialization, migration verification, and duplicate insert handling.
  • JS persistence still does not support file/path-backed database operations used by backup/nuke flows, so those tests could not run meaningfully on JS.

Causes (Optional)

  • SQLDelight’s worker-based JS driver is asynchronous and returns async query results, while Kalium persistence helpers and generated-query call sites were written around synchronous SQLDelight behavior.
  • SQLDelight’s paging helper still relies on synchronous query execution, which is not compatible with async-generated JS queries.
  • Some common DB bootstrap and migration helpers were typed around synchronous schema/query abstractions, which made them incompatible with JS async generation.
  • SQL.js returns SQLite primitive values directly, including 0/1 for boolean-like columns, while generated Kotlin models expect booleans for selected fields.
  • Native targets still rely on synchronous drivers, so the migration needed to preserve JVM/Android/iOS behavior without introducing JS-only branching across the common persistence API.

Solutions

  • Enabled SQLDelight async generation for both UserDatabase and GlobalDatabase in data:persistence.
  • Migrated affected persistence code to async-compatible SQLDelight access by replacing synchronous generated-query usage with async/suspending equivalents and propagating suspend where required through DAOs, repositories, helpers, and affected tests.
  • Added an async-compatible paging source for Kalium query paging paths that cannot use SQLDelight’s synchronous paging helper with the JS async driver.
  • Updated database bootstrap and migration code to use async-compatible schema and FK-check paths, while keeping native targets working through synchronous schema/driver adaptation.
  • Kept the official SQLDelight JS worker-driver approach and added Kalium-specific JS worker setup for Node-based tests, including result normalization for boolean columns, empty query results, affected row counts, and SELECT EXISTS.
  • Made legacy migration cleanup more idempotent by using DROP VIEW IF EXISTS where needed.
  • Added a Kalium-side JS smoke test that opens the DB, performs a write, performs a read, and validates that the async-driver exception does not occur.
  • Marked backup/nuke persistence tests as ignored on JS because the current JS implementation does not provide file/path-backed DB operations required by those flows.
  • Added TODO markers to the current JS-only file-management stubs (nuke, DB path, empty file creation) so the remaining non-native parity gaps are explicit.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

Test Results

0 tests   - 4 911   0 ✅  - 4 796   0s ⏱️ - 3m 6s
0 suites  -   806   0 💤  -   115 
0 files    -   806   0 ❌ ±    0 

Results for commit a9bfb4f. ± Comparison against base commit 86391e2.

♻️ This comment has been updated with latest results.

@Garzas Garzas changed the title chore: migrate persistence to async SQLDelight on JS chore: migrate persistence to async SQLDelight on JS [WPB-23964] Apr 3, 2026
@datadog-wireapp
Copy link
Copy Markdown

datadog-wireapp Bot commented Apr 3, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: d3bde34 | Docs | Was this helpful? Give us feedback!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2026

🐰 Bencher Report

Branchchore/sqldelight-js-async-migration
Testbedubuntu-latest

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymicroseconds (µs)
com.wire.kalium.benchmarks.logic.CoreLogicBenchmark.createObjectInFiles📈 view plot
⚠️ NO THRESHOLD
925.43 µs
com.wire.kalium.benchmarks.logic.CoreLogicBenchmark.createObjectInMemory📈 view plot
⚠️ NO THRESHOLD
481,103.39 µs
com.wire.kalium.benchmarks.persistence.MessageReadBenchmark.inboxPagingDeepPageBenchmark📈 view plot
⚠️ NO THRESHOLD
129,072.55 µs
com.wire.kalium.benchmarks.persistence.MessageReadBenchmark.inboxPagingFirstPageBenchmark📈 view plot
⚠️ NO THRESHOLD
126,261.98 µs
com.wire.kalium.benchmarks.persistence.MessageReadBenchmark.localMarkAsReadBenchmark📈 view plot
⚠️ NO THRESHOLD
3,435.53 µs
com.wire.kalium.benchmarks.persistence.MessageReadBenchmark.messagePagingDeepPageBenchmark📈 view plot
⚠️ NO THRESHOLD
29,917.63 µs
com.wire.kalium.benchmarks.persistence.MessageReadBenchmark.messagePagingFirstPageBenchmark📈 view plot
⚠️ NO THRESHOLD
13,908.55 µs
com.wire.kalium.benchmarks.persistence.MessagesNoPragmaTuneBenchmark.messageInsertionBenchmark📈 view plot
⚠️ NO THRESHOLD
1,238,734.17 µs
com.wire.kalium.benchmarks.persistence.MessagesNoPragmaTuneBenchmark.queryMessagesBenchmark📈 view plot
⚠️ NO THRESHOLD
20,622.17 µs
🐰 View full continuous benchmarking report in Bencher

@sonarqubecloud
Copy link
Copy Markdown

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 4, 2026

Codecov Report

❌ Patch coverage is 62.50000% with 93 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.61%. Comparing base (86391e2) to head (a9bfb4f).

Files with missing lines Patch % Lines
.../persistence/dao/message/AsyncQueryPagingSource.kt 65.11% 9 Missing and 6 partials ⚠️
...ersistence/dao/conversation/ConversationDAOImpl.kt 63.63% 8 Missing and 4 partials ⚠️
...lin/com/wire/kalium/persistence/dao/UserDAOImpl.kt 35.29% 7 Missing and 4 partials ⚠️
...e/kalium/persistence/dao/message/MessageDAOImpl.kt 69.23% 7 Missing and 1 partial ⚠️
...om/wire/kalium/persistence/dao/member/MemberDAO.kt 36.36% 4 Missing and 3 partials ⚠️
.../kalium/persistence/dao/backup/NomadMessagesDAO.kt 45.45% 1 Missing and 5 partials ⚠️
...om/wire/kalium/persistence/dao/call/CallDAOImpl.kt 0.00% 4 Missing ⚠️
...wire/kalium/persistence/daokaliumdb/AccountsDAO.kt 69.23% 3 Missing and 1 partial ⚠️
.../persistence/daokaliumdb/ServerConfigurationDAO.kt 50.00% 4 Missing ⚠️
...ire/kalium/persistence/dao/client/ClientDAOImpl.kt 75.00% 3 Missing ⚠️
... and 12 more
Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3982      +/-   ##
=============================================
+ Coverage      61.55%   61.61%   +0.05%     
+ Complexity      4022     3986      -36     
=============================================
  Files           2068     2069       +1     
  Lines          67436    67698     +262     
  Branches        6651     6674      +23     
=============================================
+ Hits           41513    41709     +196     
- Misses         23277    23317      +40     
- Partials        2646     2672      +26     
Files with missing lines Coverage Δ
...n/kotlin/com/wire/kalium/persistence/dao/AppDAO.kt 100.00% <100.00%> (ø)
...otlin/com/wire/kalium/persistence/dao/SearchDAO.kt 100.00% <100.00%> (ø)
...tlin/com/wire/kalium/persistence/dao/ServiceDAO.kt 68.85% <100.00%> (ø)
...istence/dao/conversation/ConversationExtensions.kt 89.09% <100.00%> (ø)
...o/conversation/folder/ConversationFolderDAOImpl.kt 77.77% <100.00%> (ø)
.../wire/kalium/persistence/dao/event/EventDAOImpl.kt 91.11% <100.00%> (ø)
...ium/persistence/dao/message/CompositeMessageDAO.kt 100.00% <100.00%> (ø)
...lium/persistence/dao/message/MessageMetadataDAO.kt 100.00% <100.00%> (ø)
...rsistence/dao/message/draft/MessageDraftDAOImpl.kt 97.43% <100.00%> (ø)
...lium/persistence/dao/newclient/NewClientDAOImpl.kt 96.87% <100.00%> (-3.13%) ⬇️
... and 28 more

... and 41 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86391e2...a9bfb4f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Garzas Garzas force-pushed the chore/sqldelight-js-async-migration branch from c130456 to f26f7a8 Compare May 12, 2026 09:23
@Garzas Garzas marked this pull request as ready for review May 12, 2026 12:49
@Garzas Garzas requested review from saleniuk and yamilmedina May 13, 2026 05:45
@Garzas Garzas force-pushed the chore/sqldelight-js-async-migration branch from 3dddedd to a9bfb4f Compare May 14, 2026 05:17
@Garzas Garzas requested a review from a team as a code owner May 14, 2026 05:17
@Garzas Garzas requested review from alexandreferris and ohassine and removed request for a team May 14, 2026 05:17
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants