Repository navigation
feat: sync the event buffer to the server - #16
Merged
Merged
Conversation
markUnauthenticated() drops the token after a 401 so no further device request is made; the remaining server URL makes the app ask to pair again. A failed token save no longer leaves a server URL behind. One DeviceSetup per process so pairing and sync share its lock.
Events leave the buffer once the server accounts for them (accepted, duplicate or rejected; only reason codes are logged). 401 stops and asks to pair again, 429, network failures and server errors keep the buffer. device/me reports the clock skew once per app start.
Hourly while a network is connected, with exponential backoff after a failure; no Wi-Fi detection, so home networks, Tailscale and public servers all work. After a 429 no request is made from any path until Retry-After has passed.
The app checks the device and syncs right away when opened, then says in words when it last synced, how many entries are waiting, and whether the device clock is off by more than the server tolerates.
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.
Closes #13
What
Uploads the local event buffer whenever the server is reachable.
Triggers:
There is no Wi-Fi detection, so the home network, Tailscale and public servers all work the same way. An unreachable server leaves the buffer for the next attempt.
Each run collects new usage first, then uploads the buffer in batches of 500 events. 500 events stay far below 512 KiB.
Events leave the buffer once the server accounts for them:
accepted,duplicate, orrejected. For rejected events only the reason code and a count are logged.429: the buffer is kept. No request is made from any path (app open, periodic run, retry) until
Retry-Afterhas passed, then a single delayed attempt runs.401: the token is dropped and the server URL is kept, so the app shows "Pair this device again". No further device requests and no timer retry; the buffer and collection are kept.
GET /api/v1/device/me: once per app start for the clock skew, never on a timer.Connected screen: says in words when the device last synced or why it could not, how many entries are waiting, and warns when the device clock is off by more than 5 minutes.
Other changes
DeviceSetupis one instance per process, so pairing, sync and the 401 handling share its lock.Security / privacy relevant
Tests
EventSyncTestruns against an HTTPS MockWebServer and covers:/device/meclock skew and 401The cross-path
Retry-Aftergate and WorkManager scheduling depend on Android and are not unit tested. Nothing has been run on a device yet. There are no new dependencies and the Room schema is unchanged.