Skip to content

fix(auth): ignore stale password reset polls - #1378

Merged
khaira777 merged 4 commits into
mainfrom
fm/flocafe-recover-poll-supersede-guard
Oct 26, 2026
Merged

khaira777 merged 4 commits into
mainfrom
fm/flocafe-recover-poll-supersede-guard

Conversation

@khaira777

@khaira777 khaira777 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Track a pollGeneration counter in RecoverAccessPage (frontend/src/app/auth/recover/page.tsx), incrementing it and resetting pollInFlight.current in stopPolling() and invoking stopPolling() at the start of requestEmailReset().
  • Guard requestEmailReset() state updates, error handling, loading cleanup, and both the email verification and reset status polling callbacks against stale pollGeneration values, and clear loading when switching recovery methods.
  • Add regression tests in tests/cloud-password-recovery.test.ts verifying 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/recover alongside npm 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 and pollInFlight is cleanly reset.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Owner resends an email password-reset request while a status poll for the previous reset is in-flight; when the superseded poll resolves approved, the UI stays in the waiting state, continues polling… ✅ pass live ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario1-after-superseded-poll.png, ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario1-reset-b-app…
Adversarial: Owner resends while an email-verification poll is in-flight (which then resolves verified: true) and resends again while a status poll is in-flight (which then resolves status: expired);… ✅ pass live ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario2-superseded-verify-and-expired-ignored.png, ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/live-…
Adversarial: Owner clicks 'Email me a reset link' and switches to the 'Master PIN' tab while the email request is still in-flight; loading state is immediately cleared so the Master PIN submit button… ✅ pass live ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario3-method-switch-pin-ready.png, ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/live-verification-r…

Scenario 1 - Recover screen stays on waiting state after superseded status poll returns approved
Scenario 1 - Recover screen transitions to password form after active reset-B poll is approved
Scenario 1 - Successful password reset completion redirects to sign-in screen
Scenario 2 - Superseded verification poll and expired status poll are ignored while active reset continues waiting
Scenario 3 - Switching to Master PIN while email reset request is in-flight clears loading state and enables submit button

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 } } }

{
  "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"
      ],
      "screenshots": [
        "~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario1-after-superseded-poll.png",
        "~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario1-reset-b-approved.png",
        "~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario1-complete-redirect-login.png"
      ]
    },
    "scenario2": {
      "requestCountAfterManualResend": 3,
      "requestCountAfterSupersededVerify": 3,
      "waitingResendStillVisible": true,
      "expiredErrorVisible": false,
      "polledReset4AfterStaleExpired": true,
      "statusPollSequence": [
        "reset-live-0003",
        "reset-live-0004"
      ],
      "screenshot": "~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario2-superseded-verify-and-expired-ignored.png"
    },
    "scenario3": {
      "submitBtnDisabledAfterSwitch": false,
      "pinInputVisibleAfterStaleEmailResolved": true,
      "backgroundPollsForStaleEmail": 0,
      "pinRecoverHttpStatus": 200,
      "pinPasswordUpdatedInSqlite": true,
      "screenshot": "~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario3-method-switch-pin-ready.png"
    }
  }
}

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 - requestEmailReset now guards setLoading(false) in its finally block with pollGeneration.current === generation (frontend/src/app/auth/recover/page.tsx:140), while stopPolling() increments pollGeneration.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) while api.post('/auth/recover-password/cloud/request') is in flight, stopPolling() increments pollGeneration.current without resetting loading to false. When the superseded requestEmailReset request settles, its finally block skips setLoading(false), leaving loading permanently stuck at true and 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). Reset setLoading(false) when cancelling via the method-switch handler at frontend/src/app/auth/recover/page.tsx:300 (and call stopPolling() before setLoading(true) in requestEmailReset at frontend/src/app/auth/recover/page.tsx:75-76).

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Owner resends an email password-reset request while a status poll for the previous reset is in-flight; when the superseded poll resolves approved, the UI stays in the waiting state, continues polling… ✅ pass live ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario1-after-superseded-poll.png, ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario1-reset-b-app…
Adversarial: Owner resends while an email-verification poll is in-flight (which then resolves verified: true) and resends again while a status poll is in-flight (which then resolves status: expired);… ✅ pass live ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario2-superseded-verify-and-expired-ignored.png, ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/live-…
Adversarial: Owner clicks 'Email me a reset link' and switches to the 'Master PIN' tab while the email request is still in-flight; loading state is immediately cleared so the Master PIN submit button… ✅ pass live ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/scenario3-method-switch-pin-ready.png, ~/.no-mistakes/evidence/01M5WGSH1YX6CF4FTDHT1A7M58/live-verification-r…
  • npm run test:cloud-password-recovery
  • npm run build && npm run build:frontend (built backend and static frontend for live server execution, then cleaned transient build outputs)
  • Live Playwright Chromium verification against dist/main/server.js on http://127.0.0.1:43101/auth/recover driving 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

  • Bug Fixes
    • Password recovery now ignores outdated requests and status updates after you switch recovery methods or start a new recovery attempt. This prevents stale results from changing the current recovery step or loading state.
    • Status checks now remain tied to the reset request they belong to, so an earlier request won’t interfere with a replacement.
  • Tests
    • Added coverage for recovery flows involving pending requests, verification, and status checks.

Ignore superseded password-reset polling responses and reset poll in-flight status when resending recovery requests. Fixes #1370
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8282f3a and a4799c3.

Files selected for processing: 2
  • frontend/src/app/auth/recover/page.tsx
  • tests/cloud-password-recovery.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

The recovery page now invalidates stale recovery requests and polling callbacks when polling stops or a new request begins. Tests cover pending requests during recovery-method changes and resends.

Changes

Password recovery polling

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: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed 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…
Description check Passed The description follows the template's main sections: Intent (related issue #1370 and the summary of the change), What Changed, Risk Assessment, and Testing with commands and live verification results…
Linked Issues check Passed 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:
- st…
Out of Scope Changes check Passed 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 pollIn…
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 #1370 and 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777 khaira777 changed the title fix(auth): ignore superseded password-reset polling responses fix(auth): ignore stale password reset polls Oct 26, 2026
@khaira777
khaira777 enabled auto-merge (squash) October 26, 2026 18:24
@khaira777
khaira777 merged commit 8b76b0b into main Oct 26, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-recover-poll-supersede-guard branch October 26, 2026 18:31
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.

fix(auth): password recovery resend does not ignore superseded status polls

1 participant