Skip to content

feat: strengthen namespace validate - #4905

Merged
turip merged 9 commits into
mainfrom
feat/strengthen-namespace-isolation
Aug 11, 2026
Merged

turip merged 9 commits into
mainfrom
feat/strengthen-namespace-isolation

Conversation

@turip

@turip turip commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Overview

This PR makes namespace handling explicit and consistent across billing reads and writes, background invoice processing, app-customer relationships, Stripe integration data, and app-owned secrets.

High-level changes

Billing and invoice workers

  • changes standard and gathering invoice list operations to accept one required namespace
  • scopes invoice lines, detailed lines, discounts, workflow configuration, and tax-code expansions to the owning namespace
  • lists unique namespaced customer IDs for collection instead of hydrating gathering invoices
  • lists namespaced invoice IDs for automatic advancement instead of hydrating full invoices
  • validates customer, profile, workflow, and tax-code references at billing repository boundaries
  • logs reference mismatches encountered while mapping persisted billing configuration

Apps, Stripe, and secrets

  • validates app and customer parents before creating app-customer relationships
  • scopes custom-invoicing and Stripe customer-data writes to the requested namespace
  • binds Stripe API-key and webhook-secret references to the exact app and expected semantic key
  • validates that secret identity, app ownership, namespace, and update key remain consistent
  • documents the deliberate Stripe webhook namespace-bootstrap flow

Tests

  • adds repository-backed coverage for billing profiles, customer overrides, invoice relations, collection candidates, app-customer data, Stripe customer data, and secret references
  • includes deliberately mismatched persisted references to verify read and write behavior at adapter boundaries

Review guide

The billing changes are centered in openmeter/billing/adapter and the collection/advancement workers. App relationship changes are under openmeter/app, while Stripe credential ownership is shared between openmeter/app/stripe and openmeter/secret.

Plan-specific changes were split into the stacked PR #4906.

Integration note

The collection and advancement worker interfaces now return lightweight customer and invoice identities. The corresponding openmeterio/cloud billing-worker consumers need to be updated before that repository advances its OpenMeter dependency.

Validation

GitHub CI passes build, lint, tests, E2E, code generation, migration checks, Quickstart, dependency review, and repository/security scans.

No Jira ticket; this is a bug fix.

Summary by CodeRabbit

  • New Features

    • Added customer-focused collection discovery for invoices ready to collect.
    • Invoice advancement now operates using invoice IDs.
    • Billing and plan searches require a single namespace.
  • Bug Fixes

    • Strengthened namespace isolation across billing, plans, customers, tax, currency, invoice, and Stripe data.
    • Added validation for missing or mismatched application, customer, secret, billing, and catalog references.
    • Improved Stripe credential and webhook association validation.
  • Documentation

    • Documented Stripe secret ownership and webhook namespace handling.

Greptile Summary

This PR strengthens namespace isolation across billing, invoice workers, app-customer relationships, Stripe data, and app-owned secrets.

  • Requires explicit namespace scoping for invoice reads, related entities, and billing configuration references.
  • Changes collection and advancement workers to process lightweight namespaced customer and invoice identities.
  • Validates app, customer, profile, tax-code, Stripe credential, and secret ownership at persistence boundaries.
  • Adds repository-backed coverage for cross-namespace and mismatched-reference behavior.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
openmeter/billing/adapter/gatheringinvoice.go Adds namespaced collection-candidate discovery and scopes gathering-invoice hydration and relations.
openmeter/billing/adapter/customeroverride.go Validates profile and customer references and rejects mismatched persisted profile or tax-code relationships.
openmeter/app/adapter/customer.go Validates app and customer existence within their declared namespaces before creating relationships.
openmeter/app/stripe/types.go Binds Stripe API-key and webhook-secret references to the exact app and expected semantic keys.
openmeter/secret/entity/secret.go Strengthens secret identity and ownership validation across app, namespace, and semantic key fields.
test/billing/customeroverride_test.go Adds namespace-isolation tests using the suite-provided cancellable test context.

Reviews (7): Last reviewed commit: "Revert "fix: strengthen plan namespace i..." | Re-trigger Greptile

Context used:

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Invoice and plan APIs now require singular namespaces. Billing, application, secret, Stripe, and product-catalog references enforce namespace ownership. Collection discovery returns customer IDs, and advancement discovery returns invoice IDs.

Changes

Namespace isolation and billing workflows

Layer / File(s) Summary
Billing namespace contracts and request propagation
openmeter/billing/..., api/v3/handlers/..., openmeter/billing/httpdriver/..., openmeter/productcatalog/plan/...
List inputs now use a required singular Namespace field. Callers and tests pass namespace values through the updated contracts.
Namespace-aware billing reads and writes
openmeter/billing/adapter/..., openmeter/productcatalog/...
Invoice lines, profiles, tax codes, currencies, plans, add-ons, and customer overrides validate and load namespace-matching references.
Collection and advancement flows
openmeter/billing/worker/..., cmd/jobs/billing/...
Collection discovery returns unique customer IDs. Advancement discovery returns invoice IDs.
App, Stripe, custom-invoicing, and secret ownership checks
openmeter/app/..., openmeter/secret/...
Relationships, credentials, customer data, and secret updates validate app, customer, key, and namespace ownership.
Regression coverage and documentation
test/..., openmeter/app/stripe/README.md
Tests cover namespace isolation, reference validation, pending candidates, and updated request fields. Stripe documentation describes app and webhook secret ownership.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Suggested labels: kind/refactor

Suggested reviewers: chrisgacsal, borbelyr-kong

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: stronger namespace validation across billing, app, Stripe, secret, and product catalog operations.
✨ 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 feat/strengthen-namespace-isolation

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.

Comment thread test/billing/customeroverride_test.go Resolved
@turip
turip marked this pull request as ready for review August 11, 2026 08:51
@turip
turip requested a review from a team as a code owner August 11, 2026 08:51
@turip turip added release-note/misc Miscellaneous changes area/billing labels Aug 11, 2026

@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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
openmeter/app/stripe/types.go (1)

39-88: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use the required validation error contract in all changed input validators.

These validators return early raw errors or a non-nillable generic error. Collect the field errors and return models.NewNillableGenericValidationError(errors.Join(errs...)) instead.

  • openmeter/app/stripe/types.go#L39-L88: Aggregate app, namespace, API key, and webhook secret validation errors with field context.
  • openmeter/secret/entity/input.go#L54-L70: Aggregate app ID, secret ID, and key validation errors with field context.
  • openmeter/billing/gatheringinvoice.go#L1006-L1023: Wrap the joined namespace, page, and expand errors in models.NewNillableGenericValidationError.
  • openmeter/billing/gatheringinvoice.go#L1038-L1043: Collect the AsOf validation error and return the required nillable generic validation error.

As per coding guidelines, Validate() error must collect field errors and return models.NewNillableGenericValidationError(errors.Join(errs...)).

🤖 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/app/stripe/types.go` around lines 39 - 88, Update Validate() in
openmeter/app/stripe/types.go (lines 39-88) to collect app, namespace, API key,
and webhook secret field errors with context, then return
models.NewNillableGenericValidationError(errors.Join(errs...)); update
openmeter/secret/entity/input.go (lines 54-70) similarly for app ID, secret ID,
and key errors; in openmeter/billing/gatheringinvoice.go (lines 1006-1023), wrap
joined namespace, page, and expand errors with the required nillable generic
error; and at lines 1038-1043, collect the AsOf error and return
models.NewNillableGenericValidationError(errors.Join(errs...)).

Source: Coding guidelines

🧹 Nitpick comments (4)
test/billing/customeroverride_test.go (2)

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

Swap context.Background() for s.T().Context() in these new tests.

All four new tests have s.T() available, so the test context is the right choice. It also cancels on test completion, which keeps the DB work tied to the test lifetime. The new tests in test/billing/adapter_test.go in this same PR already use s.T().Context(), so this also lines the two files up.

♻️ Proposed change (apply at each of the four sites)
-	ctx := context.Background()
+	ctx := s.T().Context()

As per coding guidelines: "Use t.Context() whenever a testing.T or testing.TB is available."

Also applies to: 69-69, 101-101, 129-129

🤖 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 `@test/billing/customeroverride_test.go` at line 33, Replace
context.Background() with s.T().Context() at all four new test sites in the
customer override tests, preserving the existing context usage otherwise and
tying database work to the test lifecycle.

Source: Coding guidelines


165-169: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add a nil check before reading override.Profile.ID.

GetCustomerOverride returns nil, nil when no override exists, as the assertion at line 158 shows. If the bulk assignment silently writes nothing, line 169 panics instead of reporting a clean assertion failure.

🛡️ Proposed guard
 	require.NoError(s.T(), err)
+	require.NotNil(s.T(), override)
 	require.Equal(s.T(), targetProfile.ID, override.Profile.ID)
🤖 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 `@test/billing/customeroverride_test.go` around lines 165 - 169, Before
accessing override.Profile.ID in the GetCustomerOverride test flow, assert that
override is non-nil after require.NoError. Keep the existing targetProfile.ID
comparison, but ensure a missing override produces a clean test failure instead
of a nil dereference.
test/billing/adapter_test.go (1)

193-198: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Nice isolation coverage — consider tightening the bare require.Error checks.

These three assertions pass for any error, including one caused by a setup mistake rather than by the namespace guard. require.ErrorContains (or require.ErrorIs where a sentinel exists) pins the test to the behaviour you actually want to protect. The mapper messages are stable, for example the missing-invoice message in openmeter/billing/adapter/invoicelinesplitgroup.go line 232 and the missing-usage-config message in openmeter/billing/adapter/stdinvoicelinemapper.go line 135.

♻️ Example for the split-line-group invoice subtest
-		require.Error(s.T(), err)
+		require.ErrorContains(s.T(), err, "billing invoice must be expanded")

Also applies to: 352-352

🤖 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 `@test/billing/adapter_test.go` around lines 193 - 198, Replace the bare
require.Error assertions in the relevant billing adapter tests, including the
GetGatheringInvoiceById case, with require.ErrorContains or require.ErrorIs
checks for the expected namespace-guard mapper messages. Assert the stable
missing-invoice and missing-usage-config errors so setup failures cannot satisfy
the tests.
openmeter/billing/adapter/profile.go (1)

506-511: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Nice guard — one small tweak to make the log easier to act on.

The dbWC == nil case and the namespace mismatch case take the same branch, so a workflow config edge that was simply not eager-loaded gets reported as an "isolation violation". The log also has no identifier, which makes the returned "billing workflow config not found" hard to trace. Splitting the two cases keeps the real isolation signal clean.

♻️ Proposed split of the two failure modes
-	if dbWC == nil || dbWC.Namespace != namespace {
-		a.logger.ErrorContext(ctx, "billing workflow config namespace isolation violation",
-			"expected_namespace", namespace,
-		)
-		return billing.WorkflowConfig{}, models.NewGenericNotFoundError(fmt.Errorf("billing workflow config not found"))
-	}
+	if dbWC == nil {
+		a.logger.ErrorContext(ctx, "billing workflow config edge is not loaded",
+			"expected_namespace", namespace,
+		)
+		return billing.WorkflowConfig{}, models.NewGenericNotFoundError(fmt.Errorf("billing workflow config not found"))
+	}
+
+	if dbWC.Namespace != namespace {
+		a.logger.ErrorContext(ctx, "billing workflow config namespace isolation violation",
+			"workflow_config_id", dbWC.ID,
+			"expected_namespace", namespace,
+			"actual_namespace", dbWC.Namespace,
+		)
+		return billing.WorkflowConfig{}, models.NewGenericNotFoundError(fmt.Errorf("billing workflow config not found [id=%s]", dbWC.ID))
+	}
🤖 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/billing/adapter/profile.go` around lines 506 - 511, Split the guard
in the workflow-config lookup around dbWC so a nil config logs a
not-found/missing-config message, while a non-nil config with a different
Namespace retains the isolation-violation log. Include the workflow config
identifier in both messages, and preserve the existing not-found return
behavior.
🤖 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/billing/customeroverride.go`:
- Around line 376-378: Update Validate() to accumulate profile and customer
validation failures in an errs collection instead of returning on the first
mismatch. Preserve indexed field context by wrapping each validation error,
continue checking all fields, and return
models.NewNillableGenericValidationError(errors.Join(errs...)) after validation
completes.

In `@openmeter/billing/invoice.go`:
- Around line 328-330: The Namespace checks in both validators currently append
raw errors and return errors.Join directly; update both validator methods to
return models.NewNillableGenericValidationError(errors.Join(outErr...)) while
preserving the namespace field context by wrapping the validation errors
consistently with the existing field validators.

In `@openmeter/billing/stdinvoice.go`:
- Around line 1189-1191: Update the namespace validation branch in Validate() to
wrap the “namespace is required” error with the namespace field context,
matching the existing expand: and externalIDs: validation errors before joining
them.

In `@openmeter/billing/worker/collect/collect.go`:
- Around line 33-40: Update ListCustomersToCollectInput.Validate to wrap the
joined validation errors with models.NewNillableGenericValidationError before
returning. Preserve the existing AsOf validation and collected field-error
behavior.

In `@test/billing/invoice_test.go`:
- Line 3952: Update the test setup around ctx in the affected suite test to use
s.T().Context() instead of context.Background(), preserving the test’s existing
context usage while inheriting the suite deadline and cancellation scope.

In `@test/billing/profile_test.go`:
- Line 35: Replace context.Background() with s.T().Context() in the test setup,
preserving the existing context usage while binding database calls to the suite
test lifecycle and cancellation scope.

---

Outside diff comments:
In `@openmeter/app/stripe/types.go`:
- Around line 39-88: Update Validate() in openmeter/app/stripe/types.go (lines
39-88) to collect app, namespace, API key, and webhook secret field errors with
context, then return
models.NewNillableGenericValidationError(errors.Join(errs...)); update
openmeter/secret/entity/input.go (lines 54-70) similarly for app ID, secret ID,
and key errors; in openmeter/billing/gatheringinvoice.go (lines 1006-1023), wrap
joined namespace, page, and expand errors with the required nillable generic
error; and at lines 1038-1043, collect the AsOf error and return
models.NewNillableGenericValidationError(errors.Join(errs...)).

---

Nitpick comments:
In `@openmeter/billing/adapter/profile.go`:
- Around line 506-511: Split the guard in the workflow-config lookup around dbWC
so a nil config logs a not-found/missing-config message, while a non-nil config
with a different Namespace retains the isolation-violation log. Include the
workflow config identifier in both messages, and preserve the existing not-found
return behavior.

In `@test/billing/adapter_test.go`:
- Around line 193-198: Replace the bare require.Error assertions in the relevant
billing adapter tests, including the GetGatheringInvoiceById case, with
require.ErrorContains or require.ErrorIs checks for the expected namespace-guard
mapper messages. Assert the stable missing-invoice and missing-usage-config
errors so setup failures cannot satisfy the tests.

In `@test/billing/customeroverride_test.go`:
- Line 33: Replace context.Background() with s.T().Context() at all four new
test sites in the customer override tests, preserving the existing context usage
otherwise and tying database work to the test lifecycle.
- Around line 165-169: Before accessing override.Profile.ID in the
GetCustomerOverride test flow, assert that override is non-nil after
require.NoError. Keep the existing targetProfile.ID comparison, but ensure a
missing override produces a clean test failure instead of a nil dereference.
🪄 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: 8838fe7f-2eee-4852-870f-30640ab49964

📥 Commits

Reviewing files that changed from the base of the PR and between 8db1746 and bac38dc.

📒 Files selected for processing (72)
  • api/v3/handlers/billinginvoices/list.go
  • cmd/jobs/billing/advance/advance.go
  • cmd/jobs/billing/collect/collect.go
  • openmeter/app/adapter/app.go
  • openmeter/app/adapter/customer.go
  • openmeter/app/adapter/customer_test.go
  • openmeter/app/custominvoicing/adapter/customerdata.go
  • openmeter/app/custominvoicing/adapter/customerdata_test.go
  • openmeter/app/stripe/README.md
  • openmeter/app/stripe/adapter/customer.go
  • openmeter/app/stripe/adapter/customer_test.go
  • openmeter/app/stripe/adapter/stripe.go
  • openmeter/app/stripe/service/billing.go
  • openmeter/app/stripe/types.go
  • openmeter/app/stripe/types_test.go
  • openmeter/billing/adapter.go
  • openmeter/billing/adapter/customeroverride.go
  • openmeter/billing/adapter/gatheringinvoice.go
  • openmeter/billing/adapter/gatheringlines.go
  • openmeter/billing/adapter/invoice.go
  • openmeter/billing/adapter/invoice_advancement.go
  • openmeter/billing/adapter/invoicelinesplitgroup.go
  • openmeter/billing/adapter/profile.go
  • openmeter/billing/adapter/stdinvoicelinediff_test.go
  • openmeter/billing/adapter/stdinvoicelinemapper.go
  • openmeter/billing/adapter/stdinvoicelines.go
  • openmeter/billing/charges/invoiceupdater/invoiceupdate.go
  • openmeter/billing/charges/service/creditpurchase_test.go
  • openmeter/billing/charges/service/gathering_preview_test.go
  • openmeter/billing/charges/service/invoicable_test.go
  • openmeter/billing/charges/service/pendinglines_test.go
  • openmeter/billing/charges/service/taxcode_test.go
  • openmeter/billing/charges/service/usagebased_test.go
  • openmeter/billing/customeroverride.go
  • openmeter/billing/gatheringinvoice.go
  • openmeter/billing/httpdriver/invoice.go
  • openmeter/billing/invoice.go
  • openmeter/billing/invoice_test.go
  • openmeter/billing/service.go
  • openmeter/billing/service/customeroverride.go
  • openmeter/billing/service/gatheringinvoice.go
  • openmeter/billing/service/gatheringinvoicependinglines.go
  • openmeter/billing/service/invoice.go
  • openmeter/billing/service/stdinvoice.go
  • openmeter/billing/service/stdinvoiceline.go
  • openmeter/billing/stdinvoice.go
  • openmeter/billing/stdinvoice_test.go
  • openmeter/billing/validators/customer/customer.go
  • openmeter/billing/worker/advance/advance.go
  • openmeter/billing/worker/collect/collect.go
  • openmeter/billing/worker/subscriptionsync/service/base_test.go
  • openmeter/billing/worker/subscriptionsync/service/persistedstate/loader.go
  • openmeter/billing/worker/subscriptionsync/service/reconciler/invoiceupdater/invoiceupdate.go
  • openmeter/billing/worker/subscriptionsync/service/sync_credittheninvoice_test.go
  • openmeter/billing/worker/subscriptionsync/service/sync_test.go
  • openmeter/secret/entity/input.go
  • openmeter/secret/entity/secret.go
  • openmeter/secret/entity/secret_test.go
  • openmeter/server/server_test.go
  • test/app/stripe/invoice_credits_test.go
  • test/billing/adapter_test.go
  • test/billing/collection_test.go
  • test/billing/customeroverride_test.go
  • test/billing/invoice_test.go
  • test/billing/lineengine_test.go
  • test/billing/profile_test.go
  • test/billing/subscription_test.go
  • test/credits/credit_then_invoice_test.go
  • test/credits/creditgrant_test.go
  • test/credits/sanity_test.go
  • test/credits/voidgrant_test.go
  • test/subscription/scenario_firstofmonth_test.go

Comment thread openmeter/billing/customeroverride.go Resolved
Comment thread openmeter/billing/invoice.go Resolved
Comment thread openmeter/billing/stdinvoice.go Resolved
Comment thread test/billing/invoice_test.go Resolved
Comment thread test/billing/profile_test.go Resolved

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

🧹 Nitpick comments (1)
openmeter/billing/adapter/gatheringinvoice.go (1)

338-350: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the persistence mapping explicit.

Lines 338-350 map database rows to domain identities inside local callbacks. Use a direct loop here. This keeps the namespace identity mapping visible and follows the repository rule for persistence mapping.

Proposed refactor
-		nilCollectionAtInvoiceIDs := lo.FilterMap(rows, func(row customerIDRow, _ int) (string, bool) {
-			return row.InvoiceID, row.CollectionAt == nil
-		})
+		nilCollectionAtInvoiceIDs := make([]string, 0)
+		customers := make([]customer.CustomerID, 0, len(rows))
+		for _, row := range rows {
+			if row.CollectionAt == nil {
+				nilCollectionAtInvoiceIDs = append(nilCollectionAtInvoiceIDs, row.InvoiceID)
+			}
+
+			customers = append(customers, customer.CustomerID{
+				Namespace: row.Namespace,
+				ID:        row.CustomerID,
+			})
+		}
+
 		if len(nilCollectionAtInvoiceIDs) > 0 {
 			tx.logger.WarnContext(ctx, "gathering invoices have nil next collection at; this may indicate legacy or inconsistent state", "invoice_ids", nilCollectionAtInvoiceIDs)
 		}
 
-		customers := lo.Uniq(lo.Map(rows, func(row customerIDRow, _ int) customer.CustomerID {
-			return customer.CustomerID{
-				Namespace: row.Namespace,
-				ID:        row.CustomerID,
-			}
-		}))
+		customers = lo.Uniq(customers)

As per coding guidelines: “Do not hide type switching, validation, persistence mapping, or meaningful domain translation inside local closures; use named helpers and reserve inline callbacks for obvious, tiny logic.”

🤖 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/billing/adapter/gatheringinvoice.go` around lines 338 - 350,
Replace the lo.FilterMap and lo.Map callbacks in the customer identity mapping
section with an explicit loop over rows, preserving the nil CollectionAt warning
and constructing each customer.CustomerID with row.Namespace and row.CustomerID;
deduplicate the resulting customers as before, without hiding persistence
mapping in local closures.

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.

Nitpick comments:
In `@openmeter/billing/adapter/gatheringinvoice.go`:
- Around line 338-350: Replace the lo.FilterMap and lo.Map callbacks in the
customer identity mapping section with an explicit loop over rows, preserving
the nil CollectionAt warning and constructing each customer.CustomerID with
row.Namespace and row.CustomerID; deduplicate the resulting customers as before,
without hiding persistence mapping in local closures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e381268-ac17-4e7e-abb2-843deba3c85d

📥 Commits

Reviewing files that changed from the base of the PR and between bac38dc and 98eb29e.

📒 Files selected for processing (1)
  • openmeter/billing/adapter/gatheringinvoice.go

chrisgacsal
chrisgacsal previously approved these changes Aug 11, 2026
@turip turip changed the title Feat/strengthen namespace isolation feat: strengthen namespace validate Aug 11, 2026
@turip
turip merged commit 6b41297 into main Aug 11, 2026
27 checks passed
@turip
turip deleted the feat/strengthen-namespace-isolation branch August 11, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants