Skip to content

fix(billing): make profile reads transaction-aware - #5433

Merged
turip merged 1 commit into
openmeterio:mainfrom
eudaimos:fix/billing-profile-adapter-transaction
Nov 4, 2026
Merged

turip merged 1 commit into
openmeterio:mainfrom
eudaimos:fix/billing-profile-adapter-transaction

Conversation

@eudaimos

@eudaimos eudaimos commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

GetProfile, GetDefaultProfile and ListProfiles in openmeter/billing/adapter/profile.go queried through the base ent client instead of entutils.TransactingRepo. Inside a transaction (for example GetCustomerOverride -> resolveProfileWorkflow) they took a second pool connection. When in-flight requests reach the pool size, each request holds one connection and waits for another, and the pool deadlocks. This is the failure #5255 diagnosed in the stress test and left as separate work.

  • Wrap the three reads in entutils.TransactingRepo, matching the other profile methods.
  • Add TestProfileReadsReuseTransactionConnection: with the pool limited to one connection, the three reads inside a transaction complete. It fails with context deadline exceeded without the change.
  • go build ./..., ./openmeter/billing/... and ./test/billing/ pass against Postgres.

Refs #5255

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when retrieving a profile, the default profile, or a list of profiles within a transaction, including when database connections are limited.
    • Existing profile filtering, ordering, pagination, not-found handling, and results remain unchanged.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge.

Summary

Makes GetProfile, GetDefaultProfile, and ListProfiles reuse the caller’s transaction connection.

  • Billing profile reads reuse the caller's transaction connection.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Profile read] --> B{Transaction in context?}
    B -->|Yes| C[Use existing transaction connection]
    B -->|No| D[Use original database client]
    C --> E[Read profile and workflow data]
    D --> E
    E --> F[Return billing values]
Loading

Reviews (1) · Last reviewed commit: "fix(billing): make profile reads transac..." · Reviewed by Greptile

GetProfile, GetDefaultProfile and ListProfiles queried through the base ent client, so inside a transaction (e.g. GetCustomerOverride) they took a second pool connection. With in-flight requests >= pool size every request held one connection and waited on another. Use entutils.TransactingRepo like the other profile methods.

Signed-off-by: Jeff Hoffer <[email protected]>
@eudaimos
eudaimos requested a review from a team as a code owner November 3, 2026 23:45
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

GetProfile, ListProfiles, and GetDefaultProfile now run their queries and profile mapping through a transaction-scoped adapter. A new test exercises these reads inside a transaction with one database connection.

Changes: Billing profile reads

Layer / File(s) Summary
Transaction-scoped profile reads
openmeter/billing/adapter/profile.go, test/billing/profile_test.go
The three profile read methods run queries and map results through the transaction-scoped adapter. Existing filters, pagination, ordering, and error handling remain. The new test checks the reads inside a transaction with a single database connection.

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

Change: Bug fix

Possibly related PRs

Suggested labels: kind/bug, release-note/bug-fix, area/billing

Suggested reviewers: borosr, turip

Merge Risk: Minimal · up to 06065

The profile-read change is ready to merge after normal checks; no unresolved issue is established.

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: making billing profile reads transaction-aware.
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 unit tests (beta)
  • 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
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 84b7fa8 and 0606595.

Files selected for processing: 2
  • openmeter/billing/adapter/profile.go
  • test/billing/profile_test.go

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

@turip turip added the release-note/bug-fix Release note: Bug Fixes label Nov 4, 2026
@turip

turip commented Nov 4, 2026

Copy link
Copy Markdown
Member

Thank you!

@turip
turip merged commit 386d33f into openmeterio:main Nov 4, 2026
32 of 33 checks passed
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