Skip to content

[PM-42224] fix: Retry transient login-with-device poll failures before showing an error - #7602

Open
aj-rosado wants to merge 2 commits into
mainfrom
poc/PM-42224
Open

aj-rosado wants to merge 2 commits into
mainfrom
poc/PM-42224

Conversation

@aj-rosado

Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-42224

📔 Objective

While a login-with-device request waits for approval, AuthRequestManagerImpl.createAuthRequestWithUpdates polls the server every 4 seconds. Any single failed poll emitted CreateAuthRequestResult.Error, so a brief network interruption (for example while the app is backgrounded) showed an error even though the request could still be approved a moment later.

This change treats poll failures as transient: they are retried, and an error is emitted once after 3 consecutive failures (MAX_CONSECUTIVE_POLL_FAILURES). A successful poll resets the counter, and polling continues after the error so a later poll can still recover, as before.

Tests: three new cases in AuthRequestManagerTest — a single transient failure is retried without an Error, repeated failures emit exactly one Error and then recover, and the failure count resets after a successful poll.

🤖 AI-assisted review

  • The initial fix was drafted by an automated bug-smasher run, then amended by the author (retry threshold of 3 instead of 5) and formatted by detekt.
  • Local code review (Standard, code-review-local) of the branch: APPROVE, no findings. It covered the branch except a final one-line trailing-comma formatting amend.
  • Preflight: AuthRequestManagerTest (36 tests) and detekt pass.
  • Open question from the reviewer, not raised as a finding: polls run every 4 seconds, so 3 failures take about 12 seconds. A longer outage while the app is backgrounded still shows the error (it clears on the next successful poll, as before). Whether this resolves the original repro on a device is not covered by these tests.

bug-smasher and others added 2 commits November 6, 2026 16:32
…n request while… [bug-smasher poc]

Automated fix from the bug smasher. Proof: ./gradlew :app:testStandardDebugUnitTest --tests "*AuthRequestManagerTest*" must fail on base and pass with the fix.
Signed-off-by: Andre Rosado <arosado@bitwarden.com>
@aj-rosado aj-rosado added the ai-review Request a Claude code review label Nov 10, 2026
@github-actions github-actions Bot added app:password-manager Bitwarden Password Manager app context t:bug Change Type - Bug labels Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR changes AuthRequestManagerImpl.createAuthRequestWithUpdates so a failed login-with-device poll no longer emits CreateAuthRequestResult.Error right away. At the current head, MAX_CONSECUTIVE_POLL_FAILURES is 3, so the error is emitted once, on the third consecutive failure. Any successful poll resets the counter, polling continues after the error, and the approved, declined, and expired terminal states work as before. The three new AuthRequestManagerTest cases match the threshold of 3: a single transient failure, five failures that produce exactly one Error and then recover, and two failure streaks of two separated by a pending poll, which produce no Error.

@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.85%. Comparing base (5a5399f) to head (95bfbae).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7602      +/-   ##
==========================================
+ Coverage   86.82%   86.85%   +0.03%     
==========================================
  Files         896      898       +2     
  Lines       65805    65204     -601     
  Branches     9411     9377      -34     
==========================================
- Hits        57135    56636     -499     
+ Misses       5188     5097      -91     
+ Partials     3482     3471      -11     
Flag Coverage Δ
app-data 18.99% <100.00%> (+0.28%) ⬆️
app-ui-auth-tools 18.75% <0.00%> (+0.14%) ⬆️
app-ui-platform 16.02% <0.00%> (-0.45%) ⬇️
app-ui-vault 27.02% <0.00%> (+0.05%) ⬆️
authenticator 6.06% <0.00%> (+0.04%) ⬆️
lib-core-network-bridge 4.16% <0.00%> (+0.03%) ⬆️
lib-data-ui 1.33% <0.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aj-rosado
aj-rosado marked this pull request as ready for review November 11, 2026 15:01
@aj-rosado
aj-rosado requested review from a team and david-livefront as code owners November 11, 2026 15:01
val authRequest: AuthRequest,
)

private fun pollPendingJson() = AuthRequestsResponseJson.AuthRequest(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The pattern we usually follow it to make these private helper classes and functions be top-level at the bottom of the file.

Looks like the setUpPollFailureScenario function needs to be in the test class, but can you move it to the bottom.

// they are retried and only surfaced once after repeated consecutive
// failures. Polling continues so a later success can still recover.
consecutiveFailures++
if (consecutiveFailures == MAX_CONSECUTIVE_POLL_FAILURES) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this be consecutiveFailures >= MAX_CONSECUTIVE_POLL_FAILURES

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review app:password-manager Bitwarden Password Manager app context t:bug Change Type - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants