# Tasks: Personalization Correctness Verification ## T1: Decay correctness tests Create `tidal/tests/pg1_personalization_correctness.rs` with the test schema helper and analytical reference implementation. Implement decay verification tests: - `single_event_decay_matches_analytical`: One signal event, query at multiple future times, compare against `w * exp(-lambda * dt)`. - `multi_event_decay_matches_analytical`: 10 signal events at known timestamps, compare final score against sum of `w_i * exp(-lambda * (t_q - t_i))`. - `out_of_order_converges_to_in_order`: Same events submitted in random order vs chronological order produce scores within 1e-10 relative error. - `decay_score_zero_after_many_half_lives`: After 100 half-lives, score is effectively zero (< 1e-20). **Acceptance:** All 4 tests pass with assertions on relative error < 1e-10. ## T2: Windowed count and velocity tests Add windowed count and velocity verification tests: - `one_hour_window_exact_count`: Record N events within the last hour, verify `read_windowed_count(OneHour)` returns exactly N. - `velocity_equals_count_over_duration`: Verify `read_velocity(OneHour)` equals `count / 3600.0`. - `all_time_count_monotonic`: Record signals, verify AllTime count increases monotonically and never decreases. **Acceptance:** All 3 tests pass with exact count assertions. ## T3: Preference vector EMA tests Add preference vector verification tests: - `ema_matches_manual_computation`: Create PreferenceVectors, update with known embeddings, verify result matches manual EMA `v_new = (1-alpha)*v_old + alpha*embedding` with L2 normalization. - `adaptive_learning_rate_decays`: Verify that after N updates, effective alpha = `base / (1 + ln(N + 1))` decreases. - `dimension_mismatch_is_noop`: Verify that updating with wrong-dimension embedding returns false and does not modify the stored vector. **Acceptance:** All 3 tests pass. ## T4: Ranking reactivity tests Add reactivity verification tests: - `signal_immediately_visible_in_retrieve`: Write signal, immediately retrieve, verify the signal's effect is reflected, total elapsed < 100ms. **Acceptance:** Test passes with timing assertion < 100ms. ## T5: Score ordering and invariant tests Add score ordering and formula invariant tests: - `more_engagement_ranks_higher`: Items with more views rank above items with fewer views under `for_you` profile. - `interaction_boost_is_additive`: Items from interacted creators rank above equivalent items from non-interacted creators. - `no_nan_or_infinity_in_scores`: All scores in results are finite. - `gate_below_threshold_excluded`: Items below gate threshold do not appear in results. - `max_per_creator_enforced`: After diversity enforcement, no creator exceeds the max_per_creator limit. **Acceptance:** All 5 tests pass.