← Back to Pull requests

Preserve recurring date hints when finite schedules finish #6121

Open
unknown opened this pull request with 352 lines diff across 4 files
View on GitHub
unknown unknown commented on Dec 04, 2026 08:23 UTC
Author

Summary

Keep finished schedules from writing a NULL cached date or counting later charges as extra installments.

 refresh_series(entries)
+  limit finite-plan entries to the declared schedule
+  preserve recorded count and last date after the final occurrence
 calculate_next_expected_date(from_date)
-  schedule.next_occurrence_after(from_date)
+  schedule.next_occurrence_after(from_date) || next_expected_date

Both identifier refresh paths use the model date helper. Finite detected plans use the existing schedule matcher for their statistics. Completed counts stay stable as older payments leave the detection window.

Keep Schedule’s nil result, lifecycle status, paid history, and allocations unchanged. This does not change completed-plan display or active totals.

Evidence

  • Before: Removing the fallback makes four regression tests raise PG::NotNullViolation. A September–November plan counts a December charge as payment 4. Filtering alone then drops its count to 2 in January.

  • After: Repeated refreshes retain count 3 and last date November 15, through December, January, and February. Tests cover both count/date end conditions and an empty scheduled-entry set.
  • Focused Rails tests: 183 tests, 634 assertions, 0 failures, 0 errors. Coverage also checks paid-history preservation and ongoing schedules.

  • Full Rails suite: 20,281 tests, 122,305 assertions, 0 failures, 0 errors, 10 skips. Ran with Ruby 3.4.13, isolated PostgreSQL 18 and Redis 7, without local app settings.

  • Ruby lint, ERB lint, Biome, and Brakeman pass. No local system tests: no UI changes.
  • AI assistance: GPT-6.1 Sol. Source reviews covered standards and spec; the January lookback finding has a failing-before/passing-after regression.

    Merge Danger

    Door: two-way

    No migration or data rewrite. Reverting restores the previous detection and date calculation.

    Blast Radius: Recurring

    Changes cached-date and detected-series statistics updates. Ongoing schedules still advance; finite schedules generate no extra occurrences.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    Completed installment schedules now retain their final expected date when recurring transactions are recorded or refreshed.
    Repeated updates preserve final occurrence details, including the date, payment status, and allocation information.
    Recurring transactions remain active after the final scheduled payment, with the final occurrence count and amount average preserved.
    * Charges detected on or after a finite schedule’s end no longer extend its occurrence count or move its final occurrence date.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 352 lines (+264 / -88) across 4 files Reviewer: jjmata Review duration: 1816m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 352 lines diff across 4 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.351
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #6121"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.5% (MEDIUM) · Higher = larger blast radius
    47.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.3% · Safe to merge
    25.3%