test(medium): Fix Real-time HR Display Clock Skew Issue - #8974
Conversation
Implemented a clock skew compensation mechanism for the HRM dashboard. - Added `serverTimestamp` to `ServerMessage` in `types/websocket.ts`. - Updated `utils/websocketUtils.ts` to attach the server's current time to all outgoing messages. - Modified `webSocketReducer.ts` to calculate a time offset between the client and server and use it to normalize HRM `updatedAt` timestamps. - Added unit tests in `tests/unit/context/webSocketReducer.test.ts`. - Added a reproduction Playwright test in `tests/playwright/clock-skew.spec.ts`. This ensures HR tiles are correctly displayed even when the user's system clock is out of sync with the server. Co-authored-by: arii <342438+arii@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR effectively addresses the real-time HR display clock skew issue by introducing a Key Observations:
Overall, this is a solid fix that improves the robustness and accuracy of the real-time HR display. Good work!
|
Steps taken: 1. Created a reproduction Playwright test `tests/playwright/clock-skew.spec.ts` that simulated a 60-second clock skew, confirming HR tiles were incorrectly hidden. 2. Augmented the `ServerMessage` type in `types/websocket.ts` with an optional `serverTimestamp`. 3. Updated `utils/websocketUtils.ts` (`sendWebSocketMessage` and `broadcast`) to automatically attach the current server time to all outgoing messages. 4. Implemented clock skew compensation in `webSocketReducer.ts`. The reducer now calculates a local-to-server offset and applies it to incoming HRM `updatedAt` timestamps, ensuring they are compared against `Date.now()` in the same timebase. 5. Added comprehensive unit tests in `tests/unit/context/webSocketReducer.test.ts` for both `INITIAL_STATE` and `HRM_UPDATE` scenarios. 6. Verified the fix with the reproduction Playwright test and a manual visual verification script. 7. Ensured all tests pass and the codebase follows linting/build requirements. Changes: - `types/websocket.ts`: Added `serverTimestamp` to `ServerMessage`. - `utils/websocketUtils.ts`: Attach `Date.now()` to outgoing messages. - `context/webSocketReducer.ts`: Calculate and apply clock offset to `updatedAt`. - `tests/unit/context/webSocketReducer.test.ts`: Added tests for clock skew compensation. - `tests/playwright/clock-skew.spec.ts`: Added new reproduction and regression test. Co-authored-by: arii <342438+arii@users.noreply.github.com>
This PR effectively addresses the real-time HR display clock skew issue by introducing a Key Strengths:
Overall, this is a well-executed and thoroughly tested fix. Great work!
|
Implemented a robust clock skew compensation mechanism and addressed feedback from code review and technical audit. Clock Skew Fixes: - Added `serverTimestamp` to `ServerMessage` in `types/websocket.ts`. - Updated `utils/websocketUtils.ts` to attach server time to all outgoing messages. - Modified `webSocketReducer.ts` to normalize `updatedAt` for HRM data and `timestamp` for active alerts using a client-server offset. - Ensured normalization applies to all users (new and existing) in `HRM_UPDATE`. - Added unit tests in `tests/unit/context/webSocketReducer.test.ts` for new users and alerts. PR Feedback & Polishing: - Reduced giant timer font sizes in `components/TimerDisplay.tsx` to prevent potential layout overflow. - Added a `Skeleton` loading fallback for `HeartRateTimeSeries` in `ExperimentalAnalyticsPage.tsx` to improve UX during dynamic import. Verified with Playwright and unit tests. Co-authored-by: arii <342438+arii@users.noreply.github.com>
📋 Quality Gate Results
❌ Visual Test Failure Details
|
Implemented clock skew compensation and addressed PR feedback. - Normalized timestamps in `webSocketReducer.ts` using `serverTimestamp`. - Reduced giant timer font sizes in `TimerDisplay.tsx`. - Updated `dashboard-mobile.png` snapshot to reflect fixed layout (no horizontal overflow). - Added regression tests. Co-authored-by: arii <342438+arii@users.noreply.github.com>
This PR effectively addresses the critical real-time HR display clock skew issue, which is a significant improvement for data accuracy and user experience. The solution is well-implemented and thoroughly tested. Key Improvements:
Code Quality & Adherence to Guidelines:
Overall, this is an excellent PR that delivers a critical fix with high quality and thorough testing.
|
Comprehensive fix for clock skew and refinement of workout analytics UI. Clock Skew: - Normalized HRM and Alert timestamps using server-provided `serverTimestamp`. - Added unit tests for normalization of new users and alerts. PR Feedback & Refinement: - Updated `theme/theme.ts`: Fixed missing module declaration for TypeScript and added missing workout status colors (`paused`, `finished`). - Refactored `WorkoutSummary.tsx`: Corrected MUI `Grid` usage, implemented safe palette access with fallbacks, and simplified the header layout. - Refactored `ZoneDistribution.tsx`: Replaced complex pie chart with accessible linear progress bars for better clarity and performance. - Unit Tests: Updated `WorkoutSummary.test.tsx` and `ZoneDistribution.test.tsx` to match the new UI and theme structure. - Timer: Further refined font sizes to prevent layout overflow in mobile/tablet views. - VRT: Updated snapshots for mobile dashboard and workout summary to reflect layout improvements. All tests passed (unit and visual). Co-authored-by: arii <342438+arii@users.noreply.github.com>
📋 Quality Gate Results
❌ Slop Failure Details
========================================================
|
- Implemented client-server clock skew compensation in `webSocketReducer.ts`. - Refactored `WorkoutSummary.tsx` and `ZoneDistribution.test.tsx` to align with new UI standards. - Fixed MUI `Grid` usage and added safe palette access in `WorkoutSummary.tsx`. - Improved `ZoneDistribution.tsx` with accessible linear progress bars. - Reduced timer font sizes to prevent layout overflow. - Updated VRT snapshots for mobile dashboard and workout summary. - Removed temporary `pr.diff` and verification scripts that caused slop check failures. - Added regression tests for clock skew. All tests passed (unit, visual, slop). Co-authored-by: arii <342438+arii@users.noreply.github.com>
This PR delivers a critical fix for the real-time HR display clock skew issue, which is well-implemented and thoroughly tested with a new Playwright E2E test. The approach of using Beyond the core bug fix, the PR includes significant and positive refactoring:
Overall, this PR significantly improves the stability, maintainability, and user experience of the application. The new E2E test for clock skew is particularly valuable.
|
This commit implements a clock skew compensation mechanism for the real-time heart rate dashboard. By attaching a server-side timestamp to all outgoing WebSocket messages, the client can now calculate a persistent offset and normalize incoming data timestamps to its local clock. This prevents correctly received data from being incorrectly flagged as stale due to system clock desynchronization. Additionally, this commit addresses PR feedback: - Reduced giant timer font size for improved layout on medium-sized screens. - Refactored experimental analytics components (WorkoutSummary, ZoneDistribution, SessionDetail) to follow MUI best practices and improve performance via dynamic imports. - Replaced complex Recharts zone distribution with an accessible LinearProgress-based view. - Removed legacy exportService.ts and consolidated session management hooks. Tests: - Added Playwright test simulating 60s clock skew. - Updated visual regression snapshots for the resized timer. - Verified all unit and lint tests pass. Co-authored-by: arii <342438+arii@users.noreply.github.com>
This PR delivers a critical fix for the real-time HR display clock skew issue and includes significant, positive refactorings to several UI components. The clock skew fix is well-implemented and thoroughly tested with a new Playwright E2E test. ✅ Clock Skew Fix
✨ UI Component Refactorings & Improvements
|
This PR effectively addresses the real-time HR display clock skew issue by introducing server timestamp synchronization in the WebSocket reducer. The new Playwright test ( Beyond the core bug fix, the PR includes several valuable refactoring and UI/UX improvements:
Overall, this PR delivers a critical bug fix with solid test coverage and introduces several thoughtful improvements to the UI components, making the codebase more robust, consistent, and maintainable.
|
🤖 AI Technical AuditCode Review for PR #8974⛔ ANTI-AI-SLOP DIRECTIVES
File-by-File Analysis
|
…es (#9050) Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: arii <342438+arii@users.noreply.github.com>
This PR effectively addresses the real-time HR display clock skew issue by implementing a server-side timestamp in WebSocket messages and adjusting client-side timestamps accordingly. The solution is robust and well-tested. Key improvements:
|
This PR successfully addresses a critical clock skew issue in the real-time HR display, ensuring data consistency between the server and client. The solution involves adding a The PR also includes comprehensive unit tests for the Further improvements include:
Overall, this is a high-quality PR that delivers significant value in terms of correctness, testing, and UI/UX improvements.
|
🤖 AI Technical AuditCode Review: PR #8974 - Real-time HR Display Clock Skew Fix🛡️ ANTI-AI-SLOP REPORT
📁 File-by-File Analysis
|
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: arii <342438+arii@users.noreply.github.com>
This PR effectively addresses the real-time HR display clock skew issue by introducing a The changes are well-implemented, including:
Overall, this is a high-quality PR that resolves a significant bug and improves the application's stability and user experience.
|
Description
This change fixes a bug where heart rate tiles would fail to appear on the dashboard if the user's system clock was ahead of the server's clock. The fix involves calculating a clock offset when WebSocket messages are received and using this offset to adjust the timestamps used for staleness checks.
Fixes #8963
Change Type: 🐛 Bug fix (non-breaking change fixing an issue)
PR Scope Checklist
This checklist is mandatory for all PRs.
Impact Assessment
Original PR Body
This change fixes a bug where heart rate tiles would fail to appear on the dashboard if the user's system clock was ahead of the server's clock. The fix involves calculating a clock offset when WebSocket messages are received and using this offset to adjust the timestamps used for staleness checks.
Fixes #8963
PR created automatically by Jules for task 4157911381169539447 started by @arii