[db] Guard activity overlap pairs - #2219
Conversation
Deploy the canonical view update through migration 0059 so time-disjoint activity pairs are rejected by cheap interval predicates while preserving the existing overlap semantics.
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
📝 WalkthroughWalkthroughThe PR adds a replacement ChangesActivity overlap mitigation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ActivityData
participant fitness_v_activity
participant OverlapQuery
participant PostgreSQLPlan
ActivityData->>fitness_v_activity: supply activity intervals
fitness_v_activity->>fitness_v_activity: filter mutually overlapping pairs
fitness_v_activity->>OverlapQuery: return merged activity groups
OverlapQuery->>PostgreSQLPlan: inspect EXPLAIN plan predicates
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
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 |
Reviewer's GuideAdds strict positive-interval overlap guards to the activity deduplication view, ships the canonical view via a new migration, documents the production incident, and adds a PostgreSQL-backed regression test that validates both query semantics and execution plan. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoGuard v_activity overlap pairs with positive time intersection
AI Description
Diagram
High-Level Assessment
Files changed (5)
|
|
Storybook previews for This comment updates automatically on each PR push. |
Code Review by Qodo
Context used✅ Compliance rules (platform):
156 rules✅ Skills:
fix-provider, write-tests, cloudflare 1.
|
Format the immutable migration for SQLFluff and make the database regression schema-validated and planner-shape tolerant.
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@drizzle/0059_v_activity_positive_overlap.sql`:
- Around line 154-193: Update the pairs logic in both the canonical view and
migration so they share the same implementation, using the canonical view
definition as the source of truth. Remove the separate pair_metrics CTE from the
migration and align pairs with the canonical structure while preserving the
existing overlap criteria.
In `@src/db/activity-overlap-plan.integration.test.ts`:
- Around line 89-102: Update the row-size assertion to sort numerically using an
explicit comparator rather than default lexicographic sorting. In the EXPLAIN
assertions around collectPlanStrings, replace c1/c2 alias-dependent regexes with
checks for the relevant predicate columns and comparison operators, preserving
validation of the positive-overlap boundaries without coupling to view alias
rendering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ac3cd75a-1d1a-43e5-b265-9e4ec3f4fcdd
📒 Files selected for processing (5)
docs/production-incident-baseline.mddrizzle/0059_v_activity_positive_overlap.sqldrizzle/_views/01_v_activity.sqldrizzle/meta/_journal.jsonsrc/db/activity-overlap-plan.integration.test.ts
Keep the canonical pair implementation structurally aligned with the linted migration and make the plan regression alias-independent.
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
Summary
fitness.v_activityupdate through migration 0059Root cause
The recursive activity view compared every same-user activity pair globally before request-level user/date predicates could apply. The exact production plan rejected 6,941,004 time-disjoint pairs, held all five web-pool connections for 13.94–16.29 seconds under concurrent dashboard load, and caused queued session, insights, and PMC queries to hit the unchanged ten-second acquisition timeout.
The new predicates are logically implied by both existing strict overlap-ratio branches. They preserve current grouping semantics while giving PostgreSQL cheap necessary conditions for disjoint intervals. No pool size, timeout, retry, cache, or database resource limit changes.
Validation
pnpm typecheckuv tool run sqlfluff lint drizzle/0059_v_activity_positive_overlap.sqlpnpm exec cspell --no-progressgit diff --checkSentry
Refs DOFEK-SERVER-5K, DOFEK-SERVER-5M, and DOFEK-SERVER-5N.
Summary by Sourcery
Guard activity overlap detection with positive time-interval checks and document and test the production incident regression behavior.
Bug Fixes:
Enhancements:
Documentation:
Tests:
Summary by cubic
Add positive-overlap guards to
fitness.v_activityso time‑disjoint activity pairs are skipped. This speeds up overlap grouping and prevents the web DB pool exhaustion seen in production.Bug Fixes
c1.started_at < c2.ended_atandc1.ended_at > c2.started_at) before 80% overlap checks; grouping semantics unchanged. Align the canonical view with the migration and compute pair metrics once.Migration
_views/01_v_activity.sqlmirrors it. No changes to pool size, timeouts, retries, caches, or DB resource limits.Written for commit dc8b132. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Tests