Repository navigation
fix(dashpay): check a replacement invitation once, not twice - #1339
Conversation
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>
|
Warning Review limit reachedYou'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. View limit details
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. |
|
✅ Final review complete — no blockers (commit 6b1f491) · triage: low |
llbartekll
left a comment
There was a problem hiding this comment.
Approving.
Checked against the full PendingInvitationViewModel at 6b1f491:
- After the
awaiton the stale check, the new guard re-checks whatvalidateIfPossiblechecks 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 setlastVerdict = nilfirst. The not-ready and removal-failed paths store.undetermined, whichvalidateIfPossiblealready 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 = nilwhile 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, andcreate()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
left a comment
There was a problem hiding this comment.
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:
lowbygpt-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); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 96% left, weekly 99% left; passed overgemini-3.8-flash-high(antigravity quota lookup failed) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort medium); agentphase2-reviewer
Issue being fixed or feature implemented
PendingInvitationViewModelTests.testACheckFinishingForAReplacedInvitationIsDiscardedfails 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
runValidationwait 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.runValidationnow returns the verdict already reached for the same invitation, while it is fresh (validationLifetime). The callers that want a new check (recheck,create) clearlastVerdictbefore 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):InvitationValidationPolicyTests,PendingInvitationStoreTestsandPendingInvitationViewModelTests: 78 tests, 0 failures. The full suite runs on CI.Breaking Changes
None.
Checklist:
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