Skip to content

fix(dashpay): don't check a pending invitation twice after a replaced one - #1325

Closed
llbartekll wants to merge 2 commits into
developfrom
fix/pending-invitation-vm-test-flake
Closed

llbartekll wants to merge 2 commits into
developfrom
fix/pending-invitation-vm-test-flake

Conversation

@llbartekll

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

PendingInvitationViewModelTests.testACheckFinishingForAReplacedInvitationIsDiscarded is flaky: it expects validator.calls == [linkA, linkB] and intermittently sees [linkA, linkB, linkB]. It failed once on CI ("DashWalletTests on simulator", on an unrelated PR) and reproduces locally at roughly 1 in 200 iterations.

The cause is in PendingInvitationViewModel, not in the test: the view model can validate the same pending invitation twice.

validateIfPossible checks the cached verdict and then spawns a task; runValidation never looks at the verdict again when that task actually runs. The failing order, taken from an instrumented run (everything on the main actor):

  1. Check A is running; the card is hidden and receive(linkB) spawns a task that waits for the stale check A.
  2. Check A finishes. The waiting task resumes first and starts check B, which answers.
  3. Check A's own task resumes only now. B is shown and no verdict is cached yet, so validateIfPossible spawns a third task.
  4. The second task stores B's verdict and clears validationTask.
  5. The third task starts, finds no check in flight, and checks B again.

The test's scripted validator answers instantly, which is what makes the window wide enough to hit. In production the same hole needs B's network check to finish before the third task starts, so it is rare; when it happens the cost is a redundant network check and the card showing "verifying" again while it runs.

What was done?

Before starting a check, runValidation now returns a fresh lastVerdict for the shown invitation instead of checking again. It is the same freshness test validateIfPossible applies before spawning the task, and the same one create uses for its cached path.

Callers that want a new check (recheck, create past the cache window or for an ineligible wallet, the end of a registration, a status change) clear lastVerdict first, so they are unaffected: any verdict present when the task runs is newer than their request.

One file, 8 lines. No test changes.

How Has This Been Tested?

Scheme dashwallet-dashpay, Debug, ARCHS=arm64 ONLY_ACTIVE_ARCH=YES, iOS 26.5 simulator, platform at .platform-ref.

Run Result
develop, the one test × 2000 iterations 11 failures
this branch, the one test × 2000 iterations 0 failures
this branch, whole PendingInvitationViewModelTests × 200 iterations (3800 tests) 0 failures

No dedicated regression test is added: the bad order depends on task scheduling and I found no deterministic way to force it, so the existing test under iteration is the guard. Not exercised in the running app.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • ADR (ADR-0001): no significant decision
  • Nothing in this PR (files, commit messages, branch name, description, comments, attachments, linked issues) holds customer data, unfixed vulnerability detail, secrets, or step-by-step attack detail against keys, PIN or encryption; such content is left out and handled privately with the maintainers (ADR-0001, rule 2)

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

… one

A check asked for while another check of the same invitation was running
could start after that check had already answered: `validateIfPossible`
saw no cached verdict and spawned the task, but `runValidation` never
looked at the verdict again once the task actually ran. With a stale
check finishing for a hidden-and-replaced invitation, the replacement
was then validated twice.

`runValidation` now returns a fresh verdict for the shown invitation
instead of starting a second check, the same test `validateIfPossible`
applies before spawning.

Fixes the flaky
PendingInvitationViewModelTests.testACheckFinishingForAReplacedInvitationIsDiscarded
(11 failures in 2000 iterations before, 0 in 2000 after).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 56 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: da947a55-0e9c-4b73-b609-4d96eae49443
Commits

Reviewing files that changed from the base of the PR and between 7defb24 and 67b1099.

Files selected for processing: 1

  • DashWallet/Sources/UI/DashPay/Invitations/PendingInvitationViewModel.swift
  • 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

@thepastaclaw

thepastaclaw commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🕓 Review not started yet because the new head is waiting for the 30-minute push debounce.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 58ba061. Normal review starts when eligible; priority review starts as soon as a slot is available.

@thepastaclaw thepastaclaw 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.

Final validation — Phase 1 + Phase 2

Verified the eight-line change at head 67b1099 against the base implementation, validation callers, scoped invitation model, and existing tests. The added cache check closes the duplicate-validation scheduling window while preserving explicit invalidation and the existing freshness policy; no in-scope defects were found. Current CI reports successful simulator tests, target-membership validation, and accessibility checks, with only the automated review pending; validation here was static, with no local builds or tests run.

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The diff adds a small, localized freshness guard that reuses an existing validation verdict without changing broader invitation behavior or a critical surface.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 99% left, weekly 99% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort medium); agent phase2-reviewer

develop gained the same guard in `runValidation` through #1339
(71642d9). The two sides conflicted only in the comment above it;
develop's wording is kept, so this branch's tree now equals develop.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@llbartekll

Copy link
Copy Markdown
Contributor Author

Superseded by #1339, which landed the same guard in runValidation on develop. After merging develop this branch has no diff left, so closing.

@llbartekll llbartekll closed this Nov 9, 2026
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