feat(work-costs): make the one-less-per-week suggestion a commitment, then measure it - #211
Conversation
… then measure it The Workday Cost Lens computed "try one less each workweek: save about ₹X" and stored nothing. There was no start, keep or stop to observe, so the one event that would show whether the lens changes behaviour — rather than merely being read — could not be instrumented. This is that state. `WorkCostExperiment` records the commitment against a tagged repeat cost: status, the monthly target snapshotted at the moment of committing so a later change in spending cannot rewrite what the user signed up for, the start date, and the decision date. It lives in `WorkCostState`, so it persists through the existing user-scoped secure storage and survives a restart. The lens now offers "I will try this" on a tagged cost, shows how long a running experiment has run, and takes "It stuck" or "I stopped". A decided experiment can be started again. Two events, both inside the privacy contract — no amount, date or id crosses the boundary: - `work_cost_experiment_started` carries only the work-cost kind, never the saving on offer. - `work_cost_experiment_decided` carries the kind, kept or stopped, and how long it ran as a bucket. A day count next to an event timestamp would reconstruct the start date, so `experimentAgeBucket` keeps it coarse: same_day, under_week, under_month, month_plus. Removing the work tag drops the experiment, and reports a running one as stopped first: it ended without being kept, and a start with no end is a hole in the measurement rather than an absence of one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 59 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
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 |
There was a problem hiding this comment.
4 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/features/work_costs/models/work_cost_models.dart">
<violation number="1" location="lib/features/work_costs/models/work_cost_models.dart:135">
P2: When a persisted experiment has a non-numeric `monthlyTarget`, this cast aborts the entire work-cost restore and clears valid tags from the in-memory state. Parse invalid values without throwing, or skip only the malformed experiment.</violation>
<violation number="2" location="lib/features/work_costs/models/work_cost_models.dart:137">
P3: When a decided experiment is restored from storage whose `decidedAt` is missing or unparseable, `fromJson` yields a decided status with `decidedAt == null`. `daysRunning` then computes against `now` and grows forever instead of freezing, breaking the model's 'decided length is frozen' contract. Guard the restore so a decided experiment requires a valid `decidedAt`, dropping it or treating it as running otherwise.</violation>
</file>
<file name="lib/features/work_costs/screens/work_cost_lens_screen.dart">
<violation number="1" location="lib/features/work_costs/screens/work_cost_lens_screen.dart:275">
P2: While the screen remains mounted, this label never updates as time passes because `build` runs only on state or dependency changes. Rebuild the running controls at a day boundary or periodically so the displayed duration stays accurate.</violation>
</file>
<file name="lib/features/work_costs/providers/work_cost_provider.dart">
<violation number="1" location="lib/features/work_costs/providers/work_cost_provider.dart:68">
P2: A rapid double-tap on 'I will try this' (or on 'It stuck'/'I stopped') can run `startExperiment`/`decideExperiment` twice: the state mutation only rebuilds the widget on the next frame, so a second tap in the same frame still reads the old state. Each call then emits a duplicate `work_cost_experiment_started`/`decided` event and, for start, resets `startedAt`, which corrupts the measurement this PR is meant to collect. Guard against concurrent invocation (e.g. an in-flight flag read before mutating, or reading `state.experiments[candidateId]` and skipping when a running experiment already exists).</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| (value) => value.name == status, | ||
| orElse: () => WorkCostExperimentStatus.running, | ||
| ), | ||
| monthlyTarget: (json['monthlyTarget'] as num?)?.round() ?? 0, |
There was a problem hiding this comment.
P2: When a persisted experiment has a non-numeric monthlyTarget, this cast aborts the entire work-cost restore and clears valid tags from the in-memory state. Parse invalid values without throwing, or skip only the malformed experiment.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/features/work_costs/models/work_cost_models.dart, line 135:
<comment>When a persisted experiment has a non-numeric `monthlyTarget`, this cast aborts the entire work-cost restore and clears valid tags from the in-memory state. Parse invalid values without throwing, or skip only the malformed experiment.</comment>
<file context>
@@ -57,37 +57,133 @@ class WorkCostTag {
+ (value) => value.name == status,
+ orElse: () => WorkCostExperimentStatus.running,
+ ),
+ monthlyTarget: (json['monthlyTarget'] as num?)?.round() ?? 0,
+ startedAt: startedAt,
+ decidedAt: DateTime.tryParse(json['decidedAt']?.toString() ?? ''),
</file context>
| monthlyTarget: (json['monthlyTarget'] as num?)?.round() ?? 0, | |
| monthlyTarget: json['monthlyTarget'] is num | |
| ? (json['monthlyTarget'] as num).round() | |
| : 0, |
| } | ||
|
|
||
| if (!current.status.isDecided) { | ||
| final days = current.daysRunning(DateTime.now()); |
There was a problem hiding this comment.
P2: While the screen remains mounted, this label never updates as time passes because build runs only on state or dependency changes. Rebuild the running controls at a day boundary or periodically so the displayed duration stays accurate.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/features/work_costs/screens/work_cost_lens_screen.dart, line 275:
<comment>While the screen remains mounted, this label never updates as time passes because `build` runs only on state or dependency changes. Rebuild the running controls at a day boundary or periodically so the displayed duration stays accurate.</comment>
<file context>
@@ -219,6 +242,91 @@ class _CandidateCard extends StatelessWidget {
+ }
+
+ if (!current.status.isDecided) {
+ final days = current.daysRunning(DateTime.now());
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
</file context>
| // An experiment belongs to a confirmed work cost. Without a tag there is | ||
| // nothing to be spending less on. | ||
| if (kind == null) return; | ||
| state = state.withExperiment( |
There was a problem hiding this comment.
P2: A rapid double-tap on 'I will try this' (or on 'It stuck'/'I stopped') can run startExperiment/decideExperiment twice: the state mutation only rebuilds the widget on the next frame, so a second tap in the same frame still reads the old state. Each call then emits a duplicate work_cost_experiment_started/decided event and, for start, resets startedAt, which corrupts the measurement this PR is meant to collect. Guard against concurrent invocation (e.g. an in-flight flag read before mutating, or reading state.experiments[candidateId] and skipping when a running experiment already exists).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/features/work_costs/providers/work_cost_provider.dart, line 68:
<comment>A rapid double-tap on 'I will try this' (or on 'It stuck'/'I stopped') can run `startExperiment`/`decideExperiment` twice: the state mutation only rebuilds the widget on the next frame, so a second tap in the same frame still reads the old state. Each call then emits a duplicate `work_cost_experiment_started`/`decided` event and, for start, resets `startedAt`, which corrupts the measurement this PR is meant to collect. Guard against concurrent invocation (e.g. an in-flight flag read before mutating, or reading `state.experiments[candidateId]` and skipping when a running experiment already exists).</comment>
<file context>
@@ -38,9 +38,66 @@ class WorkCostNotifier extends Notifier<WorkCostState> {
+ // An experiment belongs to a confirmed work cost. Without a tag there is
+ // nothing to be spending less on.
+ if (kind == null) return;
+ state = state.withExperiment(
+ WorkCostExperiment(
+ candidateId: candidateId,
</file context>
| ), | ||
| monthlyTarget: (json['monthlyTarget'] as num?)?.round() ?? 0, | ||
| startedAt: startedAt, | ||
| decidedAt: DateTime.tryParse(json['decidedAt']?.toString() ?? ''), |
There was a problem hiding this comment.
P3: When a decided experiment is restored from storage whose decidedAt is missing or unparseable, fromJson yields a decided status with decidedAt == null. daysRunning then computes against now and grows forever instead of freezing, breaking the model's 'decided length is frozen' contract. Guard the restore so a decided experiment requires a valid decidedAt, dropping it or treating it as running otherwise.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/features/work_costs/models/work_cost_models.dart, line 137:
<comment>When a decided experiment is restored from storage whose `decidedAt` is missing or unparseable, `fromJson` yields a decided status with `decidedAt == null`. `daysRunning` then computes against `now` and grows forever instead of freezing, breaking the model's 'decided length is frozen' contract. Guard the restore so a decided experiment requires a valid `decidedAt`, dropping it or treating it as running otherwise.</comment>
<file context>
@@ -57,37 +57,133 @@ class WorkCostTag {
+ ),
+ monthlyTarget: (json['monthlyTarget'] as num?)?.round() ?? 0,
+ startedAt: startedAt,
+ decidedAt: DateTime.tryParse(json['decidedAt']?.toString() ?? ''),
+ );
+ }
</file context>
The Workday Cost Lens computed "try one less each workweek: save about ₹X" and stored nothing. There was no start, keep or stop to observe, so the one event that would show whether the lens changes behaviour — rather than merely being read — could not be instrumented. This is that state.
WorkCostExperimentrecords the commitment against a tagged repeat cost: status, the monthly target snapshotted at the moment of committing so a later change in spending cannot rewrite what the user signed up for, the start date, and the decision date. It lives inWorkCostState, so it persists through the existing user-scoped secure storage and survives a restart.The lens now offers "I will try this" on a tagged cost, shows how long a running experiment has run, and takes "It stuck" or "I stopped". A decided experiment can be started again.
Events
Both inside the privacy contract — no amount, date or id crosses the boundary.
work_cost_experiment_startedcarries only the work-cost kind, never the saving on offer.work_cost_experiment_decidedcarries the kind, kept or stopped, and how long it ran as a bucket. A day count next to an event timestamp would reconstruct the start date, soexperimentAgeBucketkeeps it coarse:same_day,under_week,under_month,month_plus.Removing the work tag drops the experiment, and reports a running one as stopped first: it ended without being kept, and a start with no end is a hole in the measurement rather than an absence of one.
Checks
dart formatclean ·flutter analyzeno issues ·flutter test416/416, including a newtest/work_cost_experiment_test.dartcovering the run/decide lifecycle, the frozen target, the save-load round trip, and unreadable stored state.🤖 Generated with Claude Code
Summary by cubic
Turns the Workday Cost Lens’s “one less each workweek” suggestion into a recorded commitment and measures the outcome. Previously the lens only displayed a saving; now users can start, keep, or stop an experiment, we persist it, and we emit privacy‑preserving analytics.
WorkCostExperimentinWorkCostState.experiments(keyed by candidate id) with status, snapshotted monthlyTarget, startedAt, and decidedAt; drop unreadable stored entries; removing a work tag removes its experiment and first logs it as stopped if still running.startExperiment(only for tagged costs; snapshots monthlyTarget) anddecideExperiment(logs kept/stopped and run length).work_cost_experiment_started(kind only),work_cost_experiment_decided(kind, outcome,ran_forbucket viaexperimentAgeBucket: same_day, under_week, under_month, month_plus). No amount, dates, or ids leave the device.Written for commit ce640a2. Summary will update on new commits.