Skip to content

fix: the participant row is written without SQLite 3.24 - #502

Merged
an1ndra merged 2 commits into
Developfrom
fix/participant-upsert-sqlite
Nov 19, 2026
Merged

an1ndra merged 2 commits into
Developfrom
fix/participant-upsert-sqlite

Conversation

@an1ndra

@an1ndra an1ndra commented Nov 19, 2026

Copy link
Copy Markdown
Owner

What was wrong

upsertParticipant wrote its row with INSERT … ON CONFLICT(…) DO UPDATE. That syntax arrived in SQLite 3.24, and Android 10 — the app's minimum SDK — ships 3.22, where the statement is a syntax error.

Every path that touches a person went through it: the startup migration, syncFromSystem(), and creating a conversation. The visible symptom on a fresh install of Develop on Android 10:

  • The inbox opens empty while the system still holds the messages — RepoSync: syncFromSystem failed: android.database.sqlite.SQLiteException: near "ON": syntax error, and no conversation is ever created. That is the "blank screen".
  • When the startup migration has conversations to walk, the same error is thrown from a coroutine and takes the whole process down before any screen exists.

The fix

The write is now an UPDATE, then an INSERT when nothing matched, with the unique-constraint race caught and retried as an UPDATE. No statement needs anything newer than the platform's own SQLite. Every column the old upsert kept is still written (normalized, send and display forms, comparable form, country code, sub id), and a non-phone sender still gets no participant row.

Proof

Before, on the standing Android 10 AVD, after pm clear:

E RepoSync: syncFromSystem failed: android.database.sqlite.SQLiteException: near "ON": syntax error
   ... INSERT INTO participants(...) VALUES(?,?,?,?,?,?) ON CONFLICT(normalized_destination) DO UPDATE SET ...
conversations in db: 0      (the provider held messages; none was imported)
inbox: "Messages" / "Start chat" — empty

After, same clear and launch:

conversations in db: 12     (imported from the system provider)
import errors: 0
inbox rows: 12              (visible in the uiautomator dump)

scripts/test-participant-upsert.sh (8 checks) — with the migration flag cleared and the table empty, the app launches, the table fills, a number stored without its + is normalised to E.164, the display form is written, no crash report is produced, and the pass marks itself done. Red on the pre-fix build (the app never came up), green after.

JUnit: ParticipantUpsertTest (3 tests) — no upsert syntax anywhere in the repository, the update-then-insert shape, every column, the concurrent-writer retry, and the migration's own flag.

Full unit suite: ./gradlew testDebugUnitTest → 1642 tests, 0 failures.

Notes

  • DB_VERSION / DB_NAME stay internal rather than private: the newer-database compatibility check reads them from another file.
  • No schema change: this is the same table and the same columns, only written in a way Android 10 can parse.
  • scripts submodule bumped to Messages-scripts Develop (9698429, pushed there first).

upsertParticipant wrote its row with INSERT ... ON CONFLICT DO UPDATE. That
syntax arrived in SQLite 3.24 and Android 10 — the app's minimum — ships 3.22,
where the statement is a syntax error. Every path that touches a person went
through it: the startup migration, syncFromSystem, and creating a conversation.

The visible symptom was a blank inbox: the import threw on the first new number,
syncFromSystem logged its failure and no conversation was ever created, so a
fresh install on Android 10 showed an empty app while the system still held the
messages. The startup migration threw the same error from a coroutine, which
took the whole process down.

The write is now an UPDATE, then an INSERT when nothing matched, with the
unique-constraint race caught and retried as an UPDATE. No statement needs
anything newer than the platform's own SQLite, every column the old upsert kept
is still written, and a non-phone sender still gets no participant row.
@an1ndra
an1ndra merged commit 03e4867 into Develop Nov 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant