Skip to content

feat(work-costs): make the one-less-per-week suggestion a commitment, then measure it - #211

Merged
rish106-hub merged 1 commit into
mainfrom
feat/work-costs/experiment-state
Aug 15, 2026
Merged

feat(work-costs): make the one-less-per-week suggestion a commitment, then measure it#211
rish106-hub merged 1 commit into
mainfrom
feat/work-costs/experiment-state

Conversation

@rish106-hub

@rish106-hub rish106-hub commented Aug 14, 2026

Copy link
Copy Markdown
Owner

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.

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.

Checks

dart format clean · flutter analyze no issues · flutter test 416/416, including a new test/work_cost_experiment_test.dart covering 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.

  • Persist a WorkCostExperiment in WorkCostState.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.
  • Add UI controls: “I will try this” to start; show days running; “It stuck” / “I stopped”; show decided state with “Try it again.”
  • Add provider APIs: startExperiment (only for tagged costs; snapshots monthlyTarget) and decideExperiment (logs kept/stopped and run length).
  • Emit analytics: work_cost_experiment_started (kind only), work_cost_experiment_decided (kind, outcome, ran_for bucket via experimentAgeBucket: same_day, under_week, under_month, month_plus). No amount, dates, or ids leave the device.
  • Extend tests to cover experiment lifecycle, persistence round‑trip, unreadable state handling, and analytics bucketing.

Written for commit ce640a2. Summary will update on new commits.

Review in cubic

… 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>
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@rish106-hub, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 127da9b4-b684-4369-98a3-2ce745043019

📥 Commits

Reviewing files that changed from the base of the PR and between bcc8ac4 and ce640a2.

📒 Files selected for processing (6)
  • lib/features/work_costs/models/work_cost_models.dart
  • lib/features/work_costs/providers/work_cost_provider.dart
  • lib/features/work_costs/screens/work_cost_lens_screen.dart
  • lib/services/analytics_service.dart
  • test/analytics_service_test.dart
  • test/work_cost_experiment_test.dart

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
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());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() ?? ''),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@rish106-hub
rish106-hub merged commit 3729054 into main Aug 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant