Skip to content

feat(billing): track subscription revisions in cleanup sync state - #5538

Merged
turip merged 1 commit into
mainfrom
feat/subscription-sync-revisions
Nov 16, 2026
Merged

turip merged 1 commit into
mainfrom
feat/subscription-sync-revisions

Conversation

@turip

@turip turip commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

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_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.

RetriggerView in GreptileConfidence 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
Loading

Reviews (2) · Last reviewed commit: "feat(billing): track subscription revisi..." · Reviewed by Greptile

@turip
turip requested a review from a team as a code owner November 16, 2026 10:11
@turip turip added the kind/feature New feature or request label Nov 16, 2026 — with ChatGPT Codex Connector
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

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
Run configuration

Commits

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.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant SubscriptionSyncService
  participant CustomerBillingLock
  participant SyncStateAdapter
  participant Reconciler
  SubscriptionSyncService->>CustomerBillingLock: Acquire billing lock
  SubscriptionSyncService->>SyncStateAdapter: Read v2 sync state
  SyncStateAdapter-->>SubscriptionSyncService: Return current revision
  SubscriptionSyncService->>Reconciler: Run reconciliation
  SubscriptionSyncService->>SyncStateAdapter: Write cleanup state with captured revision
Loading

Possibly related PRs

Suggested reviewers: tothandras, chrisgacsal, galexihu

Merge Risk: Minimal · previous review 645e4

This adds nullable revision tracking to subscription cleanup sync state without changing reconciliation behavior. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c987793 and 645e493.

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
Files selected for processing: 11

  • openmeter/billing/worker/subscriptionsync/README.md
  • openmeter/billing/worker/subscriptionsync/adapter/syncstatev2.go
  • openmeter/billing/worker/subscriptionsync/adapter/syncstatev2_test.go
  • openmeter/billing/worker/subscriptionsync/reconciliaton_test.go
  • openmeter/billing/worker/subscriptionsync/service/sync.go
  • openmeter/billing/worker/subscriptionsync/service/sync_lock_test.go
  • openmeter/billing/worker/subscriptionsync/service/sync_test.go
  • openmeter/billing/worker/subscriptionsync/syncstatev2.go
  • openmeter/ent/schema/subscriptionsyncstatev2.go
  • tools/migrate/migrations/20261116094944_subscription_sync_revisions.down.sql
  • tools/migrate/migrations/20261116094944_subscription_sync_revisions.up.sql

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

borosr
borosr previously approved these changes Nov 16, 2026
@turip
turip force-pushed the feat/subscription-sync-revisions branch from 645e493 to 6ab3cee Compare November 16, 2026 10:59
@turip
turip enabled auto-merge (squash) November 16, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants