安卓离线能力与数据同步审计
追踪离线写入、重试及多设备冲突中的数据流,输出可复现故障、队列修复和同步验证方案。
完整提示词
# ANDROID OFFLINE-FIRST AND SYNC AUDIT
I want you to perform a maximally deep, systematic, evidence-first, and production-oriented analysis of the complete offline-first and synchronization system of an Android application.
Main objective:
> Determine whether the application can reliably function across network transitions, offline periods, process death, app restarts, multiple devices, retries, conflicts, stale data, and partial failure without data loss, duplicates, silent overwrites, or false representations of successful synchronization.
This is not:
- a generic "use Room as single source of truth" tip
- a standard networking audit
- a superficial check for WorkManager presence
- a shallow `isOnline` check
- automatically slapping retries on every call
- a recommendation to blindly queue everything offline
- an assumption that "last write wins" is always acceptable
- a recommendation to sprinkle timestamps everywhere
- an attempt to force every app into an offline-first architecture
The focus is on the real-world operational pipeline:
```text
user action
↓
local state
↓
pending operation
↓
network availability
↓
sync
↓
server
↓
response
↓
conflict resolution
↓
local reconciliation
↓
UI
```
Priority hierarchy:
**data integrity > operation durability > idempotency > conflict correctness > account isolation > retry safety > eventual consistency > freshness > performance**
Finding 5 genuine sync flaws capable of corrupting user records is infinitely more valuable than listing 100 generic offline-first best practices.
---
# 1. ESTABLISH THE ACTUAL OFFLINE MODEL
Before raising any finding, determine what offline capabilities the application actually intends to support.
Classify the operational model:
```text
ONLINE-ONLY
ONLINE-FIRST
CACHE-ASSISTED
PARTIAL OFFLINE
OFFLINE-FIRST
LOCAL-FIRST
NOT CLEAR
```
Do not demand offline write support if the product specifications never committed to it.
---
# 2. IDENTIFY THE TECHNOLOGY STACK
Inspect:
- Room
- DataStore
- Raw files / persistent storage
- Repository layer
- Retrofit / Ktor / OkHttp
- WorkManager
- ConnectivityManager
- Flow
- StateFlow
- Retry policies
- Sync workers
- Push notifications / WebSockets / SSE if present
- Server API contracts
- Entity versioning mechanisms
- Timestamps
- Operation IDs
- Remote vs local ID mappings
---
# 3. MAP THE SOURCE OF TRUTH
For every critical data entity, classify authority:
```text
Server authority
Local authority
Room as source of truth
Hybrid authority
Derived / cache-only
```
For every feature, answer:
> From where does the UI actually consume data?
If reading depends on multiple sources under varying conditions, explicitly map their precedence hierarchy.
---
# 4. UI SOURCE OF TRUTH PIPELINE
Map the complete reactive data flow.
Example:
```text
API
↓
Room
↓
Flow
↓
UI
```
or:
```text
Local edit
↓
Room
↓
UI immediately updates
↓
Sync later
```
Identify discrepancies where UI components read directly from network endpoints under some conditions and from Room under others, producing state drift.
---
# 5. DATA INVENTORY
Construct a matrix for each synchronized data entity:
| Data Entity | Local Storage | Remote Storage | Authority | Offline Read | Offline Write |
|---|---|---|---|---|---|
---
# 6. SYNC DIRECTION
Classify each entity sync stream:
```text
PULL ONLY
PUSH ONLY
BIDIRECTIONAL
LOCAL ONLY
REMOTE ONLY
```
Avoid spending analysis cycles on conflict resolution models for read-only datasets.
---
# 7. SYNC TRIGGERS
Catalog all execution triggers:
- Application cold startup
- Foregrounding / lifecycle resumption
- Pull-to-refresh gestures
- Scheduled WorkManager runs
- Connectivity restoration callbacks
- Explicit user mutations
- Push notifications / FCM signals
- Manual retry actions
- Background periodic refresh
Evaluate:
> Can two or more triggers execute the identical sync pipeline concurrently?
---
# 8. DUPLICATE SYNC SCENARIOS
Scenario:
```text
app foregrounds
↓
manual pull-to-refresh begins
↓
WorkManager executes scheduled task
↓
network restore callback triggers sync
```
Verify:
- Deduplication gates
- Mutexes / locking mechanisms
- Unique work constraints
- Backend processing idempotency
---
# 9. SINGLE-FLIGHT SYNC GUARDS
Where synchronization must be strictly sequential:
Determine whether a genuine single-flight mechanism is enforced.
Do not assume an in-memory `isSyncing` boolean protects across process death or across multiple repository instances.
---
# 10. SYNC STATE MACHINE
If the system operates multi-phase synchronizations, formalize the states:
Example:
```text
IDLE
↓
PULLING
↓
MERGING
↓
PUSHING
↓
COMPLETED
```
Account for failure transitions:
```text
FAILED_TRANSIENT
FAILED_PERMANENT
AUTH_REQUIRED
CONFLICT
```
Audit for deadlocks and invalid transitions.
---
# 11. LOCAL READ WHILE OFFLINE
For each critical destination screen, audit:
```text
network unavailable
↓
app opens
↓
Room / local data available
```
Examine what the UI actually renders.
---
# 12. COLD START WHILE OFFLINE
Scenario:
```text
process terminated by system
↓
network disabled
↓
application cold launches
```
Do not restrict audits to online-to-offline runtime transitions; cold execution paths often fail differently.
---
# 13. FIRST-EVER LAUNCH WHILE OFFLINE
If an unauthenticated or newly installed client launches without network connectivity:
What does the interface display?
Distinguish between:
```text
EMPTY
```
and:
```text
FAILED TO LOAD
```
---
# 14. EMPTY CACHE VS OFFLINE ERROR
When local storage holds no records and no active network is available, the UI must avoid stating:
> No results found.
The system simply cannot load records; do not conflate absence of records with fetch failure.
---
# 15. STALE DATA INDICATORS
Offline-first architectures regularly display cached snapshots.
Verify:
> Does the user receive explicit feedback regarding data freshness when timeliness is domain-critical?
---
# 16. LAST SYNC TIMESTAMP AUDIT
If displaying:
```text
Last synced 10 minutes ago
```
Verify:
- Originating authority (server timestamp vs device clock)
- Timezone handling
- Client clock drift resilience
- Behavior upon partial or failed syncs
Never bump the sync timestamp simply because a sync job was initiated.
---
# 17. FALSE FRESHNESS HAZARDS
Scenario:
```text
sync starts
↓
server request partly succeeds
↓
later phase fails
↓
lastSynced updated anyway
```
The UI misleads users by claiming data is up to date when the pipeline experienced partial degradation.
---
# 18. TIME-SENSITIVE DOMAIN DATA
Segregate and evaluate sensitive business data:
- Pricing tables
- Inventory quotas
- Security permissions
- Subscription entitlements
- Operational statuses
- Financial balances
- Slot availability
Stale cache presentations here carry critical commercial or functional liability.
---
# 19. LOCAL MUTATION PIPELINE
For each offline-capable mutation, trace the lifecycle:
```text
User action
↓
Local DB write
↓
Pending marker
↓
Queue
↓
Sync
↓
Remote confirmation
↓
Pending cleared
```
---
# 20. DURABLE QUEUE REQUIREMENTS
If the application guarantees eventual server delivery, mutations must survive:
- Process death
- Explicit application force stops
- Device reboots
An in-memory list or volatile flow is wholly inadequate.
---
# 21. PENDING OPERATION SCHEMA
For every queued operation, inspect:
- Unique operation ID
- Operation type
- Target entity ID
- Serialized payload
- Creation timestamp
- Attempt counter
- Execution state
- Dependency references
- User / account owner ID
---
# 22. QUEUE STATE TAXONOMY
Standard robust state lifecycle:
```text
PENDING
IN_FLIGHT
SUCCEEDED
FAILED_RETRYABLE
FAILED_PERMANENT
CANCELLED
```
Do not mandate exact identifiers, but verify that the implementation distinctly differentiates these execution states.
---
# 23. IN_FLIGHT STALL ACROSS PROCESS DEATH
Scenario:
```text
operation marked IN_FLIGHT
↓
network request dispatched
↓
OS terminates process
```
Upon subsequent restart:
> Does the operation remain permanently stranded in IN_FLIGHT state?
---
# 24. LEASE EXPIRY AND ORPHAN RECOVERY
If using in-flight state locks, check how orphaned or crashed operations are reclaimed for processing.
---
# 25. UNCERTAIN REMOTE OUTCOME
The fundamental distributed systems dilemma:
```text
client sends create mutation
↓
server commits write to database
↓
response connection drops before reaching client
↓
client experiences socket timeout
```
The client cannot know whether the mutation executed remotely.
---
# 26. RETRIES FOLLOWING UNCERTAIN OUTCOMES
If the client blindly resends the creation request:
Duplicate records will be generated.
Audit end-to-end idempotency guarantees.
---
# 27. IDEMPOTENCY KEYS
For critical state changes and creations, check for a stable client-generated operation key recognized by the backend across retries.
---
# 28. CLIENT-GENERATED IDENTIFIERS
Standard architecture pattern:
```text
UUID generated locally
↓
identical ID preserved across all retries
```
This facilitates transparent deduplication when backend contracts support client-defined primary keys.
---
# 29. THE EXACTLY-ONCE ILLUSION
Never declare an asynchronous network operation "exactly once" simply because it resides in a durable queue.
Distributed synchronization operates on:
```text
at-least-once delivery
+
idempotent processing
```
or explicit deduplication semantics.
---
# 30. CREATION DUPLICATION HAZARDS
Scenario:
```text
offline creation
↓
sync request dispatched
↓
server inserts record
↓
connection drops
↓
client worker retries
↓
second identical record inserted
```
Inspect deduplication boundaries.
---
# 31. UPDATE IDEMPOTENCY
Absolute set operations:
```text
set name = X
```
are inherently more idempotent than delta operations:
```text
increment balance by X
```
Backend endpoint semantics must be strictly evaluated.
---
# 32. DELETION IDEMPOTENCY
Repeated deletion invocations must have well-defined semantics.
If the backend returns HTTP 404 upon a retried deletion of an already purged item, the client must treat the final state as resolved, depending on domain rules.
---
# 33. QUEUE ORDERING GUARANTEES
Must operations on the same entity execute in strict order?
Example:
```text
create entity A
↓
update entity A
↓
delete entity A
```
If requests execute concurrently or reorder due to retry timings, state corruption occurs.
---
# 34. DEPENDENT OPERATIONS
Mutating a locally created record depends upon the success of the creation request when the backend assigns primary keys.
Trace the dependency resolution graph.
---
# 35. LOCAL VS REMOTE IDENTIFIER MAPPINGS
Verify the translation between:
```text
localId
remoteId
```
Particularly across:
- Offline entity creation
- Subsequent updates before initial sync completes
- Cross-entity foreign key relationships
---
# 36. REMOTE ID RECONCILIATION
Scenario:
```text
local entity ID = -1 (or temp UUID)
↓
server creates entity with ID = 572
```
Audit how:
- Database rows
- Foreign key relations
- Pending operations in queue
- Active UI state holders
are updated with the canonical remote ID.
---
# 37. ID REMAPPING RACE CONDITIONS
If a user constructs child entities before the parent record receives its canonical remote ID:
Verify how the dependency hierarchy is maintained through the queue.
---
# 38. STABLE CLIENT UUID IDENTIFIERS
When the backend supports persistent client-generated UUIDs, ID remapping complexities are largely bypassed.
Evaluate the system in place rather than inventing unnecessary redesigns.
---
# 39. QUEUE COMPACTION POLICIES
Scenario:
```text
offline
↓
edit field to A
↓
edit field to B
↓
edit field to C
```
Should the client dispatch 3 discrete mutations or compact to the terminal state?
Depends on business semantics (event sourcing vs state sync).
---
# 40. DELETION COMPACTION
If an entity lifecycle while offline undergoes:
```text
create
update
delete
```
prior to any network dispatch, remote calls are unnecessary provided the server was never aware of the entity.
---
# 41. OPERATION VS STATE SYNCHRONIZATION
Determine whether the application synchronizes:
**operations** (delta events / command log)
or:
**current state** (whole object snapshots)
This is a fundamental architectural boundary.
---
# 42. OPERATION-BASED SYNCHRONIZATION
Example:
```text
ADD_ITEM
RENAME_ITEM
DELETE_ITEM
```
Ordering, sequencing, and deduplication are mission-critical.
---
# 43. STATE-BASED SYNCHRONIZATION
Example:
```text
local entity state
↓
PUT / upsert to server
```
Conflict semantics and race handling become the central challenge.
---
# 44. SERVER AUTHORITY BIAS
When the backend acts as single authority, local unsynced edits risk silent overwrites during remote refreshes if merge logic is unprincipled.
---
# 45. LOCAL DIRTY FLAGS
When an entity row possesses unsynchronized local changes:
A remote pull must never blindly overwrite dirty rows.
---
# 46. SYNC VS LOCAL EDIT RACE CONDITION
Scenario:
```text
sync starts and downloads server v10
↓
user locally edits entity to v11
↓
sync response v10 written to database afterward
↓
user edit v11 is lost
```
This is a critical sync race condition.
---
# 47. SNAPSHOT TIMING INTEGRITY
Evaluate:
> At what exact point in time was the remote response snapshot valid relative to local modifications?
Request initiation time differs significantly from response arrival time.
---
# 48. SERVER REVISIONING SIGNALS
If the server provides monotonic:
- Revisions
- Versions
- ETags
Verify whether client repositories leverage these signals for conflict detection.
---
# 49. `updatedAt` RELIABILITY
Timestamps can assist ordering but are inherently brittle for conflict resolution.
Flaws:
- Device clock skew
- Identical millisecond collisions
- Client-generated timestamps
---
# 50. SERVER-GENERATED TIMESTAMPS
When timestamps govern ordering, server-assigned timestamps provide higher authority than device clocks.
Verify the actual backend contract.
---
# 51. CLOCK SKEW HAZARDS
Scenario:
```text
device clock skewed +2 hours ahead
```
If local `updatedAt` enforces "newest wins", the client will permanently overwrite newer remote edits from other devices.
---
# 52. LAST WRITE WINS (LWW) SCRUTINY
Where LWW is implemented, rigorously document:
- What defines "last" (client clock, server arrival, monotonic counter)
- Whether silent data loss occurs
- Whether silent data loss is acceptable within the business domain
---
# 53. FIELD-LEVEL MERGING
When concurrent devices alter distinct fields:
```text
Device A modifies title
Device B modifies color
```
Whole-object LWW obliterates one mutation.
Determine whether the domain demands granular field-level resolution.
---
# 54. USER-ASSISTED CONFLICT RESOLUTION
For high-value domain entities, manual user reconciliation may be required.
Do not impose manual flows on trivial settings.
---
# 55. CRDT JUSTIFICATION
Do not introduce CRDTs simply because offline capabilities exist.
They are justified exclusively for specialized collaborative workflows.
---
# 56. CONCURRENT DELETION CONFLICTS
Scenario:
```text
Device A deletes item while offline
Device B updates item while online
```
What occurs when Device A reconnects?
---
# 57. TOMBSTONES
When deletion must propagate through sync pipelines, local deletion tombstones must persist until confirmation is received.
---
# 58. PREMATURE HARD DELETIONS
If a row is immediately purged from the local database, the sync engine has no record of the deletion to propagate remotely.
---
# 59. TOMBSTONE RETENTION LIFECYCLE
Retain tombstones until verified server acknowledgement is achieved across all downstream targets.
---
# 60. REMOTE DELETION PROPAGATION
When the server reports an entity has been deleted, verify:
- Local dirty modifications on that entity
- Local dependent child records
- Open detail screens displaying the entity
---
# 61. RESURRECTION DEFECTS
Scenario:
```text
server deletes entity
↓
offline client retains cached copy
↓
user edits local copy
↓
network reconnects
↓
blind upsert recreates purged server record
```
Determine whether resurrection is intentional or a defect.
---
# 62. SYNC WINDOWS AND TOKENS
When backend endpoints return incremental changes since a timestamp or token:
Inspect token update semantics.
---
# 63. DELTA SYNCHRONIZATION PIPELINE
Trace the execution path:
```text
sync token
↓
request changes
↓
apply database transaction
↓
persist new sync token
```
---
# 64. TOKEN PERSISTENCE ATOMICITY
Critical race condition:
```text
apply 50% of delta changes
↓
save new sync token
↓
crash / process death
```
Subsequent syncs will permanently skip the unapplied 50%.
Token updates and entity writes must share an atomic database transaction.
---
# 65. TOKEN SAVED PRIOR TO DATA WRITE
Even worse failure mode:
```text
persist new sync token
↓
write data entities
↓
write fails
```
Delta changes are skipped permanently.
---
# 66. PAGINATED DELTA SYNCHRONIZATION
When delta or full sync spans multiple pages:
```text
page 1
page 2
page 3
```
Verify:
- Partial progress checkpoints
- Cursor persistence
- Crash recovery
- Duplicate entry resilience
---
# 67. CURSOR EXPIRATION HANDLING
If server pagination cursors or sync tokens expire, verify the client's fallback path to a clean full resynchronization.
---
# 68. FULL RESYNCHRONIZATION PROTOCOL
Does the system support rebuilding local caches from authoritative backend snapshots when incremental states become corrupted?
---
# 69. FULL RESYNC VS DIRTY LOCAL STATE
A full cache refresh must never discard or overwrite uncommitted local mutations.
---
# 70. DESTRUCTIVE CACHE REPLACEMENT HAZARDS
Scenario:
```text
DELETE ALL FROM table
↓
INSERT server snapshot
```
If pending local modifications reside in that table, immediate data loss results.
---
# 71. STAGING TABLE MERGING
For complex synchronization models, pulling remote snapshots into staging entities prior to transactional reconciliation prevents UI flickers and dirty overwrites.
---
# 72. TRANSACTION BOUNDARIES
Batched remote changes forming a coherent snapshot must apply within an atomic database transaction so the UI never observes partial states.
---
# 73. MID-SYNC ABORTION
Evaluate:
> If network or parsing fails after ingesting 60% of incoming changes, what state does the UI observe?
---
# 74. PARTIAL BATCH OUTCOMES
Distinguish between:
```text
10 operations sent
↓
7 succeed
3 fail
```
and a holistic request failure.
---
# 75. BATCH API ERROR MAPPING
When the backend returns itemized status codes per batch item, the client must accurately map success and failure to individual queue items.
---
# 76. ALL-OR-NOTHING BATCH SEMANTICS
When a backend batch endpoint operates with transactional rollback on single-item failure, verify client retry boundaries.
---
# 77. ERROR CLASSIFICATION TAXONOMY
Classify errors semantically before deciding retry policies:
```text
TRANSIENT
PERMANENT
AUTH
CONFLICT
VALIDATION
NOT FOUND
RATE LIMITED
UNKNOWN
```
Never treat all HTTP failures uniformly.
---
# 78. HTTP 400 VALIDATION ERRORS
Client validation errors will not resolve by repeated retries.
Infinite retry loops here wedge the queue permanently.
---
# 79. HTTP 401 AUTHENTICATION FAILURES
Auth errors require:
- Token refresh attempts
- Prompting user re-authentication
- Preserving queued operations until credentials recover
Never discard queued user edits due to an expired token.
---
# 80. HTTP 403 FORBIDDEN
Signals that the account lacks authorization to perform the mutation.
The queue must route to an explicit permanent-failure handling path.
---
# 81. HTTP 404 NOT FOUND
Semantics depend on the operation:
- Updating a missing entity (conflict / remote deletion)
- Deleting an already removed entity (potential success)
Do not apply a single uniform handler.
---
# 82. HTTP 409 CONFLICT
Conflicts demand domain-specific reconciliation rather than generic transient network retries.
---
# 83. HTTP 429 RATE LIMITING
Verify:
- `Retry-After` header parsing
- Exponential backoff
- Coordinated queue pause
Prevent aggressive client request stampedes.
---
# 84. HTTP 5XX SERVER ERRORS
Candidates for transient retry, but must be strictly bounded with jittered backoff.
---
# 85. NETWORK SOCKET TIMEOUTS
A timeout leaves remote execution status completely ambiguous.
Never treat a timeout as "the request never reached the server."
---
# 86. CONNECTION AND DNS FAILURES
Failures occurring prior to socket establishment allow safe immediate retry, though clients rarely have 100% precision regarding the exact point of failure.
---
# 87. BACKOFF POLICIES
Inspect:
- Backoff strategy (exponential, linear)
- Maximum retry delay cap
- Maximum attempt bounds
- Server throttling hints
---
# 88. THUNDERING HERD / RETRY STORMS
If thousands of mobile clients reconnect simultaneously following backend recovery, immediate un-jittered retries cause a thundering herd failure.
---
# 89. WORKMANAGER INTEGRATION
Audit background sync workers:
- Unique work name enforcement
- Network / battery constraints
- Backoff criteria
- Identification tags
- Cancellation handling
- Expedited execution flags if configured
---
# 90. NETWORK CONSTRAINTS
WorkManager's `NetworkType.CONNECTED` constraint prevents wasteful execution while offline, but network connectivity does not guarantee API reachability.
---
# 91. UNIQUE WORK POLICIES
Verify that `ExistingWorkPolicy` coordinates background scheduling without inadvertently killing active foreground syncs or dropping queued tasks.
---
# 92. PERIODIC WORK ACCURACY
Do not expect exact timing execution from periodic WorkManager tasks.
---
# 93. ONE-TIME WORK ACCUMULATION
If queuing a one-time worker after every local mutation, verify that 100 rapid offline changes do not schedule 100 redundant worker instances.
---
# 94. WORK CHAINS AND DEPENDENCIES
When push phases must strictly follow pull or authentication phases, verify proper WorkManager chaining.
---
# 95. WORKER EXECUTION INTERRUPTIONS
Workers can be killed by the OS and re-executed from scratch.
Evaluate:
> Is re-executing the interrupted worker phase safe and idempotent?
---
# 96. `ListenableWorker.Result.retry()` SCRUTINY
Never invoke `Result.retry()` on deterministic, unrecoverable validation rejections.
---
# 97. WORKMANAGER DATA PAYLOAD SIZE
WorkManager's `Data` object enforces a strict 10 KB limit.
Durable queue payloads must reside in Room tables or local storage, not inside worker `Data`.
---
# 98. FOREGROUND VS BACKGROUND COORDINATION
When a user pulls to refresh in the foreground, coordinate with running background workers to avoid redundant network overhead.
---
# 99. SYNC PROGRESS INTEGRITY
If long-running sync operations display progress bars, verify that metrics correlate with actual completion checkpoints.
---
# 100. FALSE SUCCESS IN THE UI
The most pervasive user trust vulnerability:
```text
user saves while offline
↓
UI displays "Saved"
```
Does "Saved" mean:
- Saved locally on device
- Queued for sync
- Confirmed by backend
Never mislead users regarding synchronization completion.
---
# 101. LOCAL SAVED VS REMOTELY SYNCED
Separate domain states where business context requires distinction:
```text
Saved on device
Waiting to sync
Synced
Sync failed
```
Internal models must track these differences even if simplified for display.
---
# 102. PENDING INDICATORS
Ensure critical records awaiting sync convey pending status where business consequences matter.
---
# 103. FAILED OPERATION VISIBILITY
Permanent sync rejections must not remain silently hidden.
Scenario:
```text
message queued
↓
server permanently rejects payload
↓
UI continues to display message as sent
```
---
# 104. MANUAL RETRY USER EXPERIENCE
A manual retry action must operate on the original logical operation and idempotency key rather than creating a brand-new duplicate mutation.
---
# 105. CANCELLATION OF PENDING OPERATIONS
If users can abort an operation prior to sync:
Verify:
- Local database rollback
- Queue record removal
- Cleanup of dependent queued operations
---
# 106. CANCELLATION DURING IN-FLIGHT DISPATCH
If an HTTP request has already been transmitted, local cancellation cannot ensure the server will not commit the write.
---
# 107. CONNECTIVITY DETECTION LIMITATIONS
Never equate:
```text
network transport available
```
with:
```text
API backend reachable
```
---
# 108. `isOnline` BOOLEAN FRAGILITY
If relying on a global boolean, audit its computation.
It serves as UX guidance, not as a conclusive gatekeeper for dispatching requests.
---
# 109. NETWORK CAPABILITY VALIDATION
ConnectivityManager flags transport availability, but DNS resolution, captive portals, and server health determine actual connectivity.
---
# 110. OFFLINE DETECTION RACE CONDITIONS
Network availability can drop in the microseconds between capability checks and socket execution:
```text
if (isOnline) {
api.call() // Can still throw IOException
}
```
Standard network exception handling remains mandatory.
---
# 111. RECONNECT STAMPEDE
When network connectivity restores, identify which listeners activate:
- Foreground network callbacks
- WorkManager constraints
- WebSocket re-connectors
- Repository observers
Audit for duplicate concurrent sync dispatch.
---
# 112. FLAPPING NETWORK BEHAVIOR
Simulate rapid cycling:
```text
online → offline → online → offline → online
```
Ensure the sync queue does not flood with duplicate tasks or exhaust thread pools.
---
# 113. HIGH LATENCY AND DEGRADED NETWORKS
Offline is not the only network hazard.
Scenario:
```text
network technically connected
↓
requests hang for 30 seconds
```
Verify timeouts, UI responsiveness, and stale response handling.
---
# 114. MULTI-DEVICE CONCURRENCY
When a single account is active across multiple mobile devices, local concurrency locks provide zero protection against cross-device conflicts.
---
# 115. CROSS-DEVICE CONFLICT SCENARIOS
Simulate:
```text
Device A offline
Device B online
Device A mutates entity X
Device B mutates entity X
Device A reconnects
```
Document the exact resolution outcome.
---
# 116. DEVICE IDENTIFIER INTEGRITY
If using device IDs for sync fences or cursor tracking, verify behavior across reinstallation, backups, and privacy rotations.
---
# 117. MULTI-ACCOUNT ISOLATION
Sync queues and pending tables must be strictly partitioned by user account.
---
# 118. QUEUE ISOLATION ON LOGOUT
Scenario:
```text
User A queues pending mutations
↓
User A logs out
↓
User B logs in
```
What occurs to User A's pending queue?
---
# 119. CROSS-USER MUTATION DISPATCH (CRITICAL RISK)
Catastrophic P0 vulnerability:
```text
User A queues private mutation
↓
User B logs in
↓
Generic sync worker triggers
↓
Worker grabs User B auth token
↓
Worker dispatches User A payload under User B session
```
Actively inspect and test for this vulnerability.
---
# 120. ACCOUNT OWNERSHIP METADATA
Every queued record must store the owner's `accountId`, and sync workers must validate that current session credentials match before execution.
---
# 121. LOGOUT DISPOSITION POLICIES
Upon user logout, explicit policy must dictate queue handling:
- Purge pending mutations
- Preserve account-scoped mutations in isolation
- Prompt user to sync before exit
- Explicitly warn of data loss
---
# 122. LOGOUT WITH UNCOMMITTED LOCAL DATA
If logging out wipes uncommitted local changes, the user must receive a prominent warning, particularly if no remote copy exists.
---
# 123. ACCOUNT DELETION CLEANUP
Pending mutations belonging to a deleted account must be completely purged and never executed.
---
# 124. CONCURRENT TOKEN REFRESH DURING SYNC
When multiple queued requests receive HTTP 401 simultaneously, ensure a single-flight token refresh executes without spawning redundant refresh calls.
---
# 125. EXTENDED OFFLINE AUTHENTICATION EXPIRY
Scenario:
```text
user remains offline for 7 days
↓
creates multiple local records
↓
authentication token expires
↓
network returns
```
Ensure local pending data is safely preserved until the user completes re-authentication.
---
# 126. AUTH FAILURES MUST NOT DISCARD QUEUED DATA
Never purge user mutations simply because an access token is expired or revoked.
Distinguish:
```text
invalid mutation data
```
from:
```text
temporary authentication invalidity
```
---
# 127. PERMISSION REVOCATION HANDLING
If a user's permissions were revoked on the backend while the device was offline, queued requests will receive HTTP 403.
The UI must inform the user that their edits could not be synchronized.
---
# 128. BACKEND SCHEMA EVOLUTION VS QUEUED OPERATIONS
An older client may hold queued operations formatted under a legacy schema.
If the backend has evolved in the interim:
> Does the API still accept the legacy payload?
---
# 129. QUEUE PAYLOAD VERSIONING
When operations can remain queued across extended intervals, consider payload schema versioning and backward-compatible parsers.
---
# 130. APP UPDATE OVER PENDING QUEUE
Scenario:
```text
v1 queues operations
↓
user updates app to v2
↓
v2 worker reads v1 queue
```
Ensure payload serialization and Room schemas remain fully compatible.
---
# 131. DATABASE MIGRATIONS PRESERVING QUEUES
Room migrations must preserve pending mutation tables, dirty flags, and queue payloads without truncation.
---
# 132. ENUM DRIFT IN QUEUED PAYLOADS
Queued payloads containing deprecated enum values must have explicit fallback parsing or migration strategies.
---
# 133. SCHEMA DRIFT IN ENTITY POINTERS
If a queued operation only stores an entity ID and reads the live database row at execution time:
It may dispatch a completely different payload than originally intended.
Determine whether the queue stores:
- Point-in-time operation snapshot
- Live entity pointer
---
# 134. OPERATION SNAPSHOT VS LIVE ROW DYNAMICS
Example:
```text
user schedules change A
↓
later locally modifies row to B
```
If the pending worker reads the live row at sync time, does it dispatch A or B?
---
# 135. ATTACHMENT AND FILE SYNCHRONIZATION
Offline file uploads require a dedicated lifecycle:
```text
local file created
↓
pending upload record created
↓
upload worker executes
↓
remote URL / ID obtained
↓
entity reconciled with remote file reference
```
---
# 136. FILE EXISTENCE VERIFICATION
If the system or user deletes a temporary file prior to worker execution:
Verify how the upload failure is detected and reported.
---
# 137. URI PERMISSION SURVIVABILITY
If storing external content URIs in the queue, verify that persistable URI permissions are requested so access survives process death and reboots.
---
# 138. PERSISTABLE URI GRANTS
Ensure `takePersistableUriPermission` is invoked for document URIs requiring delayed background upload.
---
# 139. TEMPORARY FILE PERSISTENCE
Never store files destined for queued upload exclusively in disposable cache directories that the OS can purge under memory pressure.
---
# 140. RESUMABLE LARGE FILE UPLOADS
If the application routinely handles multi-megabyte media uploads, verify chunked or resumable upload support.
If file sizes are negligible:
**NOT APPLICABLE**
---
# 141. UPLOAD RETRY IDEMPOTENCY
Retrying an upload after a dropped connection must not generate duplicate orphan media files on the server.
---
# 142. OFFLINE DOWNLOAD INTEGRITY
For downloaded content assets, verify:
- Completion marker
- Partial file cleanup
- Checksum verification
- Resume capabilities
---
# 143. PARTIAL DOWNLOAD CONTAMINATION
Never treat an interrupted, partial file download as valid cached content.
---
# 144. ATOMIC DOWNLOAD FINALIZATION
Robust model:
```text
download to temp file
↓
verify length / checksum
↓
atomic file rename to target path
```
---
# 145. CHECKSUM VERIFICATION
Use checksums for critical offline binary assets to detect storage corruption.
---
# 146. REALTIME WEBSOCKET / PUSH INTERACTIONS
If the server pushes updates via WebSocket or FCM:
Map the interaction between realtime pushes and background sync workers.
---
# 147. DUPLICATE REMOTE EVENT HANDLING
Push notifications and socket frames can arrive duplicated.
Event processing on the client must be strictly idempotent.
---
# 148. OUT-OF-ORDER EVENT RECONCILIATION
Realtime event v12 may arrive prior to v11 due to network routing.
Check whether revision tracking orders or discards stale incoming events.
---
# 149. MISSED EVENT RECOVERY
WebSockets and FCM are not durable event logs.
Following reconnect, the client must execute a catch-up delta sync.
---
# 150. PUSH NOTIFICATION AS INVALIDATION SIGNAL
Best practice pattern:
```text
push notifies "data changed"
↓
client initiates authenticated fetch of authoritative state
```
Verify whether this pattern is utilized.
---
# 151. PUSH INVALIDATION STORM SUPPRESSION
A rapid burst of push invalidations must be debounced to avoid triggering concurrent fetch storms.
---
# 152. LOCAL CACHE INVALIDATION SCOPE
When an entity updates, verify that related cached queries, joins, and derived views update consistently.
---
# 153. DENORMALIZED DATA INCONSISTENCIES
If identical data fields are stored across multiple Room tables, verify that synchronization updates all copies atomically.
---
# 154. DERIVED AGGREGATE STALENESS
Example:
```text
folder.itemCount
```
alongside child item rows.
Ensure insertions and deletions recalculate or refresh cached aggregates.
---
# 155. MATERIALIZED VIEW CONSISTENCY
If caching derived computation tables for UI performance, audit their invalidation rules during sync writes.
---
# 156. INFINITE SYNC LOOPS
Hazard scenario:
```text
remote change arrives
↓
local write commits
↓
local observer interprets write as user mutation
↓
dispatches push to server
↓
server returns update event
↓
infinite loop ensues
```
Verify mutation source origin tagging.
---
# 157. LOCAL VS REMOTE MUTATION ORIGIN
The sync engine must distinguish between:
```text
USER_EDIT
REMOTE_SYNC
MIGRATION
SYSTEM_UPDATE
```
to prevent reactive observers from re-queuing remote writes.
---
# 158. ECHO SUPPRESSION
When the server broadcasts back the change this specific client just pushed, the client must recognize its own operation and suppress duplicate local writes.
---
# 159. CANONICAL SERVER VERSION ACKNOWLEDGEMENT
When a mutation succeeds remotely, the local database entity must update its version tracking to match the authoritative server revision.
---
# 160. ACKNOWLEDGEMENT RACE CONDITIONS (CRITICAL HAZARD)
Scenario:
```text
local edit A dispatched to server
↓
user immediately makes local edit B
↓
server response acknowledging A arrives
↓
client response handler writes canonical entity A over Room
↓
user edit B is silently obliterated
```
This is one of the most critical bugs in offline-first architectures.
---
# 161. PATCH VS FULL REPLACEMENT RESPONSES
If server responses return only metadata and version headers, protecting local pending fields is simpler than when responses return whole entity snapshots.
---
# 162. FULL ENTITY RESPONSE RECONCILIATION
When the server returns the full entity snapshot, the merge logic must determine whether subsequent un-synced edits occurred while the request was in flight.
---
# 163. LOCAL DIRTY GENERATION COUNTERS
A local monotonic revision or generation counter prevents stale acknowledgements from overwriting newer local edits.
---
# 164. PULL-AFTER-PUSH EVENTUAL CONSISTENCY TRAPS
If executing a full pull immediately following a successful push, distributed backend replication lag may return a stale snapshot that temporarily overwrites the fresh write.
---
# 165. READ-AFTER-WRITE BACKEND GUARANTEES
Never assume distributed backend databases offer immediate global read-after-write consistency.
---
# 166. SERVER-SIDE CACHING ANOMALIES
If intermediate proxies or CDN caches serve cached GET responses immediately following a write, client Room tables may revert to stale state.
---
# 167. UI OPTIMISM VS SERVER CANONICALIZATION
Servers regularly normalize fields:
- Trim text strings
- Calculate computed fields
- Adjust timestamps
- Format values
Audit how optimistic UI states reconcile with canonical server transformations.
---
# 168. OPTIMISTIC MUTATION ROLLBACK INTEGRITY
If an optimistic local mutation fails permanently:
Rollback logic must account for subsequent user edits applied on top of the optimistic state.
---
# 169. NAIVE SNAPSHOT ROLLBACK HAZARD
Scenario:
```text
initial state = A
↓
optimistic edit 1 → B
↓
user performs edit 2 → C
↓
edit 1 fails remotely
↓
system naively rolls back to A
```
Valid user modification C is completely lost.
---
# 170. REVERSIBLE PATCH ROLLBACKS
Concurrent optimistic updates require inverse patch applications rather than blind whole-record historical snapshot restoration.
---
# 171. CONFLICT RESOLUTION UI REQUIREMENTS
When conflicts demand user decision:
Verify the UI supplies necessary context:
- Local value
- Remote value
- Relative timestamps and author
- Explicit selection controls
---
# 172. HIDDEN CONFLICT OVERWRITES
Never silently drop user-authored business data under the guise of automated resolution without explicit domain justification.
---
# 173. ERROR STATE PERSISTENCE
Failure statuses must survive application process restarts.
If an operation requires attention, restarting the app must not disguise the failure.
---
# 174. RETRY COUNTER PERSISTENCE
If retry counts reside exclusively in volatile memory, process restarts reset the count to zero, producing unbounded retry loops.
---
# 175. DEAD-LETTER QUEUE HANDLING
Permanently rejected operations must transition to a dead-letter state so they do not block independent queue progress indefinitely.
---
# 176. POISON OPERATION ISOLATION
An invalid, malformed mutation must not halt the processing of unrelated queued mutations behind it unless strict ordering dependencies exist.
---
# 177. CASCADE ON DEPENDENCY FAILURE
If a parent entity creation permanently fails:
Queued child mutations must be safely aborted rather than dispatching doomed requests.
---
# 178. QUEUE PRIORITY SCHEMES
User-initiated interactive syncs should take precedence over background routine polling.
Do not overcomplicate without business need.
---
# 179. QUEUE FAIRNESS
A backlog of hundreds of updates for one entity must not starve operations belonging to other domain features.
---
# 180. UNBOUNDED QUEUE ACCUMULATION
If a client operates offline for days:
How large can the pending queue grow?
---
# 181. STORAGE AND MEMORY UNDER EXTENDED OFFLINE
Verify queue querying and serialization performance when hundreds of operations accumulate.
---
# 182. SAFE QUEUE COMPACTION
If compaction is enabled, prove that coalescing two operations preserves business semantics without losing intermediate audit requirements.
---
# 183. BACKPRESSURE MITIGATION
If the user generates mutations faster than network throughput can upload them upon reconnect:
Verify queue stability and database transaction latency.
---
# 184. DISPATCH RATE LIMITING
Throttle parallel network requests from the queue to avoid exhausting client connection pools or tripping server rate limits.
---
# 185. REQUEST BATCHING
Batching multiple queued operations into a single network payload reduces radio wakeups.
Verify partial failure and error attribution semantics.
---
# 186. BACKEND PAYLOAD SIZE LIMITS
If syncing a large backlog in batches, enforce batch size caps to respect backend HTTP request body limits.
---
# 187. PAGINATED PUSH CHECKPOINTS
When pushing large queue volumes in segments, update persistence checkpoints after each successful batch.
---
# 188. ATOMICITY OF BACKEND BATCH ENDPOINTS
Determine whether the backend processes batch items individually or rolls back the entire batch upon any single item rejection.
---
# 189. SYNC OBSERVABILITY AND TELEMETRY
Synchronization is notoriously difficult to diagnose without clear telemetry:
- Sync start events
- Completion durations
- Batch item counts
- Retry counts
- Permanent failure classifications
- Conflict events
---
# 190. SENSITIVE DATA IN LOGS
Never write raw mutation payloads or private user credentials into system logs during sync debugging.
---
# 191. STABLE CORRELATION OPERATION IDS
Non-sensitive, stable operation UUIDs must be passed through log statements to enable tracing across retries.
---
# 192. OPERATIONAL SYNC METRICS
Key diagnostic metrics:
- Current pending queue depth
- Age of oldest un-synced operation
- Sync success / failure ratio
- Conflict frequency
---
# 193. INTERNAL DIAGNOSTIC DEBUG SCREEN
A hidden debug screen rendering the live pending queue, sync states, and triggers significantly accelerates production issue triage (classify as P4 if absent).
---
# 194. SYNC TEST HARNESS AUDIT
Inspect the test suite:
- Repository unit tests
- Room migration and query tests
- WorkManager testing via `TestListenableWorkerBuilder`
- MockWebServer network failure simulations
- End-to-end sync integration tests
---
# 195. COMPREHENSIVE OFFLINE TEST SCENARIO
Minimum critical verification flow:
```text
online
↓
fetch and seed data
↓
cut network
↓
read and locally mutate
↓
kill application process
↓
restore network
↓
verify convergence and sync
```
---
# 196. PROCESS DEATH RESILIENCE TEST
Verify:
```text
mutation queued
↓
kill process immediately
↓
launch new process
↓
sync triggers and completes
```
---
# 197. DEVICE REBOOT RECOVERY TEST
Verify that scheduled WorkManager sync workers survive device reboots where background sync is expected.
---
# 198. LOST RESPONSE TEST SIMULATION
Crucial test:
```text
server commits mutation
↓
connection severed before HTTP response received
↓
client retries
```
Verify that no duplicate record is created.
---
# 199. OUT-OF-ORDER NETWORK RESPONSE TEST
Inject artificial latency:
```text
dispatch request A
dispatch request B
response B arrives
response A arrives
```
Verify final local database state matches intended sequence.
---
# 200. MULTI-DEVICE CONCURRENCY SIMULATION
Test simultaneous mutations from two distinct simulated clients against the same entity to verify server conflict handling.
---
# 201. ACCOUNT SWITCHING INTEGRITY TEST
Execute:
```text
User A queues mutation while offline
↓
User A logs out
↓
User B logs in
↓
network restores
```
Assert:
- User A's mutation is NOT dispatched under User B's auth token
- User A's un-synced data is NOT exposed to User B
---
# 202. TOKEN EXPIRY DURING OFFLINE TEST
Queue operations, expire auth tokens, re-authenticate, and verify queued data dispatches successfully under the original account.
---
# 203. PERMANENT VALIDATION REJECTION TEST
Simulate server returning HTTP 422 / 400.
Assert:
- Infinite retries do NOT occur
- Operation transitions to failed state
- User receives actionable notification
---
# 204. TRANSIENT FAILURE RECOVERY TEST
Simulate HTTP 503 / network drops.
Assert proper exponential backoff retry execution.
---
# 205. STALE REVISION CONFLICT TEST
Client submits mutation with revision v2 when server is at v4.
Assert proper conflict pathway activation.
---
# 206. DELETION VS UPDATE CONFLICT TEST
Device A deletes entity while Device B updates entity.
Verify deterministic resolution.
---
# 207. LOCAL EDIT DURING PULL TEST
Execute:
```text
trigger sync pull
↓
delay remote response
↓
user edits entity locally
↓
release remote response
```
Assert that the local edit is NOT overwritten by the incoming snapshot.
---
# 208. ACKNOWLEDGEMENT RACE CONDITION TEST
Execute:
```text
dispatch local version A
↓
user immediately modifies to version B locally
↓
receive HTTP 200 acknowledgement for A
```
Assert that local version B remains preserved in the database.
---
# 209. DATABASE MIGRATION WITH ACTIVE QUEUE TEST
Seed an older database schema containing dirty rows and pending queue items.
Execute Room migration to latest version.
Assert queue integrity is completely preserved.
---
# 210. MASSIVE BACKLOG SCALE TEST
Seed 500 pending operations into the queue.
Verify memory footprint, battery impact, and batch chunking.
---
# 211. RAPID NETWORK FLAPPING TEST
Cycle network state 20 times in 10 seconds.
Assert worker scheduling does not spawn uncontrolled threads or duplicate executions.
---
# 212. FINDING REPORTING FORMAT
Every substantive finding must be documented using this exact template:
```text
ID:
Severity:
Category:
Confidence:
Status:
Feature:
Entity/Data type:
Local store:
Remote endpoint:
Worker/Repository:
File:
Relevant code:
Sync direction:
Source of truth:
Account scope:
Problem:
Evidence:
Sync Timeline:
T0:
T1:
T2:
T3:
Offline behavior:
Retry behavior:
Conflict behavior:
Expected final state:
Actual/Possible final state:
Data loss risk:
Duplicate risk:
Cross-user risk:
Root cause:
Recommended remediation:
Regression test:
Runtime verification:
Complexity:
XS / S / M / L / XL
```
---
# 213. SEVERITY CLASSIFICATION
Use these strict definitions:
## P0 - CRITICAL
- Cross-user data contamination through queued operations
- Catastrophic local or remote data loss / corruption
- Duplicate financial, transactional, or irreversible mutations
- Security and authentication boundary failure via sync workers
## P1 - HIGH
- Local user data silently dropped or permanently overwritten
- Retrying creates duplicate entities
- Offline mutations silently vanish upon sync
- Conflict resolution routinely overwrites newer data
- Queue lacks durability when product promises offline writes
## P2 - MEDIUM
- Substantial stale data or conflict issues with manual workaround
- Sync retry starvation or unhandled permanent failures
- Partial consistency failures of bounded scope
## P3 - LOW
- Minor offline sync edge cases
- Trivial freshness UI lag or cosmetic indicator mismatch
## P4 - IMPROVEMENT
- Architectural optimizations, enhanced batching, observability, or UX refinements without verified data correctness flaws
---
# 214. CONFIDENCE RATINGS
Use:
```text
HIGH
MEDIUM
LOW
```
HIGH:
Concrete code paths, data flows, or test evidence directly prove the failure.
MEDIUM:
Implementation logic clearly permits the failure, but runtime or server verification is incomplete.
LOW:
Dependent upon unverified backend contracts or edge production behaviors.
---
# 215. VERIFICATION STATUS
Use:
```text
CONFIRMED
LIKELY
THEORETICAL
NOT VERIFIED
```
---
# 216. BACKEND CONTRACT VERIFICATION STATUS
For findings dependent upon server semantics:
```text
SERVER CONTRACT:
VERIFIED
INFERRED
NOT VERIFIED
```
Never assume backend idempotency or conflict semantics without proof.
---
# 217. DATA LOSS CLASSIFICATION
For affected data:
```text
CACHE
SERVER-RECOVERABLE
LOCAL-ONLY
USER-GENERATED
IRREVERSIBLE ACTION
NOT VERIFIED
```
---
# 218. FALSE POSITIVE PREVENTION RULES
Before declaring P0, P1, or P2 findings, verify:
1. Room database schemas and indices
2. Repository query logic
3. Queue persistence mechanics
4. Worker constraints and execution paths
5. Server API contract documentation
6. Idempotency key usage
7. Account boundary isolation
8. Database transaction scopes
9. Retry policy constraints
10. Existing automated tests
Never infer architecture solely from a single `retry()` invocation.
---
# 219. AVOID DEFAULTING TO LAST WRITE WINS
LWW is acceptable for:
- User preferences
- Low-value transient state
Dangerous for:
- Text documents
- Inventory allocations
- Collaborative records
- Financial data
Always evaluate domain semantics.
---
# 220. TIMESTAMPS ARE NOT A UNIVERSAL FIX
Timestamps do not solve:
- Clock skew
- Concurrent field edits
- Lost responses
- Duplicate creations
---
# 221. DO NOT OVER-PRESCRIBE WORKMANAGER
WorkManager is designed for deferrable, persistent background work.
It is not a replacement for immediate interactive foreground requests.
---
# 222. RETRY SELECTIVITY
Retries are only appropriate when a failure is genuinely transient or after corrective recovery has completed.
---
# 223. DO NOT RELY SOLELY ON `isOnline`
Standard network requests must maintain robust fallback handling regardless of pre-flight checks.
---
# 224. NEVER BLINDLY DISCARD LOCAL DATA UPON CONFLICT
Resolving conflicts by blindly adopting server state and discarding user edits violates offline-first integrity unless explicitly required by domain rules.
---
# 225. DO NOT MODIFY CODE DURING THE AUDIT
Throughout the audit:
- Do not implement new queues
- Do not modify WorkManager configurations
- Do not inject timestamps
- Do not append versions
- Do not alter API contracts
- Do not add idempotency keys
- Do not rewrite merge logic
Complete the investigation first.
---
# 226. OUTPUT REPORT STRUCTURE - ANDROID_OFFLINE_SYNC_AUDIT.md
Structure the audit report:
## 1. Executive Summary
- Offline operational model
- Sync architecture overview
- Source of truth classification
- Durability posture
- Conflict resolution strategy
- Principal integrity risks
## 2. Data / Source-of-Truth Inventory
## 3. Sync Architecture Map
## 4. Offline Read Audit
## 5. Offline Write Audit
## 6. Pending Queue Audit
## 7. Queue Durability Audit
## 8. Idempotency Audit
## 9. Retry Audit
## 10. WorkManager Audit
## 11. Network Transition Audit
## 12. Pull Sync Audit
## 13. Push Sync Audit
## 14. Delta / Incremental Sync Audit
## 15. Conflict Detection Audit
## 16. Conflict Resolution Audit
## 17. Delete / Tombstone Audit
## 18. Local ID / Remote ID Audit
## 19. Attachment / File Sync Audit
## 20. Multi-Device Audit
## 21. Multi-Account / Logout Audit
## 22. Auth Expiry Audit
## 23. App Upgrade / Queue Compatibility
## 24. Observability Audit
## 25. Sync Test Coverage
## 26. Findings Summary
| ID | Severity | Data | Sync Stage | Problem | Confidence | Status |
|---|---|---|---|---|---|---|
## 27. P0 Findings
## 28. P1 Findings
## 29. P2 Findings
## 30. P3 Findings
## 31. P4 Improvements
## 32. Things Done Well
## 33. Unknown / Not Verified
## 34. Remediation Roadmap
---
# 227. ENTITY SYNC MATRIX
For every entity:
| Entity | Pull | Push | Queue | Conflict Model | Idempotent | Risk |
|---|---|---|---|---|---|---|
---
# 228. QUEUE OPERATIONAL MATRIX
| Operation | Durable | Account Scoped | Ordered | Retry Policy | Idempotent |
|---|---|---|---|---|---|
---
# 229. FAILURE RECOVERY MATRIX
| Failure Type | Retryable | User Action Required | Queue Retained | Risk |
|---|---|---|---|---|
Covering:
- No network
- Socket timeout
- HTTP 401
- HTTP 403
- HTTP 404
- HTTP 409
- HTTP 429
- HTTP 5xx
- Malformed response
---
# 230. CONFLICT MATRIX
| Conflict Scenario | Current Behavior | Data Loss Possible | User Visible | Verified |
|---|---|---|---|---|
---
# 231. ACCOUNT ISOLATION MATRIX
| Data / Operation | User Scoped | Cleared on Logout | Preserved for Retry | Cross-User Safe |
|---|---|---|---|---|
---
# 232. SECOND PASS - LOST RESPONSE ATTACK SCENARIO
For every remote write operation:
```text
request reaches server
↓
server successfully commits write
↓
response connection drops before reaching client
```
Evaluate:
> What exact sequence does the client execute next?
If the answer is:
```text
resends request blindly and duplicates entity
```
this is a major finding.
---
# 233. SECOND PASS - OLD RESPONSE ATTACK SCENARIO
For every pull operation:
```text
remote request dispatches
↓
user edits entity locally
↓
remote response arrives
```
Evaluate:
> Can the older incoming remote snapshot overwrite the newer local user edit?
---
# 234. SECOND PASS - SEVEN-DAY OFFLINE SIMULATION
Simulate a user remaining offline for an entire week:
- Generates dozens of local mutations
- Remote data evolves on server
- User permissions change remotely
- Application process restarts multiple times
Re-enable network.
Trace full convergence behavior.
---
# 235. SECOND PASS - TWO-DEVICE CONCURRENT EDIT SIMULATION
Simulate:
```text
Device A offline
Device B online
```
Apply conflicting modifications.
Evaluate:
> What final converged state does each device arrive at after complete synchronization?
---
# 236. SECOND PASS - LOGOUT MID-SYNC SIMULATION
Scenario:
```text
User A sync request dispatches
↓
User A logs out
↓
User B logs in
↓
User A response arrives
```
Inspect:
- Room database
- Queue state
- UI displays
- Auth headers
- Running workers
---
# 237. SECOND PASS - PROCESS DEATH AT CRITICAL JUNCTURES
Simulate process termination at:
```text
PENDING
IN_FLIGHT
AFTER_REMOTE_SUCCESS
BEFORE_LOCAL_ACK
```
Evaluate system recovery paths.
---
# 238. SECOND PASS - RETRY STORM SIMULATION
Seed a substantial backlog and simulate network restoration.
Evaluate:
- Number of scheduled workers
- Concurrent network requests
- Server burst load
- Client memory and battery drain
---
# 239. SECOND PASS - POISON PILL IN QUEUE
Inject an unrecoverable invalid operation midway through the queue.
Evaluate:
> Does it halt all subsequent independent operations?
If so:
Does domain ordering genuinely demand this block?
---
# 240. SECOND PASS - APP UPGRADE OVER ACTIVE QUEUE
Seed queue in an older version of the application.
Execute upgrade to latest version.
Evaluate:
- Can updated worker code parse legacy payloads?
- Does the server still accept legacy formats?
- Is account metadata preserved?
---
# 241. SECOND PASS - REMOTE DELETION COLLISION
The server deletes an entity while an offline client has an un-synced update pending for that entity.
Restore connectivity.
Evaluate:
> Does deletion prevail, does the update resurrect the entity, or does a conflict trigger?
---
# 242. SECOND PASS - ACKNOWLEDGEMENT RACE VERIFICATION
Verify:
```text
local edit A created
↓
dispatch A
↓
local edit B created
↓
receive acknowledgement for A
```
Must be audited for every high-value mutable entity.
---
# 243. SECOND PASS - FULL RESYNC RECOVERY
Simulate total local cache rebuild from backend.
Evaluate:
> What happens to un-synced dirty local mutations?
---
# 244. SECOND PASS - DEVICE CLOCK SKEW
Set device clock significantly forward or backward.
If sync relies on client timestamps for ordering, evaluate convergence outcome.
---
# 245. FINAL QUALITY GATE
Before publishing findings, verify:
- Offline model is established before recommending fixes
- Source of truth is explicitly mapped per entity
- Local saved and remotely synced states are not conflated
- Every write retry verifies idempotency mechanisms
- Lost-response scenarios are analyzed
- Queue survives process death
- In-flight orphan recovery is evaluated
- Conflict model is grounded in code, not assumed
- Server contract claims are classified verified/inferred/not verified
- Local edits during active pull requests are evaluated
- Stale acknowledgement overwriting fresh local edits is evaluated
- Deletion tombstones and retention are inspected
- Multi-device concurrency is evaluated where relevant
- Account switching cannot execute User A's queue under User B's token
- Auth expiration does not purge un-synced user data
- Permanent failures are separated from transient failures
- Connectivity booleans are not treated as reachability guarantees
- Queue growth and backlog scaling are analyzed
- App upgrades across active queues are evaluated
- WorkManager retries are not assumed to provide exactly-once delivery
- Architectural improvements (P4) are strictly separated from correctness bugs
---
# FINAL RULE
Do not deliver a report stating:
> Use Room, WorkManager, retries, and last-write-wins for offline support.
That is not an offline-first audit.
Seek concrete systemic failures such as:
```text
user creates item offline
↓
queue persists create mutation
↓
network reconnects
↓
server creates item
↓
response connection drops
↓
WorkManager retries creation
↓
server inserts duplicate item
```
or:
```text
sync request downloads entity v4
↓
user locally edits entity to v5 while request is in flight
↓
v4 response arrives
↓
repository blindly upserts remote entity
↓
user's v5 edit is lost
```
or:
```text
User A queues private mutation
↓
logs out
↓
User B logs in
↓
generic sync worker wakes
↓
uses current User B token
↓
dispatches User A mutation under User B account
```
or:
```text
delta sync receives 3 pages
↓
pages 1 and 2 written
↓
new sync token saved
↓
process crashes before page 3
↓
next sync starts after token
↓
page 3 changes are permanently skipped
```
or:
```text
local delete stored only by deleting row
↓
device remains offline
↓
sync engine later scans rows needing upload
↓
deleted row no longer exists
↓
remote entity is never deleted
```
or:
```text
local version A sent to server
↓
user changes local entity to B
↓
server confirms A and returns canonical entity A
↓
client replaces entire Room row
↓
newer local B is lost
```
These are the offline-first and sync failures you must uncover.
Think through:
- Source of truth
- Durability
- Queue semantics
- Operation identity
- Idempotency
- Retries
- Lost responses
- Conflicts
- Remote vs local revisions
- Process death
- Multiple devices
- Account boundaries
- Eventual convergence
For every substantive finding, you must answer:
> What modification occurred locally?
> Is it durable?
> What payload is dispatched to the server?
> What happens if the server succeeds but the response drops?
> What happens if the user modifies data again before an in-flight response returns?
> What happens if the process is terminated mid-sync?
> What happens if another device modifies the same entity?
> What happens if the user logs out and logs in with a different account?
If the answer cannot be proven:
**NOT VERIFIED.**
If server behavior is unknown:
**SERVER CONTRACT NOT VERIFIED.**
If it represents only an architectural enhancement without verified failure:
**P4 - IMPROVEMENT.**
Uncovering 5 genuine sync correctness defects with precise timelines is infinitely superior to writing 100 generic offline guidelines.
The goal is a forensically precise offline-first audit from which every substantive finding translates directly into:
- a deterministic failure scenario
- a queue and state-machine fix
- an idempotency defense
- a conflict resolution policy
- a regression test
- a process-death test
- a multi-account isolation test
- a production-safe synchronization architecture分类与标签
编程开发、安卓离线应用、同步队列、幂等重试、多设备冲突、进程终止恢复