Repository navigation
fix(auth): ignore stale password reset polls - #1378
Conversation
Ignore superseded password-reset polling responses and reset poll in-flight status when resending recovery requests. Fixes #1370
…ord recovery polling guard
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
Generation-scoped recovery lifecycle frontend/src/app/auth/recover/page.tsx, tests/cloud-password-recovery.test.ts |
The recovery page ignores request and polling responses from prior generations and clears the in-flight flag only for the active generation. Tests cover method-switch and resend races, including a later poll that approves the replacement reset. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related PRs
- FreeOpenSourcePOS/FloCafe#1310: Adds the cloud email-recovery flow that this change updates with stale-response handling and race tests.
- FreeOpenSourcePOS/FloCafe#1330: Updates backend recovery endpoints used by the frontend flow addressed here.
Merge Risk: 
Minimal · up to a4799
-
No actionable password-recovery polling risk remains. The change is ready to merge after normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title "fix(auth): ignore stale password reset polls" matches the main change. The PR adds a generation counter so superseded reset requests and poll responses are ignored. It also clears in-flight polling and loading state. The title is short, specific, and uses conventional commit form.
Full details: Description check
-
Explanation
The description follows the template's main sections: Intent (related issue
#1370and the summary of the change), What Changed, Risk Assessment, and Testing with commands and live verification results. It also contains a pipeline attestation. Several template sections are missing: the Scope section, the Compatibility & data safety section, the Cross-cutting surfaces table, the Developer documentation checkboxes, and the Contributor checklist. The description does not use the template headings, so the mapping to the template is partial. The core required information is present.Resolution
Consider adding the missing template sections for clarity: Scope (what is out of scope), Compatibility & data safety (database, migration, user-visible, and offline impact), Cross-cutting surfaces (for example UI and RTL), and the Developer documentation and Contributor checklist items. Consider also using the template headings (Related work, Summary, Verification) so reviewers can find each item.
Full details: Linked Issues check
-
Explanation
Requirement group [
#1370]: ignore superseded status and verification poll responses, and reset pollInFlight when polling stops or restarts. Source at head, frontend/src/app/auth/recover/page.tsx:- stopPolling() (line ~48) now increments pollGeneration and sets pollInFlight.current = false. It runs at the start of requestEmailReset(), so each restart begins with a clear in-flight flag.
- requestEmailReset() captures generation after stopPolling(). It ignores the response and skips setState updates when pollGeneration differs. This covers the request response, error path, and loading cleanup.
- The verification poll callback and the status poll callback each check pollGeneration !== generation before acting on a response. A stale 'approved' result cannot set emailStep to 'approved'.
- The status poll uses expectedResetId, captured when the reset is created, for its reset_id parameter.
- The finally blocks in both poll callbacks clear pollInFlight only when the generation is still current. A superseded poll cannot clear the flag of its replacement poll.
- Switching recovery methods calls stopPolling() and setLoading(false). This prevents loading from staying true when a superseded request is ignored.
The issue does not require tests. The PR also adds a UI race test in tests/cloud-password-recovery.test.ts (per the change summary). The visible part of that file, which is truncated, covers backend routes only. I could not confirm the UI test body from source. This does not change the verdict, because the behavior requirement is met in the page source.
Full details: Out of Scope Changes check
-
Explanation
All source changes at head are in frontend/src/app/auth/recover/page.tsx. Each change maps to
#1370:- pollGeneration counter and stopPolling() reset: implement superseded-response handling and pollInFlight reset.
- Generation guards in requestEmailReset() and both poll callbacks: implement ignoring of stale responses.
- expectedResetId in the status poll: binds each status poll to the reset it started for, which supports the stale-reset requirement.
- setLoading(false) in the method-switch handler: needed because stopPolling() now invalidates the request that would otherwise clear loading.
The test file tests/cloud-password-recovery.test.ts is supporting test coverage for the same behavior (per the change summary). The PR description's live Playwright scenarios and build steps are verification activities. They add no repository changes. No unrelated code change was found in the reviewed evidence.
-
-
Finishing Touches: 💡 1
-
📝 Generate docstrings: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Intent
Fix the P2 release-readiness issue from PR #1310 (#1310) at frontend/src/app/auth/recover/page.tsx:80-125: ignore superseded password-reset polling responses. When the owner resends an email password-reset request on the recover screen, stopPolling() clears the interval timer but does not reset pollInFlight.current or invalidate an in-flight status poll or verification poll from the previous reset request. If the superseded request resolves (for example, returning approved for the old reset_id after resetId has been replaced by the new request), it transitions emailStep to approved while resetId holds the unapproved new reset, causing password submission to fail with 409, or leaves pollInFlight.current stuck. Ignore any superseded polling response and reset pollInFlight when polling stops or restarts.
Fixes #1370
What Changed
pollGenerationcounter inRecoverAccessPage(frontend/src/app/auth/recover/page.tsx), incrementing it and resettingpollInFlight.currentinstopPolling()and invokingstopPolling()at the start ofrequestEmailReset().requestEmailReset()state updates, error handling,loadingcleanup, and both the email verification and reset status polling callbacks against stalepollGenerationvalues, and clearloadingwhen switching recovery methods.tests/cloud-password-recovery.test.tsverifying that superseded in-flight reset requests, verification polls, and status polls are ignored when switching recovery methods or resending.Risk Assessment
✅ Low: The change is well-bounded to guarding password recovery requests and polling callbacks with a generation counter and resetting in-flight and loading state when polling stops or recovery methods switch, with direct regression test coverage.
Testing
Built the backend and static Next.js frontend, stood up an isolated FloCafe Express server and SQLite database on port 43101, and drove three live Playwright Chromium scenarios on
/auth/recoveralongsidenpm run test:cloud-password-recovery(expanded to cover verification-poll supersede), capturing screenshots and structured verification logs confirming that superseded status/verification polls and in-flight requests on method switch are ignored andpollInFlightis cleanly reset.Evidence: Live browser verification report (JSON)
{ "scenarios": { "scenario1": { "heldSupersededResetId": "reset-live-0001", "resendStillVisibleAfterStaleApproval": true, "passwordInputVisibleAfterStaleApproval": false, "completedResetIdSentByBrowser": "reset-live-0002", "completeHttpStatus": 200, "redeemedResetIdsOnBackend": ["reset-live-0002"], "passwordUpdatedInSqlite": true, "statusPollSequence": ["reset-live-0001", "reset-live-0002"] }, "scenario2": { "requestCountAfterManualResend": 3, "requestCountAfterSupersededVerify": 3, "waitingResendStillVisible": true, "expiredErrorVisible": false, "polledReset4AfterStaleExpired": true, "statusPollSequence": ["reset-live-0003", "reset-live-0004"] }, "scenario3": { "submitBtnDisabledAfterSwitch": false, "pinInputVisibleAfterStaleEmailResolved": true, "backgroundPollsForStaleEmail": 0, "pinRecoverHttpStatus": 200, "pinPasswordUpdatedInSqlite": true } } }Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
frontend/src/app/auth/recover/page.tsx:140-requestEmailResetnow guardssetLoading(false)in itsfinallyblock withpollGeneration.current === generation(frontend/src/app/auth/recover/page.tsx:140), whilestopPolling()incrementspollGeneration.current(frontend/src/app/auth/recover/page.tsx:48). If the user clicks a recovery-method toggle button (frontend/src/app/auth/recover/page.tsx:300) whileapi.post('/auth/recover-password/cloud/request')is in flight,stopPolling()incrementspollGeneration.currentwithout resettingloadingtofalse. When the supersededrequestEmailResetrequest settles, itsfinallyblock skipssetLoading(false), leavingloadingpermanently stuck attrueand disabling both the PIN submit button (frontend/src/app/auth/recover/page.tsx:390) and the email send button (frontend/src/app/auth/recover/page.tsx:327). ResetsetLoading(false)when cancelling via the method-switch handler atfrontend/src/app/auth/recover/page.tsx:300(and callstopPolling()beforesetLoading(true)inrequestEmailResetatfrontend/src/app/auth/recover/page.tsx:75-76).🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
npm run test:cloud-password-recoverynpm run build && npm run build:frontend(built backend and static frontend for live server execution, then cleaned transient build outputs)Live Playwright Chromium verification againstdist/main/server.jsonhttp://127.0.0.1:43101/auth/recoverdriving Scenario 1 (in-flight status poll superseded by resend), Scenario 2 (in-flight verification poll and expired status poll superseded by resend), and Scenario 3 (in-flight email request superseded by switching to Master PIN)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Summary by CodeRabbit