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
{{ message }}
Repository navigation
feat(billing): record ended and skipped subscription sync results - #5548
Record subscription_ended after normal billing reconciliation succeeds for a subscription whose ActiveTo has passed and whose requested AsOf covers that end. A future cancellation request or a historical horizon does not establish final reconciliation.
By default, subscriptions whose ActiveTo is more than 30 days before the worker clock record subscription_skipped without loading the subscription view or billing artifacts, changing legacy scheduling, or collecting pending lines. Exactly 30 days old remains eligible. Subscription-deletion and customer-deleted-before-start cleanup retain precedence and still reconcile an empty target regardless of age.
Adds the independent ForceResyncOldSubscriptions input and sync option. CLI --f retains its billing-deadline override; new --force-all enables both overrides. Lookback and customer/namespace selection still apply, including the existing exclusion of completed subscription-deletion cleanup.
Notes for reviewer
Ended results commit with billing changes and legacy scheduling. An intentional skipped outcome acknowledges the observed revision's age-policy decision, not completed billing reconciliation. Both paths preserve newer current revisions; dry runs and failed transactions record no result.
Subscription hooks and further periodic suppression using v2 state remain separate follow-up work.
Tests exercise both legacy invoicing and the real charges/ledger stack: end/horizon and 30-day boundaries, forced resync replacing a skip, independent force inputs and lookback selection, deletion precedence, dry runs, result-write rollback, and skipping view/artifact reads after acquiring the billing lock.
Verified after rebasing onto origin/main: PostgreSQL-backed subscription-sync tests, scoped fast lint including the CLI, Ent regeneration, and Atlas schema diff. The enum values use the existing string column; Atlas requires no SQL migration.
Summary by CodeRabbit
New Features
Added a --force-all option to resynchronize older subscriptions, while retaining the existing -f behavior. Lookback settings still limit which subscriptions are selected.
Sync results now distinguish subscriptions successfully reconciled after ending from those skipped because they ended more than 30 days ago.
Documentation
Clarified sync outcomes, resynchronization options, and how skipped subscriptions affect billing reconciliation and pending-line collection.
Confidence Score: 5/5
The PR appears safe to merge; no blocking issues were found.
Summary
Adds recorded outcomes for ended subscriptions and subscriptions skipped by the 30-day age policy.
Subscription sync records ended results and skips very old billing work.
Operators can force old-subscription resyncs without changing lookback filters.
No actionable issues were found in the changes since the previous review or the full-PR rule check.
No actionable comments were generated in the recent review.
Walkthrough
The subscription sync service now records ended and too_old outcomes. The reconciler and all command can enable resynchronization beyond the 30-day age cutoff. The lookback still limits selection, and deletion cleanup takes precedence over the age cutoff.
Changes: Subscription synchronization
Layer / File(s)
Summary
Record ended and skipped outcomes openmeter/billing/worker/subscriptionsync/syncstatev2.go, openmeter/billing/worker/subscriptionsync/service.go, openmeter/billing/worker/subscriptionsync/service/sync.go, openmeter/billing/worker/subscriptionsync/reconciliaton_test.go, openmeter/billing/worker/subscriptionsync/service/sync_lock_test.go
The sync service adds ended and too_old outcomes. It records ended when the worker clock and sync horizon cover ActiveTo. It skips subscriptions whose ActiveTo is more than 30 days before the worker clock unless forced resync or deletion cleanup applies. Tests cover cutoff behavior, cleanup precedence, dry runs, revision capture, and failed result writes.
The reconciler forwards the resync option when enabled. The all command adds --force-all; the existing -f still enables only Force. Documentation describes the lookback limit, cleanup exclusion, and recorded outcomes.
This change adds ended and skipped outcomes to subscription sync, along with an option to force resync of old subscriptions. No actionable merge-blocking risk was found, and the change appears ready to merge.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: subscription sync now records ended and skipped outcomes. The raw summary shows new ended and too_old v2 states, the age-cutoff skip, and recording of these results. T…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: subscription sync now records ended and skipped outcomes. The raw summary shows new ended and too_old v2 states, the age-cutoff skip, and recording of these results. The title does not mention the new force-all flag, but it does not need to cover every detail. It uses the conventional feat(billing) prefix and is specific enough for a teammate scanning history.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
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.
Overview
Record
subscription_endedafter normal billing reconciliation succeeds for a subscription whoseActiveTohas passed and whose requestedAsOfcovers that end. A future cancellation request or a historical horizon does not establish final reconciliation.By default, subscriptions whose
ActiveTois more than 30 days before the worker clock recordsubscription_skippedwithout loading the subscription view or billing artifacts, changing legacy scheduling, or collecting pending lines. Exactly 30 days old remains eligible. Subscription-deletion and customer-deleted-before-start cleanup retain precedence and still reconcile an empty target regardless of age.Adds the independent
ForceResyncOldSubscriptionsinput and sync option. CLI--fretains its billing-deadline override; new--force-allenables both overrides. Lookback and customer/namespace selection still apply, including the existing exclusion of completed subscription-deletion cleanup.Notes for reviewer
origin/main: PostgreSQL-backed subscription-sync tests, scoped fast lint including the CLI, Ent regeneration, and Atlas schema diff. The enum values use the existing string column; Atlas requires no SQL migration.Summary by CodeRabbit
--force-alloption to resynchronize older subscriptions, while retaining the existing-fbehavior. Lookback settings still limit which subscriptions are selected.

Confidence Score: 5/5
The PR appears safe to merge; no blocking issues were found.Summary
Adds recorded outcomes for ended subscriptions and subscriptions skipped by the 30-day age policy.
No actionable issues were found in the changes since the previous review or the full-PR rule check.
Reviews (2) · Last reviewed commit: "refactor(billing): shorten terminal sync..." · Reviewed by Greptile