Skip to content

fix(subscription): allow rate card currency changes in edits - #5213

Merged
GAlexIHU merged 1 commit into
mainfrom
codex/fix-subscription-edit-currency
Sep 25, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
codex/fix-subscription-edit-currency

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Remove/add subscription edits incorrectly rejected a replacement rate card when its currency differed from an earlier version under the same item key. Remove the extra currency immutability check so an omitted currency defaults to the subscription invoice currency and an explicit currency follows normal resolution and validation.

Notes for reviewer

  • Regression tests cover fiat/custom currency switches, defaulting, historical item currency and timing, and rejection of mismatched fiat, unknown currencies, and missing cost bases.
  • Confirmed the regression tests reproduce the original restriction. All four affected subscription, patch, service, and workflow test packages pass with PostgreSQL enabled.
  • Updated the subscription materialization and migration documentation.

Summary by CodeRabbit

  • New Features
    • You can now change the currency of a replacement item when editing a running subscription. If you omit the currency, it defaults to the subscription’s invoice currency.
  • Validation
    • Replacement item currencies are checked against the subscription’s currency rules, including fiat compatibility and cost-basis requirements. Invalid edits are rejected without changing the subscription.
    • The subscription’s invoice currency remains unchanged when replacing an item.

RetriggerConfidence Score: 4/5

The PR should not merge until updates are prevented from changing the currency of an existing item version.

Fix All in Claude CodeFindings

  1. P1 Existing item currencies can change ▶
  2. P2 Direct update path lacks coverage ▶
Fix with agent prompt
### Issue 1
openmeter/subscription/service/servicevalidation.go:69-72
`SubscriptionService.Update` accepts a complete spec, not only remove/add edits. A caller can change the currency of an item version at its existing phase, key, and index. With this check removed, the service accepts that change, then archives and recreates the indexed item with the new currency. That lets an update rewrite historical pricing terms instead of adding a new term at an effective time. Please allow currency changes for new replacement versions while protecting existing versions.

### Issue 2
openmeter/subscription/workflow/service/edit_currency_test.go:102-117
These cases all replace an item through `EditRunning` with remove/add patches. They do not cover a direct `SubscriptionService.Update` that changes the currency at an existing item-version index, even though that service path lost its currency check and its service-layer tests. Add a test that distinguishes an existing-version change from a valid appended replacement; without it, a regression in historical pricing terms could go unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR removes subscription-update item-currency immutability, documents currency changes for replacement versions and migrations, and adds running-edit regression tests. The removed check also leaves direct updates able to change an existing version’s currency.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Edit[Remove/add running edit] --> Spec[Complete target spec]
  Direct[Direct service update] --> Spec
  Spec --> Validate[Currency and spec validation]
  Validate --> Sync[Compare items by version index]
  Sync --> Replace[Archive and recreate changed item]
Loading

Reviews (1) · Last reviewed commit: "fix(subscription): allow rate card curre..."

@GAlexIHU
GAlexIHU requested a review from a team as a code owner September 25, 2026 14:11
@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Sep 25, 2026
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openmeterio/openmeter/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e439ddf5-f2d4-411c-bd91-81bfda787d85

📥 Commits

Reviewing files that changed from the base of the PR and between 49638d2 and 5aaea2c.

📒 Files selected for processing (5)
  • openmeter/subscription/service/README.md
  • openmeter/subscription/service/servicevalidation.go
  • openmeter/subscription/service/servicevalidation_test.go
  • openmeter/subscription/workflow/README.md
  • openmeter/subscription/workflow/service/edit_currency_test.go
💤 Files with no reviewable changes (2)
  • openmeter/subscription/service/servicevalidation_test.go
  • openmeter/subscription/service/servicevalidation.go

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


📝 Walkthrough

Walkthrough

Subscription updates can now use a different currency for a replacement item version. The invoice currency remains unchanged. Integration tests cover currency defaults, explicit currency validation, and persisted item history.

Changes

Replacement item currency edits

Layer / File(s) Summary
Allow replacement item currencies to change
openmeter/subscription/service/README.md, openmeter/subscription/service/servicevalidation.go, openmeter/subscription/service/servicevalidation_test.go
Update validation no longer checks that materialized items retain their currencies or that priced versions in a phase and item group share an established currency. The service documentation states that replacement item currencies may change.
Verify currency edits and migration rules
openmeter/subscription/workflow/service/edit_currency_test.go, openmeter/subscription/workflow/README.md
Integration tests cover default and explicit replacement currencies, validation errors, persisted item history, and unchanged invoice currency. Migration documentation describes normal currency validation for replacement items while keeping invoice currency unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Suggested reviewers: turip

Merge Risk: ⚪ Minimal · up to 5aaea

Currency edits preserve historical item versions, and no remaining issue prevents merging after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 5aaea

Normal currency and invoice checks remain in place, but the broader validation removal may also allow changes to historical item currencies. The billing-history implications and behavior under overlapping edits need confirmation.

Retained concerns

  • Medium · security · inferred: Removing the entire update-time comparison appears to permit a direct specification update to change the currency of an already materialized item, rather than only assigning a different currency to a new replacement version. The sync path can replace an item whose desired state differs. Whether an authorized production caller can submit such an amendment, and its effect on billed history, is unverified.
Security review details

Security Blast Radius

  • inferred — The demonstrated effect is within subscription item history and billing-currency selection for an addressed subscription. The evidence does not establish a new external entrypoint or cross-tenant currency lookup.

Trust Boundaries and Controls

  • observed — Replacement rate cards undergo namespace-scoped currency resolution; the tests reject mismatched fiat, unknown currencies, and missing required cost bases without changing the stored specification.

Hardening Proposals

  • proposed — Preserve currency immutability for previously materialized item versions while allowing a new replacement version to select a validated currency; verify direct historical amendments and overlapping same-plan edits against that boundary.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing rate card currency changes during subscription edits.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

Comment @coderabbitai help to get the list of available commands.

@GAlexIHU
GAlexIHU enabled auto-merge (squash) September 25, 2026 14:12
Comment on lines 69 to 72
))
}

if err := validateMaterializedItemCurrenciesUnchanged(currentView.Spec, newSpec); err != nil {
return err
}

// Fetch the customer & validate the customer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Existing item currencies can change

SubscriptionService.Update accepts a complete spec, not only remove/add edits. A caller can change the currency of an item version at its existing phase, key, and index. With this check removed, the service accepts that change, then archives and recreates the indexed item with the new currency. That lets an update rewrite historical pricing terms instead of adding a new term at an effective time. Please allow currency changes for new replacement versions while protecting existing versions.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/subscription/service/servicevalidation.go
Line: 69-72

Comment:
**Existing item currencies can change**

`SubscriptionService.Update` accepts a complete spec, not only remove/add edits. A caller can change the currency of an item version at its existing phase, key, and index. With this check removed, the service accepts that change, then archives and recreates the indexed item with the new currency. That lets an update rewrite historical pricing terms instead of adding a new term at an effective time. Please allow currency changes for new replacement versions while protecting existing versions.

**Knowledge Base Used:**
- [Subscription lifecycle](https://app.greptile.com/openmeter/-/custom-context/knowledge-base/openmeterio/openmeter/-/docs/subscription-lifecycle.md)
- [Product catalog and subscriptions](https://app.greptile.com/openmeter/-/custom-context/knowledge-base/openmeterio/openmeter/-/docs/product-catalog-and-subscriptions.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Comment on lines +102 to +117
_, err = deps.WorkflowService.EditRunning(t.Context(), created.Subscription.NamespacedID, []subscription.Patch{
patch.PatchRemoveItem{PhaseKey: phaseKey, ItemKey: itemKey},
patch.PatchAddItem{
PhaseKey: phaseKey,
ItemKey: itemKey,
CreateInput: subscription.SubscriptionItemSpec{
CreateSubscriptionItemInput: subscription.CreateSubscriptionItemInput{
CreateSubscriptionItemPlanInput: subscription.CreateSubscriptionItemPlanInput{
PhaseKey: phaseKey,
ItemKey: itemKey,
RateCard: replacement,
},
},
},
},
}, immediate)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Direct update path lacks coverage

These cases all replace an item through EditRunning with remove/add patches. They do not cover a direct SubscriptionService.Update that changes the currency at an existing item-version index, even though that service path lost its currency check and its service-layer tests. Add a test that distinguishes an existing-version change from a valid appended replacement; without it, a regression in historical pricing terms could go unnoticed.

Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/subscription/workflow/service/edit_currency_test.go
Line: 102-117

Comment:
**Direct update path lacks coverage**

These cases all replace an item through `EditRunning` with remove/add patches. They do not cover a direct `SubscriptionService.Update` that changes the currency at an existing item-version index, even though that service path lost its currency check and its service-layer tests. Add a test that distinguishes an existing-version change from a valid appended replacement; without it, a regression in historical pricing terms could go unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

@GAlexIHU
GAlexIHU merged commit f32c3d6 into main Sep 25, 2026
29 of 31 checks passed
@GAlexIHU
GAlexIHU deleted the codex/fix-subscription-edit-currency branch September 25, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants