Harden participant completion flow against latency and write races#1186
Harden participant completion flow against latency and write races#1186
Conversation
|
🪓 PR closed, deleted preview. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the participant completion path under latency by introducing a serialized participant-data write queue, an explicit finalizeParticipant() flow that waits for pending writes/uploads and validates persisted state, and UI retry logic on the study end screen.
Changes:
- Replace throttled answer saving with a queued/debounced participant-data persistence chain plus
flushPendingParticipantData(). - Add
finalizeParticipant()to gate completion on converged answer persistence + finished asset uploads, and patch progress updates to avoid clobbering completion. - Introduce a StudyEnd finalization/retry loop utility and update StudyEnd UI + tests to use it.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/storage/tests/highLevel.spec.ts | Adds high-level regression tests for delayed writes/uploads and completion/progress preservation. |
| src/storage/engines/types.ts | Implements participant-data write queue, asset upload tracking, and finalizeParticipant(); updates progress patching behavior. |
| src/storage/engines/SupabaseStorageEngine.ts | Adds _getSequenceAssignment() for finalize/progress logic. |
| src/storage/engines/LocalStorageEngine.ts | Adds _getSequenceAssignment() for finalize/progress logic. |
| src/storage/engines/FirebaseStorageEngine.ts | Adds _getSequenceAssignment() for finalize/progress logic. |
| src/components/StudyEnd.utils.ts | New finalize/retry loop helper for StudyEnd. |
| src/components/StudyEnd.utils.spec.ts | Tests finalize loop backoff, no-overlap requests, and manual retry gating. |
| src/components/StudyEnd.tsx | Switches completion verification to finalize loop; improves retry/error UX and adds manual download fallback. |
| src/components/StudyEnd.spec.tsx | Adds a basic render test with updated Mantine mocks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…g for answer saving
Does this PR close any open issues?
Towards #1182
Give a longer description of what this PR addresses and why it's needed
This PR makes study completion robust under high latency and slow uploads by replacing the old throttled answer-save path with a serialized participant-data write queue and an explicit finalizeParticipant() flow. Completion now waits for pending participant-data writes and asset uploads, verifies local and persisted answers match, rejects false zero-answer completions, and only marks a participant complete once storage and realtime state are both confirmed.
It also fixes realtime progress updates so they patch only progress fields instead of rewriting the full sequence-assignment document, which prevents late progress writes from clobbering completion state or causing answered-count drift. On the UI side, the study end screen now uses the explicit finalization result to retry only while writes are still converging and to show a terminal error message when uploads actually fail.
Provide pictures/videos of the behavior before and after these changes (optional)
Are there any additional TODOs before this PR is ready to go?
No