Premium Analytics: harden sync stall detection against finished/milestone read gap - #49651
Premium Analytics: harden sync stall detection against finished/milestone read gap#49651chihsuan wants to merge 1 commit into
Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
b4948f7 to
0ab9f02
Compare
…d gap instead of stalling
0ab9f02 to
fa9898e
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens @automattic/jetpack-premium-analytics-site-sync sync stall detection to avoid a false “stalled” state when a poll observes finished/100% progress before the initial_full_sync_finished milestone becomes visible.
Changes:
- Treat
percentage >= 100 && initialFullSyncFinished === 0as a “finishing” state (not stalled) so polling continues through a transient read gap. - Add unit and hook-level tests covering the read-gap case and confirming a real sub-100% stalled state still surfaces.
- Add a patch changelog entry describing the defensive behavior change.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| projects/packages/premium-analytics/packages/site-sync/src/status.ts | Adjusts stall detection to ignore the transient “100% but milestone still 0” finishing gap. |
| projects/packages/premium-analytics/packages/site-sync/src/status.test.ts | Adds unit coverage for the finishing-gap behavior and confirms genuine stall behavior. |
| projects/packages/premium-analytics/packages/site-sync/src/hooks/tests/use-sync-status.test.ts | Adds hook-level test to ensure polling continues through the finishing gap and then completes. |
| projects/packages/premium-analytics/changelog/wooa7s-1546-harden-sync-stall-detection | Documents the defensive change in stall detection. |
| const isFinishing = status.percentage >= 100 && status.initialFullSyncFinished === 0; | ||
| return status.isStarted && ! status.isRunning && ! isSyncComplete( status ) && ! isFinishing; | ||
| } |
|
Closing as won't-do. After investigation this isn't a real bug on the shipping path: the default |
Proposed changes
Defensive hardening from review feedback on #49267 (
use-sync-status.ts). Not a live bug fix — the gap can't occur on the default full-sync path; this just removes a permanent failure mode for a theoretical edge case.Why —
useSyncStatuscleared polling permanently the first timeisSyncStalledwas true, with no tolerance. The one false-positive is a read gap: a poll seeingfinished: trueat 100% progress while the milestone write hasn't landed (initial_full_sync_finished === 0). The default path writes the milestone beforefinished, so this can't happen there; only the legacy queue-basedFull_Syncleaves a sub-ms window. Unreachable in practice, but cheap to guard.How —
isSyncStallednow treatspercentage >= 100 && milestone === 0as finishing, not stalled. The hook already keeps polling for anything neither complete nor stalled, so it self-heals on the next tick. A genuine stall sits below 100%.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
cd projects/packages/premium-analytics && pnpm test packages/site-sync— all suites pass;pnpm run typecheckclean.