Skip to content

feat(ios): keep recorded messages across relaunches - #300

Merged
easyhooon merged 2 commits into
mainfrom
feat/ios-persist-messages
Nov 13, 2026
Merged

easyhooon merged 2 commits into
mainfrom
feat/ios-persist-messages

Conversation

@easyhooon

Copy link
Copy Markdown
Owner

Summary

Opt-in DariConfiguration(persistsMessages: true) keeps recorded messages across relaunches and crashes on iOS, as Android does with Room. Closes #297.

Changes

  • MessageFileStore writes one <id>\t<json> line (versioned DTO) per added or updated message to Application Support/Dari/messages.jsonl.
    • One serial queue and one open handle per file.
    • Excluded from backups, and protected with .completeUntilFirstUserAuthentication.
  • Loading runs asynchronously, as Android loads Room:
    • start() only scans the id prefixes, so live ids continue after stored ones.
    • Stored records are decoded off the file queue, then merged before live ones.
    • maxEntries and retentionPeriod apply during the merge.
    • After the merge, observers get cleared and then every record in order, and the file is compacted.
  • Responses never pair with records from an earlier launch, even when callback ids are reused. Android does pair them; iOS is stricter on purpose.
  • clear() deletes the file. Starting with persistsMessages: false deletes it too. stop() keeps it for the next start().
  • The sample app turns it on, and DariLoopbackDemo gets --persist and --crash[=<ms>].
  • Docs: iOS guide (+ ko) option and section, README tables.

Notes for reviewers

  • No byte cap, matching Android. A cap for both platforms is tracked in feat: cap total recorded message size on Android and iOS #299.
  • Measured on a Mac:
    • start() blocks 0–12 ms, even for a 123 MB file.
    • The background merge takes 61 ms for 2 MB.
    • A crash loses messages recorded within about 1–5 ms before it.
  • Reviewed with Opus at high effort. Its findings are fixed in the second commit:
    • unbounded file growth across short runs
    • a record glued to a partial line after a crash
    • appends waiting behind a large load
    • two instances writing to a replaced file
  • Verified:
    • swift test, with new MessageFileStoreTests
    • relaunch and crash runs with DariLoopbackDemo
    • the sample on an iOS 27 Simulator, where 3 messages came back after terminate and relaunch, below a new one

Opt-in persistsMessages writes each change to an id-prefixed JSON Lines file; start() reads only the last id
and merges stored messages in the background, as Android loads Room asynchronously.

Closes #297
Compact after each launch's merge, start on a fresh line after a partial one, decode off the file queue,
and share one handle per file.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@easyhooon
easyhooon marked this pull request as ready for review November 13, 2026 00:37
@easyhooon
easyhooon merged commit 5e1e891 into main Nov 13, 2026
6 checks passed
@easyhooon
easyhooon deleted the feat/ios-persist-messages branch November 13, 2026 00:37
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.

feat(ios): keep recorded messages across app relaunches

1 participant