Skip to content

Fix multi-account switching during authentication and auto-sync - #169

Merged
anod merged 7 commits into
masterfrom
fix/account-selection-handoff
Sep 30, 2026
Merged

anod merged 7 commits into
masterfrom
fix/account-selection-handoff

Conversation

@anod

@anod anod commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Preserve the latest explicit Google account selection across Main and Search, even if an earlier automatic request is queued behind running initialization. AuthAccountInitializer now tracks all in-flight initializations and cancels/joins running and queued predecessors before an explicit selection; a real sync remains fail-fast. The redundant ViewModel-level waiting helper was removed.
  • Refresh Main's displayed account on return from Search, where a modal picker can switch accounts while Main remains alive.
  • Finish auto-sync scheduling after WorkManager reaches a terminal state instead of keeping an initialization job active indefinitely.
  • Add Robolectric regressions for bidirectional and rapid switches, cross-screen initialization, A → queued automatic request → explicit B, Main → Search automatic resume, return to Main, and auto-sync. Reuse Search test helpers rather than duplicating event and wait logic. Includes the Gradle priority change requested alongside the original fix.

Validation

  • Latest PR Android CI: build and Compose dependency alignment passed; uploaded unit-test report shows 181 tests, 0 failures. CodeQL passed.
  • :app:testDebugUnitTest and :app:ktlintCheck passed locally. The A → queued X → B cancellation test failed before the fix and passed after it.
  • Advisory instrumentation reports 1 failure out of 3 tests: SearchSurfacesUiTest could not find the "Settings" drawer menu. Its check appears green because the test step uses continue-on-error; the earlier PR run reported the same UI-test failure, and the pre-PR master run had startup Compose-hierarchy failures.

Copilot AI added 3 commits September 30, 2026 09:50
Prioritize explicit account selections over in-flight authentication on the main and search screens. Add regression tests for multi-account switching and include the Gradle priority setting.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Share a cancellation-safe initialization handoff between Main and Search, finish scheduling when WorkManager reaches a terminal state, and cover rapid account changes with auto-sync enabled.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 07:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Account selections can still be dropped when initialization is active in the other view model.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Improves account-switch handoffs during authentication and ensures auto-sync scheduling terminates correctly.

Changes:

  • Serializes rapid account selections with cancellation-safe handoffs.
  • Stops waiting after WorkManager reaches a terminal state.
  • Adds Robolectric coverage and WorkManager test support.
File Description
AccountInitialization.kt Adds account-initialization handoff helper.
MainViewModel.kt Uses handoff and terminal sync state.
SearchViewModel.kt Applies handoff to search authentication.
AccountSelectionViewModelTest.kt Adds account-switch regressions.
app/​build.gradle.kts Adds WorkManager testing dependency.
libs.versions.toml Defines WorkManager testing artifact.
gradle.properties Lowers Gradle process priority.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread app/src/main/java/com/anod/appwatcher/search/SearchViewModel.kt Outdated
Cancel and join an in-flight initializer when the modal account picker returns a new choice from another screen. Refresh the main drawer account on resume, and cover picker handoff with deterministic Robolectric tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Cross-view-model cancellation and Play session serialization remain timing-sensitive despite focused regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 14:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

A queued automatic initialization can mask the running job, allowing stale account work to complete before the latest explicit selection.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Comment thread app/src/main/java/com/anod/appwatcher/accounts/AuthAccountInitializer.kt Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The concurrency changes are covered by focused regressions, unit CI passes, and the instrumentation failure is pre-existing.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 15:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The concurrency behavior is coherently coordinated, regression-tested, and the relevant CI checks passed.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@anod
anod merged commit 8a3fa72 into master Sep 30, 2026
5 checks passed
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.

3 participants