Skip to content

fix(dashpay): check a replacement invitation once, not twice - #1339

Merged
romchornyi merged 1 commit into
developfrom
fix/invitation-duplicate-check
Nov 9, 2026
Merged

romchornyi merged 1 commit into
developfrom
fix/invitation-duplicate-check

Conversation

@romchornyi

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

PendingInvitationViewModelTests.testACheckFinishingForAReplacedInvitationIsDiscarded fails now and then: it failed on CI for #1257 (a PR that does not touch invitations) and passed on a rerun. The test is right. The view model sends a replacement invitation to the network twice, and the test catches the duplicate ([linkA, linkB, linkB] instead of [linkA, linkB]).

What was done?

When an invitation is hidden while its check runs and another one takes its place, two callers of runValidation wait for the stale check to end: the one started by the store's change, and the one the stale check starts itself when it sees a replacement. If one of them checked the replacement and finished before the other woke, the other found no check running and started a second one.

runValidation now returns the verdict already reached for the same invitation, while it is fresh (validationLifetime). The callers that want a new check (recheck, create) clear lastVerdict before they call it, so they still get one.

The user saw the right card either way; the second check was an extra network request.

How Has This Been Tested?

The failing test reproduces the race locally when repeated (-test-iterations 1000 -run-tests-until-failure, iPhone 17 simulator, Debug):

  • before the fix: failed at iteration 777 with the same assertion as on CI;
  • after the fix: 3,000 iterations, 0 failures.

InvitationValidationPolicyTests, PendingInvitationStoreTests and PendingInvitationViewModelTests: 78 tests, 0 failures. The full suite runs on CI.

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
  • I have assigned this pull request to a milestone

The existing test is the regression test; no new one, since the race needs the scheduler's ordering and cannot be forced from the test.

🤖 Generated with Claude Code

When an invitation is hidden while its check runs and another one takes
its place, two callers wait for the stale check: the store's change and the
stale check's own end. If one of them checked the replacement and finished
before the other woke, the other found no running check and asked the
network again. runValidation now returns the fresh verdict for the same
invitation instead.

Co-Authored-By: Claude Opus 5.5 <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 12 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: 863dd712-dc66-4b2e-8e10-d8c8e3e67be9
Commits

Reviewing files that changed from the base of the PR and between f896b98 and 6b1f491.

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

✅ Final review complete — no blockers (commit 6b1f491) · triage: low

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

Approving.

Checked against the full PendingInvitationViewModel at 6b1f491:

  • After the await on the stale check, the new guard re-checks what validateIfPossible checks before it starts a caller: a fresh verdict means no new check. It also requires the same invitation, so a verdict for A never answers B. This is the usual fix for main-actor reentrancy: re-check state after a suspension.
  • Callers that want a new check still get one. recheck(), create(), the registration-ended sink and the status-update observer all set lastVerdict = nil first. The not-ready and removal-failed paths store .undetermined, which validateIfPossible already treated as fresh.
  • The early return skips nothing: no state changes in this call before it, and the caller that stored the verdict already refreshed the card.

Non-blocking:

  • Suppose the status-update observer sets lastVerdict = nil while a check that started earlier is still finishing. The next caller can now take that earlier verdict instead of starting a new check. The join on line 302 already allowed this while such a check was running, so the guarantee barely changes, and create() re-checks eligibility synchronously. If it ever matters, a generation counter would close both cases: bump it on each invalidation and store it with the verdict.
  • The freshness check now appears three times (lines 254, 294 and 320). A small helper would keep the three copies in sync.

When I looked, Unit tests (dashpay) was still queued. I didn't run the tests locally.

@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

The six-line change at 6b1f491 closes the duplicate-validation window by reusing a fresh verdict for the same invitation after competing callers finish waiting. Static inspection of the validation lifecycle, cache invalidation, wallet/network scoping, and existing regression test found no introduced defects. Current exact-head CI confirms simulator tests, test-target membership, and accessibility checks pass; no builds or tests were run locally.

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 check to reuse an existing invitation verdict and prevent duplicate validation requests without changing 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 96% 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

@romchornyi
romchornyi merged commit 71642d9 into develop Nov 9, 2026
5 checks passed
llbartekll added a commit that referenced this pull request Nov 9, 2026
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>
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