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): track subscription revisions in cleanup sync state - #5538
Track the subscription revision observed by a successful cleanup without overwriting changes made while cleanup runs. Sync reads v2 state after acquiring the customer billing lock and before reloading subscription billing intent, then acknowledges that captured revision only after cleanup succeeds.
Adds nullable last_synced_subs_revision and current_subs_revision columns. Inserts initialize both to one ULID. ON CONFLICT updates the acknowledged revision and initializes a NULL current revision while preserving any existing current value.
Notes for reviewer
V2 writes remain limited to subscription-deletion and customer-deleted-before-start cleanup. Ordinary syncs only read state; dry runs and failed transactions do not acknowledge revisions.
This step adds no change hooks or revision-based reconciliation skipping. Requiring and backfilling the columns is separate work.
Tests cover legacy NULL rows, generation, changes between capture and acknowledgment, a row inserted after the initial read, ordinary syncs, dry runs, and rollback, including both billing implementations.
Validated after rebasing onto origin/main: PostgreSQL-backed subscription-sync tests, scoped fast lint, Ent regeneration, and Atlas migration validation. go vet also passed during implementation.
Summary by CodeRabbit
New Features
Subscription sync now tracks current and last-synced revisions, generating a revision when none exists.
Successful cleanup records the revision it observed, while preserving newer revisions set during sync.
Documentation
Added documentation describing revision tracking and clarifying that revisions do not yet change scheduling or reconciliation behavior.
Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.
Summary
Tracks the subscription revision observed by successful cleanup.
Subscription cleanup records the revision it saw without replacing a newer one.
No actionable issues were found. The previous-review merge bases differed, so the full PR was reviewed. Tests were inspected but not run.
Diagram
sequenceDiagram
participant S as Subscription sync
participant B as Billing transaction
participant V as V2 state
S->>B: Acquire customer lock
B->>V: Read current revision
B->>B: Reload subscription intent
B->>B: Apply cleanup
B->>V: Acknowledge captured revision
Note over B,V: Keep any existing current revision
B->>B: Commit cleanup and state together
Reviewing files that changed from the base of the PR and between 645e493 and 6ab3cee.
Files ignored due to path filters: 10
openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
openmeter/ent/db/subscriptionsyncstatev2.go is excluded by !**/ent/db/**
openmeter/ent/db/subscriptionsyncstatev2/subscriptionsyncstatev2.go is excluded by !**/ent/db/**
openmeter/ent/db/subscriptionsyncstatev2/where.go is excluded by !**/ent/db/**
openmeter/ent/db/subscriptionsyncstatev2_create.go is excluded by !**/ent/db/**
openmeter/ent/db/subscriptionsyncstatev2_update.go is excluded by !**/ent/db/**
tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The change adds current and last-synced subscription revisions to v2 sync state. The sync service captures a revision under the customer billing lock and records it during cleanup. Adapter and reconciliation tests cover revision persistence, concurrent updates, and cleanup outcomes.
Changes: Subscription revision tracking
Layer / File(s)
Summary
Revision data contract and schema openmeter/billing/worker/subscriptionsync/syncstatev2.go, openmeter/ent/schema/subscriptionsyncstatev2.go, tools/migrate/migrations/*_subscription_sync_revisions.*.sql
V2 sync state adds nullable current and last-synced revision fields. The upsert input includes a last-synced revision, and the schema and migrations add the corresponding database columns.
Revision persistence and conflict handling openmeter/billing/worker/subscriptionsync/adapter/syncstatev2.go, openmeter/billing/worker/subscriptionsync/adapter/syncstatev2_test.go
The adapter maps and upserts revision fields. It generates a ULID when the input revision is empty and preserves a non-NULL current revision on conflict. Tests cover legacy rows, generated revisions, and competing writes.
Cleanup revision capture and validation openmeter/billing/worker/subscriptionsync/service/sync.go, openmeter/billing/worker/subscriptionsync/service/*_test.go, openmeter/billing/worker/subscriptionsync/reconciliaton_test.go, openmeter/billing/worker/subscriptionsync/README.md
The service reads v2 state under the billing lock and records the captured revision during cleanup. Tests check lock-time capture, ordinary sync, cleanup, dry-run, and rollback. The README describes the revision behavior.
This adds nullable revision tracking to subscription cleanup sync state without changing reconciliation behavior. No concrete merge-blocking risk was found.
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 revision tracking in the cleanup sync state. The raw summary and PR objectives both describe adding nullable revision columns, acknowledging captured revi…
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 revision tracking in the cleanup sync state. The raw summary and PR objectives both describe adding nullable revision columns, acknowledging captured revisions after successful cleanup, and related tests. The title is concise, specific, and follows the conventional commit style. It does not cover every detail, which is expected.
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
Track the subscription revision observed by a successful cleanup without overwriting changes made while cleanup runs. Sync reads v2 state after acquiring the customer billing lock and before reloading subscription billing intent, then acknowledges that captured revision only after cleanup succeeds.
Adds nullable
last_synced_subs_revisionandcurrent_subs_revisioncolumns. Inserts initialize both to one ULID.ON CONFLICTupdates the acknowledged revision and initializes a NULL current revision while preserving any existing current value.Notes for reviewer
origin/main: PostgreSQL-backed subscription-sync tests, scoped fast lint, Ent regeneration, and Atlas migration validation.go vetalso passed during implementation.Summary by CodeRabbit


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Tracks the subscription revision observed by successful cleanup.
No actionable issues were found. The previous-review merge bases differed, so the full PR was reviewed. Tests were inspected but not run.
Diagram
Reviews (2) · Last reviewed commit: "feat(billing): track subscription revisi..." · Reviewed by Greptile