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
fix(billing): creating a product no longer removes a shared feature from its other products - #2064
Creating a product (or a feature) that references an already-existing feature replaced the feature's stored product links with only the incoming product, silently unlinking the feature from every other product it belonged to. UpsertFeature now unions the incoming product IDs with the stored ones, so an upsert only ever adds links.
billing/product: UpsertFeature unions the existing and incoming ProductIDs (deduplicated) instead of replacing the stored set. This covers both create paths that funnel through it: Service.Create (product create with features) and the CreateFeature API handler.
billing/plan: the final convergence loop in UpsertPlans now calls UpdateFeature instead of UpsertFeature (and UpdateFeature joins the ProductService interface). That loop deliberately converges the stored set to exactly what the plan file states, including removing the feature from products that no longer list it; UpdateFeature keeps those replace semantics.
billing/product tests: regression case for the union — a feature stored with products A+B, upserted with product C, ends up stored with A+B+C.
Technical Details
Shrinking a feature's product set stays possible and deliberate: UpdateFeature (full replace) and RemoveFeatureFromProduct are unchanged. The BillingFeature reconciler is unaffected — it creates new features through CreateFeature without product IDs and routes updates through UpdateFeature.
Test Plan
New regression test fails on the old code (stored set would have been just the incoming product) and passes with the fix
Updating a feature’s product associations now preserves existing links when adding another product, instead of replacing them.
Plan updates apply the product associations provided for each feature.
Feature upserts now preserve existing product links and add incoming links. Plan reconciliation uses UpdateFeature to apply the product IDs derived from plan files.
Changes: Feature product links
Layer / File(s)
Summary
Additive upserts and plan link replacement billing/plan/service.go, billing/product/service.go, billing/product/service_test.go
UpsertFeature deduplicates existing and incoming product IDs. Plan reconciliation calls UpdateFeature with plan-derived product IDs. The test checks that an upsert retains prior product links and adds the incoming link.
raystack/frontier#2046: Adds the BillingFeature reconcile kind and references the product-link behavior changed here.
Suggested reviewers:kushsharma, rohanchkrabrty
Merge Risk: Low · up to 05d87
Creating a product with an existing feature now adds the link instead of removing the feature's other product links, and plan files still replace the full set. A remaining edge case is two simultaneous upserts of the same feature, where one added link could be lost. This race was already present and is bounded, so the change is mergeable with a follow-up to make the merge atomic.
Pre-merge checks: 2
Check name
Status
Explanation
Linked Issues check
Issue #2047 requires that creating a product with an existing feature adds the new product link without removing existing links. It also requires that CreateFeature on an existing name either fail wit…
Out of Scope Changes check
All changes connect to #2047. The UpsertFeature union in billing/product/service.go is the core fix. The billing/plan/service.go change adds UpdateFeature to the ProductService interface and switches …
Full details: Linked Issues check
Explanation
Issue #2047 requires that creating a product with an existing feature adds the new product link without removing existing links. It also requires that CreateFeature on an existing name either fail with "already exists" or keep existing links. The PR changes UpsertFeature in billing/product/service.go to union the incoming ProductIDs with the stored ones, deduplicated (per the whole-PR AI summary and PR description). Service.Create calls UpsertFeature for each product feature, so the product-create path now adds links. The CreateFeature handler also goes through UpsertFeature, so an existing name keeps its links and adds the request's product IDs, which satisfies the second expected behavior. The regression test in billing/product/service_test.go covers the A+B plus C case. The UpsertPlans convergence loop now calls UpdateFeature, which keeps replace semantics. The issue states that UpsertPlans intentionally rebuilds the full link list, so this preserves its behavior. Limitation: the raw diff blobs were unavailable in this review, so the verdict relies on the supplied summary and PR description, not a direct read of the changed hunks. The UpdateFeature behavior for a feature that does not yet exist was not verified.
Full details: Out of Scope Changes check
Explanation
All changes connect to #2047. The UpsertFeature union in billing/product/service.go is the core fix. The billing/plan/service.go change adds UpdateFeature to the ProductService interface and switches the final UpsertPlans convergence loop to UpdateFeature. This is required so the fix does not change plan-file convergence, which the issue says must keep rebuilding the full link list. The billing/product/service_test.go addition is a regression test for the union. No unrelated changes were identified in the supplied summary. Limitation: the raw diff blobs were unavailable, so the assessment relies on the supplied summary and PR description for the full change list.
Finishing Touches
Fix failing CI checks
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.
Reviewing files that changed from the base of the PR and between 4e33f29 and 05d8731.
Files selected for processing: 3
billing/plan/service.go
billing/product/service.go
billing/product/service_test.go
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Heavy lift
UpsertFeature can lose product links under concurrent calls.
UpsertFeature reads the stored product IDs, adds the incoming IDs in memory, and then writes the full array with UpdateByName. The write does not depend on the earlier read, and no transaction or lock covers both steps. If two calls for the same feature run concurrently, the call that commits last overwrites the other call's added link. For example, both calls read [A], one adds B, the other adds C, and the final stored value is either [A,B] or [A,C]. The lost link is not reported as an error.
The union in this change does not remove this race. The earlier full-replacement write had the same race, so the change does not introduce it. The union also does not prevent it, because the merge still happens outside the write.
Make the link merge part of the persisted write. Use one statement that unions the stored product_ids with the incoming IDs, or serialize the read and write for each feature name. Keep UpdateByName replace semantics for UpdateFeature and RemoveFeatureFromProduct, which remove links on purpose.
This branch has not been deployed
No deployments
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.
Summary
Creating a product (or a feature) that references an already-existing feature replaced the feature's stored product links with only the incoming product, silently unlinking the feature from every other product it belonged to.
UpsertFeaturenow unions the incoming product IDs with the stored ones, so an upsert only ever adds links.Fixes #2047
Changes
billing/product:UpsertFeatureunions the existing and incomingProductIDs(deduplicated) instead of replacing the stored set. This covers both create paths that funnel through it:Service.Create(product create with features) and theCreateFeatureAPI handler.billing/plan: the final convergence loop inUpsertPlansnow callsUpdateFeatureinstead ofUpsertFeature(andUpdateFeaturejoins theProductServiceinterface). That loop deliberately converges the stored set to exactly what the plan file states, including removing the feature from products that no longer list it;UpdateFeaturekeeps those replace semantics.billing/producttests: regression case for the union — a feature stored with products A+B, upserted with product C, ends up stored with A+B+C.Technical Details
Shrinking a feature's product set stays possible and deliberate:
UpdateFeature(full replace) andRemoveFeatureFromProductare unchanged. The BillingFeature reconciler is unaffected — it creates new features throughCreateFeaturewithout product IDs and routes updates throughUpdateFeature.Test Plan
go build ./...passesgo test ./billing/product/ ./billing/plan/passes