You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Habit metrics currently use the habit creation timestamp as the lower bound. That admits dates before the first scheduled due date. Bad habits receive unearned clean days, while good habits can have their streak suppressed.
Intended approach
Persist an optional immutable scheduled start date from the creation due date and use it as the shared expected-date lower bound for current streak, longest streak, and completion rates. Keep a guarded fallback for legacy rows so future habits with no activity are corrected while habits whose due date already advanced retain their historical window.
Add calculator coverage for future good and bad habits, the exact start date, a start yesterday, an advanced due date, a pre-start log, and completion-rate behavior. Add goal service coverage proving a future linked bad habit reads zero.
I will add ScheduledStartDate as a nullable persisted domain property and initialize it from HabitCreateParams.DueDate. The field stays internal to the existing API contract, so no shipped DTO changes.
HabitMetricsCalculator.GenerateExpectedDates will use that immutable date. For legacy rows where the field is null, it will use a future DueDate only when there are no completed logs, and otherwise preserve the creation-date lower bound. This fixes the reported legacy row without allowing an advanced due-date pointer to truncate an active habit's history.
The schema change will be one generated EF migration plus its snapshot. Tests will land in HabitMetricsCalculatorTests and GoalStreakSyncServiceTests, covering future good and bad habits, start-date boundaries, completion-rate denominator behavior, pre-start logs, an advanced due date, and goal progress.
I rejected using DueDate directly because logging and catch-up mutate it. I also rejected changing GoalStreakSyncService because it already delegates to the shared calculator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DEGRADED: same-vendor review
Fixes ORB-127.
Root cause
Habit metrics currently use the habit creation timestamp as the lower bound. That admits dates before the first scheduled due date. Bad habits receive unearned clean days, while good habits can have their streak suppressed.
Intended approach
Persist an optional immutable scheduled start date from the creation due date and use it as the shared expected-date lower bound for current streak, longest streak, and completion rates. Keep a guarded fallback for legacy rows so future habits with no activity are corrected while habits whose due date already advanced retain their historical window.
Add calculator coverage for future good and bad habits, the exact start date, a start yesterday, an advanced due date, a pre-start log, and completion-rate behavior. Add goal service coverage proving a future linked bad habit reads zero.
Verification
Pending implementation.