Fix activities missing when sleep dbt build times out - #1315
Conversation
Split dbt into activity and sleep/dashboard phases so deduped_activities keeps refreshing, and replace sleep_heart_rate_sample microbatch with dirty-key incremental updates. Co-authored-by: Cursor <cursoragent@cursor.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough
Changessleep_heart_rate_sample rewrite and entrypoint build split
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
|
Storybook previews for This comment updates automatically on each PR push. |
There was a problem hiding this comment.
3 issues found across 3 files
Confidence score: 2/5
- In
entrypoint.sh, the analytics-worker dbt phase commands are not chained, so an early phase failure can be masked and the cycle may report success despite failed activity models; this undermines fail-fast behavior and can hide broken runs in production — chain the phase commands (or explicitly propagate exit codes) before merging. - In
analytics/models/read_models/sleep_heart_rate_sample.sql, dirty-key logic misses activity removals (deleted/provider-absent transitions), so overlapping sleep windows are not recomputed and stale sleep heart-rate rows can persist until unrelated updates occur — include removal transitions in dirty-key detection before merge. - In
analytics/models/read_models/sleep_heart_rate_sample.sql, the incremental watermark usesrefreshed_atwithout activity_peerdb_synced_at, so activity-only changes can stall progress and trigger repeated reprocessing of the same sleep keys each run — incorporate the activity sync timestamp into watermark advancement to de-risk merge.
You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Requires human review: Auto-approval blocked by 3 unresolved issues from previous reviews.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Requires human review: Restructures dbt orchestration, updates sleep_heart_rate_sample to an incremental pattern, and changes production analytics pipelines; may impact data freshness and metrics, so human review is required.
Re-trigger cubic
Summary
Production
/activitieswas stale becausesleep_heart_rate_samplemicrobatch runs timed out (121 daily batches with a 120-day lookback), failing the entire dbt build and blockingdeduped_activitiesfrom refreshing. This splits analytics-worker dbt into activity and sleep/dashboard phases so activity read models keep updating even when sleep builds fail. It also rewritessleep_heart_rate_samplefrom microbatch to dirty-key incremental updates, scoping work to changed sleeps, sensors, and overlapping activities instead of reprocessing the full lookback every run. Tests were updated for the split build and dirty-key sleep model pattern.Test plan
read_model_microbatch.sql.test.tspasses locallydeduped_activitiesrefreshes even if sleep models fail550063f5-bcd1-4c63-88bf-c4533b62b9c5appears on/activitiessleep_heart_rate_samplerun after deploy (120-day bootstrap may be heavy, then incremental runs should be fast)Made with Cursor
Summary by cubic
Splits analytics builds into activity and sleep/dashboard phases and rewrites
sleep_heart_rate_sampleto an append-based dirty-key incremental model withReplacingMergeTree(refresh_version). This avoids microbatch timeouts, keeps/activitiesfresh, and fixes the table’s ClickHouse sort/order stability.Bug Fixes
sleep_heart_rate_sampleusing arefresh_clockandsource_refreshed_atto avoid nondeterminism.assumeNotNullforsleep_id,user_id,recorded_at, andrecorded_date.sleep_heart_rate_sampleto improve merges and determinism.Refactors
analytics-workerbuilds inentrypoint.shintoDBT_ACTIVITY_MODELSandDBT_SLEEP_DASHBOARD_MODELS, combined intoDBT_SAFE_MODELSand executed viarun_dbt_safe_builds.sleep_heart_rate_samplemicrobatch with append +ReplacingMergeTree(refresh_version)and dirty-key increments from changed sleeps (_peerdb_synced_at), heart rate updates (refreshed_at), overlapping activities, and deleted/absent records; emit tombstones for stale samples and include aninitial_lookback_daysbootstrap.Written for commit 3a38c18. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Chores
Tests