Skip to content

fix(sync): reuse a server token across sync runs - #1665

Open
A-EDev wants to merge 1 commit into
mainfrom
fix/sync2-reuse-token
Open

A-EDev wants to merge 1 commit into
mainfrom
fix/sync2-reuse-token

Conversation

@A-EDev

@A-EDev A-EDev commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Every sync run built a new ServerStore, and the token lived inside that instance, so each run signed in again (challenge + token): 138 sign-ins in 14 minutes in device testing. Issued tokens now live in a process-wide map keyed by server URL and device id, so the next run, including the next WorkManager run in the same process, reuses the token until a minute before it expires.

  • A held token is used only when it was issued for the instance and group this device pinned. If the server refuses it with a 401, the existing path signs in again once and retries once, and that path still detects InstanceChanged and SignInRefused.
  • The live channel still signs in afresh, as before.
  • Tokens are never logged or persisted.

No user-visible change, so no nightly note.

Related issue

None.

Change type

  • Bug fix
  • Feature
  • Refactor or maintenance
  • Build, packaging, or CI
  • Documentation

Validation

  • New test ServerStoreTest.the_next_store_reuses_the_token_until_it_nearly_expires:
    • two stores against a server whose token lasts long make one sign-in;
    • against a token expiring in 30 s, each store signs in.
      It failed before the fix (AssertionError at ServerStoreTest.kt:114, with app/src/main stashed) and passes after. The existing a_refused_token_is_renewed_once still passes.
  • ./gradlew --offline -Dorg.gradle.jvmargs="..." :app:testGithubDebugUnitTest --tests 'io.github.aedev.flow.sync2.*': 227 tests, 0 failures.
  • ./gradlew --offline ... ktlintCheck: exit 0.
  • ./gradlew :app:assembleGithubDebug: not run separately (the test task compiled the github debug sources).
  • I manually tested the affected behavior on an Android device or emulator: not yet; part of the Phase 7 device test round.

Test device and Android version: none yet.

Risk and compatibility

Fewer requests. A token the server no longer accepts (device removed, server reset) gets the same 401 handling as before.

  • The change does not introduce secrets, private data, or unexpected telemetry.
  • New user-facing text uses Android string resources.
  • Dependency and lockfile changes are intentional and limited to this PR.
  • Room schema changes include the required version bump and migration, or this PR does not change the Room schema.
  • Breaking changes and upgrade steps are clearly documented.

Copilot AI balanced review requested due to automatic review settings November 2, 2026 22:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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.

2 participants