Repository navigation
feat(mobile): add versioned offline sync for subscription edits - #2321
Merged
github-actions[bot] merged 1 commit intoNov 24, 2026
Merged
github-actions[bot] merged 1 commit into
github-actions[bot] merged 1 commit into
Conversation
- Add the mobile/src/sync outbox, conflict policy and push engine. Reason: issue Smartdevs17#1987 requires subscription edits made offline to survive restarts and be reconciled without silent overwrite. Consequence: each queued edit carries the server version it was made against and is applied only while that version is still current. - Use versioned optimistic concurrency with a server-authoritative winner for conflicts. Reason: device-clock last-writer-wins is unreliable after offline periods and drops the other device's change without a trace. Consequence: a version mismatch holds the local edit for the user to discard or re-apply, and edits to different fields of one record also conflict when the version moved. - Persist the outbox as one JSON document with copy-on-write commits. Reason: a failed write must not leave memory and storage disagreeing. Consequence: unreadable stored data throws OutboxCorruptError and is never overwritten. - Retry transient failures using the existing isRetryableQueryError, and hold rejected or exhausted edits. Reason: one bad record must not block the queue indefinitely. Consequence: a transient failure pauses the queue in FIFO order, while a conflict or rejection affects only its own record. - Emit identifier-only sync telemetry and warn logs. Reason: sync failures are user-visible and need observability without leaking subscription values. Consequence: patch values never appear in telemetry or logs. - Add unit tests for the policy, outbox persistence and rebase rules, and engine failure paths. Consequence: these tests were verified by reading only, not run. - Add mobile/src/sync/README.md covering the policy, behaviour, and what is not implemented. Not included: the HTTP write adapter, the server version and 409 contract, network and lifecycle wiring, and conflict-resolution UI. See the README for details. Refs Smartdevs17#1987
|
@tesleem-28 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the client-side core for offline-first subscription edits under
mobile/src/sync/:baseVersion).mobile/src/sync/README.md.The change is dependency-free. It reuses
isRetryableQueryError,queryErrorMessage,SubscriptionListItemandQueryHttpErrorfrommobile/src/queries/.What breaks if this is wrong
version, applies a write only whenbaseVersionmatches, and answers a mismatch with a conflict payload. The backend has none of this today. Against the current server, every push fails, and edits stay queued. Nothing is lost, but nothing syncs.asyncStorageAdapterinsrc/utils/storage.tsreturns null on read failure. Wiring it in as-is would make an unreadable outbox look empty, and the next write would overwrite it. The README calls this out. A throwing adapter is needed before wiring.maxAttempts.Scope
Implemented (under
mobile/src/sync/):types.ts,conflictPolicy.ts,outbox.ts,engine.ts,index.ts,README.md__tests__/conflictPolicy.test.ts,__tests__/outbox.test.ts,__tests__/engine.test.tsAcceptance criteria:
mobile/src/sync/.logger.warnare emitted from the engine. There is no UI, soengine.status()andsubscribe()are the only user-facing surface.mobile/src/sync/README.mdadded.docs/API.mdis not updated, because there is no API for this yet.docs/offline-architecture.mdis not updated. It describes a different design (a field-level LWW CRDT insrc/services/cache/crdt.tsandsrc/store/subscriptionStore.ts), and reconciling the two is a follow-up.Not implemented, which remains for follow-up work:
createHttpSubscriptionApiinmobile/src/queries/subscriptions.tsis GET-only.useOfflineSynchook lives insrc/hooks/, outsidemobile/, and is not connected here.SyncStorageadapter (see above).mobile/package.jsonis not present in this repository, so no dependency manifest was checked formobile/. The new code imports nothing outside existing modules.The acceptance criteria are not all met. The remaining items are listed above.
Verification
Verified by reading only:
../queries/queryClient(isRetryableQueryError,queryErrorMessage) and../queries/subscriptions(SubscriptionListItem,QueryHttpError).SyncOutbox,SyncEngine, andSyncTransportmatches its declared signature.flush().__tests__layout matched by the rootjest.config.jstestMatch, and Prettier settings from the repo.prettierrc(printWidth100, single quotes, trailing commas).package.jsonhas only"prepare": "husky"as a lifecycle script, with no install-time download or execution. The changed files contain no eval or base64-decoded code. None of the flagged file names (temp_auto_push.bat,config.bat,dist/setup.js) exist in the repository.Not run:
tsc, ESLint, Prettier, the app, and CI. The branch was created from upstreammainat091a12368e2936377b8eb87586104cd84dc382d9. Upstream moved one commit ahead of the fork'smain(9d75e5488af0802bc85010987c68a787987ad762) during the run. That commit touches onlybackend/andworkers/billingShift files, notmobile/.Closes #1987