Skip to content

feat(credits): filter grants by feature spendability - #5317

Merged
GAlexIHU merged 2 commits into
mainfrom
codex/creditgrant-spendability-filters
Oct 20, 2026
Merged

GAlexIHU merged 2 commits into
mainfrom
codex/creditgrant-spendability-filters

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Credit grant listing can now select grants spendable on requested features, including grants without feature restrictions. Matching applies before pagination.

  • filter[feature_key][oeq]=api-calls,storage matches either feature without duplicating shared grants.
  • Shorthand and eq select one feature; exists=false selects grants without feature restrictions.
  • Lifecycle status remains a separate filter.

Reuses the balance/history feature-matching SQL predicates and regenerates the v3 API and SDKs.

Validation: HTTP filter tests, PostgreSQL-backed credit-grant and ledger tests, Go SDK build/vet/tests, TypeScript SDK typecheck, and scoped Go lint.

Summary by CodeRabbit

  • New Features

    • Added feature_key filtering when listing credit grants.
    • Supports exact matching, matching any of multiple feature keys, and selecting grants without feature restrictions.
    • Feature filtering works with pagination and includes unrestricted grants when no filter is provided.
  • Bug Fixes

    • Invalid or conflicting feature filters now return a clear bad-request response.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with no outstanding findings.

Summary

Adds feature_key filtering to credit grant lists, including grants without feature restrictions.

  • Credit grant lists can find grants usable for selected features.

Reviews (3) · Last reviewed commit: "chore(ci): retrigger pull request checks" · Reviewed by Greptile

@GAlexIHU
GAlexIHU requested a review from a team as a code owner October 20, 2026 09:13
@GAlexIHU GAlexIHU added the release-note/feature Release note: Exciting New Features label Oct 20, 2026
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 8214b28a-e1f5-4287-a3ad-b98a6a529661
📥 Commits

Reviewing files that changed from the base of the PR and between daea479 and ac34361.

⛔ Files ignored due to path filters: 1
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing: 18
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip-client-javascript/src/models/types.ts
  • api/spec/packages/aip/src/customers/credits/operations.tsp
  • api/v3/api.gen.go
  • api/v3/client/customers_credits_grants.go
  • api/v3/handlers/customers/credits/feature_filter.go
  • api/v3/handlers/customers/credits/list_grants.go
  • api/v3/handlers/customers/credits/list_grants_test.go
  • openmeter/billing/charges/README.md
  • openmeter/billing/charges/creditpurchase/adapter.go
  • openmeter/billing/charges/creditpurchase/adapter/charge.go
  • openmeter/billing/creditgrant/service.go
  • openmeter/billing/creditgrant/service/service.go
  • openmeter/ledger/account/adapter/subaccount.go
  • openmeter/ledger/historical/adapter/ledger.go
  • openmeter/ledger/historical/adapter/sumentries_query.go
  • openmeter/ledger/internal/routequery/subaccount_ids.go
  • test/credits/creditgrant_test.go
🚧 Files skipped from review as they are similar to previous changes: 1
  • openmeter/billing/charges/README.md

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

📝 Walkthrough

Credit-grant listing now accepts an optional feature-key filter. The handler validates and passes the filter to the listing service, which applies feature predicates to charge queries. Tests cover supported and invalid filters, unrestricted grants, totals, and pagination.

Changes: Credit grant feature filtering

Layer / File(s) Summary
API contract and request parsing
api/spec/packages/aip/..., api/spec/packages/aip-client-javascript/src/models/*, api/v3/api.gen.go, api/v3/client/customers_credits_grants.go, api/v3/handlers/customers/credits/*
The API specifications and clients add the feature_key filter. The handler validates supported operators and passes valid filters to the listing request. Invalid filters return HTTP 400.
Filter propagation and grant selection
openmeter/billing/creditgrant/*, openmeter/billing/charges/creditpurchase/*, openmeter/ledger/creditfilterquery/*, openmeter/ledger/account/adapter/subaccount.go, openmeter/ledger/historical/adapter/*, openmeter/ledger/internal/routequery/subaccount_ids.go, openmeter/billing/charges/README.md, test/credits/creditgrant_test.go
The listing service and charge adapter validate and propagate feature filters. Charge queries combine exact-feature and match-feature predicates. Ledger predicate references use creditfilterquery. Tests cover matching, unrestricted grants, totals, and pagination.

Priority: ⬇️ Low

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ListCreditGrants
  participant CreditGrantService as creditgrant.service.List
  participant ChargeAdapter as creditpurchase.ListCharges
  participant SQLSelector
  ListCreditGrants->>CreditGrantService: validated FeatureFilters
  CreditGrantService->>ChargeAdapter: FeatureFilters
  ChargeAdapter->>SQLSelector: feature predicates before pagination
Loading

Suggested reviewers: borosr, tothandras, mark-vass-konghq

Merge Risk: ⚪ Minimal · up to 5fd4d

Merge Risk: ⚪ Minimal · up to 5fd4d

The feature-key filter has no identified issue that should block merging after normal checks.

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 clearly and concisely describes the main change: adding feature-spendability filtering to credit grant listings.
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
  • 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

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

@GAlexIHU
GAlexIHU force-pushed the codex/creditgrant-spendability-filters branch from daea479 to ac34361 Compare October 20, 2026 09:38
@GAlexIHU GAlexIHU changed the title feat(credits): add grant spendability filters feat(credits): filter grants by feature spendability Oct 20, 2026
@GAlexIHU
GAlexIHU changed the base branch from codex/credit-plan-query-filters to main October 20, 2026 09:39
@GAlexIHU
GAlexIHU enabled auto-merge (squash) October 20, 2026 09:43
@greptile-apps

greptile-apps Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P2 Tracing rethrows production panics pkg/framework/tracex/v2/span.go:94 ▶

    The new tracing helper calls panic(r) in production code. The repository guide says, “Never use panic in non-test code. Return and propagate errors.” Recording the callback failure does not satisfy that requirement while the helper still rethrows it.

    Return the failure through the helper’s error result instead. This repository requirement must be satisfied before merging.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@GAlexIHU
GAlexIHU disabled auto-merge October 20, 2026 12:20
@GAlexIHU
GAlexIHU merged commit 705cc6b into main Oct 20, 2026
36 checks passed
@GAlexIHU
GAlexIHU deleted the codex/creditgrant-spendability-filters branch October 20, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants