Skip to content

fix: feature resolve in subscription - #4896

Draft
chrisgacsal wants to merge 2 commits into
mainfrom
fix/subscription-feature-validation
Draft

fix: feature resolve in subscription#4896
chrisgacsal wants to merge 2 commits into
mainfrom
fix/subscription-feature-validation

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Overview

What

Added feature validation for subscription items during create and edit, including feature-only items without entitlements.
Added PostgreSQL-backed regression tests and updated the subscription domain documentation.

Why

Feature validation previously happened indirectly during entitlement scheduling.
Feature-only items skipped that path, allowing subscriptions to reference nonexistent or mismatched features.

How

The subscription service now batch-resolves every item feature before creating or updating a subscription.
It rejects:

  • Unknown feature keys
  • Mismatched feature keys and IDs
    The existing key-based storage model remains unchanged, so no database migration was required.

Summary by CodeRabbit

  • New Features

    • Subscription items now resolve feature references within their subscription namespace during creation and updates.
    • Feature-only items are supported with consistent feature IDs and keys.
    • Feature references can be identified by either ID or key.
  • Bug Fixes

    • Invalid, unknown, mismatched, or cross-namespace feature references are rejected before saving.
    • New subscriptions reject archived features, while existing subscriptions remain editable when features are later archived.
    • Failed subscription edits no longer alter existing items.

Greptile Summary

The PR adds subscription-wide feature-reference validation during create and update, including feature-only items, and documents the intended archive behavior.

  • Adds feature resolution to subscription create and update validation.
  • Adds identity, missing-feature, and archived-feature regression coverage.
  • Introduces an option intended to permit archived feature snapshots during updates.

Confidence Score: 4/5

The PR is not yet safe to merge because updates referencing archived feature snapshots remain blocked.

The update path requests archived references be ignored, but its resolver excludes those features before validation can apply that policy, leaving the previously reported subscription-edit failure reachable.

Files Needing Attention: openmeter/productcatalog/ratecard.go, openmeter/productcatalog/featureresolver/resolver.go, openmeter/subscription/service/servicevalidation.go

Important Files Changed

Filename Overview
openmeter/productcatalog/ratecard.go Adds IgnoreArchived validation behavior, but the option is applied only after production resolution has already excluded archived features.
openmeter/subscription/service/feature.go Collects all subscription item rate cards and validates them through the namespaced production resolver.
openmeter/subscription/service/servicevalidation.go Adds create and update feature validation; the update option cannot currently preserve archived references through the resolver.
openmeter/subscription/service/feature_resolution_test.go Adds PostgreSQL-backed create/edit coverage, including the archived-feature update scenario.
openmeter/productcatalog/ratecard_test.go Tests the new option with a static resolver that bypasses production archived-feature filtering.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  U[Update existing subscription] --> V[validateUpdate with IgnoreArchived]
  V --> R[Production feature resolver]
  R --> L[ListFeatures IncludeArchived=false]
  L --> N[Archived feature omitted]
  N --> E[ErrRateCardFeatureNotFound]
  E --> B[Update blocked before archive check]
Loading

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
### Issue 1
openmeter/productcatalog/ratecard.go:1089-1093
**Archived features remain unresolved**

When an existing subscription references a feature archived after creation, `validateUpdate` passes `IgnoreArchived`, but the production resolver excludes archived features before this check runs. Resolution therefore returns `ErrRateCardFeatureNotFound`, causing unrelated subscription edits to remain blocked.

---

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

Reviews (2): Last reviewed commit: "refactor: use validation instead of reso..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used:

@chrisgacsal
chrisgacsal requested review from GAlexIHU and turip August 10, 2026 08:24
@chrisgacsal chrisgacsal self-assigned this Aug 10, 2026
@chrisgacsal
chrisgacsal requested a review from a team as a code owner August 10, 2026 08:24
@chrisgacsal chrisgacsal added the release-note/bug-fix Release note: Bug Fixes label Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The subscription service now resolves rate-card features before creating or updating subscriptions. It validates feature key and ID pairs, pins resolved IDs, rejects unknown or mismatched references, and applies different archived-feature rules for creation and updates.

Changes

Subscription feature validation

Layer / File(s) Summary
Rate-card validation options
openmeter/productcatalog/ratecard.go, openmeter/productcatalog/ratecard_test.go
ValidateRateCardsWithFeatures now accepts optional options. Archived features remain rejected by default and can be ignored for updates. Tests cover both modes.
Subscription resolver wiring
openmeter/subscription/service/service.go, openmeter/subscription/service/feature.go
The service initializes a product catalog feature resolver and validates non-nil rate cards across subscription phases and items, including feature-only items.
Create and update validation
openmeter/subscription/service/servicevalidation.go, openmeter/subscription/README.md, openmeter/subscription/service/README.md, openmeter/subscription/service/feature_resolution_test.go
Creation rejects unresolved, mismatched, or archived features. Updates resolve and pin features, ignore archival state, and preserve existing subscriptions after failed edits. Documentation and tests describe these rules.

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

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant SubscriptionService
  participant FeatureResolver
  participant Persistence
  Client->>SubscriptionService: create or update subscription
  SubscriptionService->>FeatureResolver: validate item feature references
  FeatureResolver-->>SubscriptionService: resolved references or error
  SubscriptionService->>Persistence: persist valid subscription
  Persistence-->>Client: return subscription result
Loading

Possibly related PRs

Suggested reviewers: galexihu, turip

🚥 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 identifies the main change: feature resolution in subscriptions.
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
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/subscription-feature-validation

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.

turip
turip previously approved these changes Aug 10, 2026
Comment thread openmeter/subscription/service/feature.go Outdated
Comment on lines +1089 to 1093
if !options.IgnoreArchived {
if feat.ArchivedAt != nil && clock.Now().UTC().After(feat.ArchivedAt.UTC()) {
errs = append(errs, models.ErrorWithFieldPrefix(rateCardFieldSelector, ErrRateCardFeatureArchived))
}
}

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 Archived features remain unresolved

When an existing subscription references a feature archived after creation, validateUpdate passes IgnoreArchived, but the production resolver excludes archived features before this check runs. Resolution therefore returns ErrRateCardFeatureNotFound, causing unrelated subscription edits to remain blocked.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/productcatalog/ratecard.go
Line: 1089-1093

Comment:
**Archived features remain unresolved**

When an existing subscription references a feature archived after creation, `validateUpdate` passes `IgnoreArchived`, but the production resolver excludes archived features before this check runs. Resolution therefore returns `ErrRateCardFeatureNotFound`, causing unrelated subscription edits to remain blocked.

**Knowledge Base Used:**
- [Subscription](https://app.greptile.com/openmeter/-/custom-context/knowledge-base/openmeterio/openmeter/-/docs/subscription.md)
- [Product Catalog](https://app.greptile.com/openmeter/-/custom-context/knowledge-base/openmeterio/openmeter/-/docs/productcatalog.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

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
openmeter/productcatalog/ratecard.go (1)

1044-1056: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the archival-policy contract.

Add Go documentation for ValidateRateCardsWithFeaturesOptions and ValidateRateCardsWithFeatures. State that IgnoreArchived bypasses only the archived-feature check. State that feature identity and meter validation still run.

As per coding guidelines, “Document domain helpers whose names compress important business semantics, including observable behavior and why excluded cases are excluded.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/productcatalog/ratecard.go` around lines 1044 - 1056, Add Go doc
comments for ValidateRateCardsWithFeaturesOptions and
ValidateRateCardsWithFeatures that describe the archival-policy contract:
IgnoreArchived bypasses only archived-feature validation, while feature identity
and meter validation continue to run. Include why archived features are excluded
when the option is enabled, without changing implementation behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openmeter/productcatalog/ratecard.go`:
- Around line 1089-1092: Update the archival check in the feature validation
flow to reject features when the current UTC time is equal to or later than
feat.ArchivedAt, replacing the strictly-after comparison while preserving the
existing IgnoreArchived guard and error handling.

---

Nitpick comments:
In `@openmeter/productcatalog/ratecard.go`:
- Around line 1044-1056: Add Go doc comments for
ValidateRateCardsWithFeaturesOptions and ValidateRateCardsWithFeatures that
describe the archival-policy contract: IgnoreArchived bypasses only
archived-feature validation, while feature identity and meter validation
continue to run. Include why archived features are excluded when the option is
enabled, without changing implementation behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: dd151d6d-b8f6-44d9-9576-024f9aaa14e3

📥 Commits

Reviewing files that changed from the base of the PR and between 51f43c3 and c107974.

📒 Files selected for processing (8)
  • openmeter/productcatalog/ratecard.go
  • openmeter/productcatalog/ratecard_test.go
  • openmeter/subscription/README.md
  • openmeter/subscription/service/README.md
  • openmeter/subscription/service/feature.go
  • openmeter/subscription/service/feature_resolution_test.go
  • openmeter/subscription/service/service.go
  • openmeter/subscription/service/servicevalidation.go
💤 Files with no reviewable changes (1)
  • openmeter/subscription/service/service.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • openmeter/subscription/README.md
  • openmeter/subscription/service/README.md

Comment on lines +1089 to +1092
if !options.IgnoreArchived {
if feat.ArchivedAt != nil && clock.Now().UTC().After(feat.ArchivedAt.UTC()) {
errs = append(errs, models.ErrorWithFieldPrefix(rateCardFieldSelector, ErrRateCardFeatureArchived))
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject a feature at its archival timestamp.

At Line 1090, a feature remains valid when clock.Now() equals feat.ArchivedAt. Use an inclusive comparison so creation cannot accept a feature at the instant it becomes archived.

Proposed fix
-				if feat.ArchivedAt != nil && clock.Now().UTC().After(feat.ArchivedAt.UTC()) {
+				if feat.ArchivedAt != nil && !clock.Now().UTC().Before(feat.ArchivedAt.UTC()) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !options.IgnoreArchived {
if feat.ArchivedAt != nil && clock.Now().UTC().After(feat.ArchivedAt.UTC()) {
errs = append(errs, models.ErrorWithFieldPrefix(rateCardFieldSelector, ErrRateCardFeatureArchived))
}
if !options.IgnoreArchived {
if feat.ArchivedAt != nil && !clock.Now().UTC().Before(feat.ArchivedAt.UTC()) {
errs = append(errs, models.ErrorWithFieldPrefix(rateCardFieldSelector, ErrRateCardFeatureArchived))
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/productcatalog/ratecard.go` around lines 1089 - 1092, Update the
archival check in the feature validation flow to reject features when the
current UTC time is equal to or later than feat.ArchivedAt, replacing the
strictly-after comparison while preserving the existing IgnoreArchived guard and
error handling.

@chrisgacsal
chrisgacsal marked this pull request as draft August 11, 2026 08:14
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