Skip to content

feat: add db support for flatfee/usagebased charge intent overrides - #4556

Merged
turip merged 6 commits into
mainfrom
feat/flat-fee-api-updates
Jun 25, 2026
Merged

turip merged 6 commits into
mainfrom
feat/flat-fee-api-updates

Conversation

@turip

@turip turip commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds type-owned charge intent overrides for flat-fee and usage-based charges.

Charge intents are the durable instructions used to produce charge state and invoice lines. Overrides are API-owned replacement intents for the same charge, so API edits can remain effective while subscription sync continues reconciling the base intent.

Overrides are full snapshots, not sparse patches. If no override row exists, the base intent is effective. If an override row exists, the override intent is effective.

Rules

  • Override presence is represented by a dedicated override row existing.
  • Flat-fee and usage-based charges each own their override domain object and table.
  • Credit-purchase charges do not participate in this override model.
  • Creating an override creates the type-specific override row.
  • Updating an override requires the override row to already exist.
  • Deleting an override removes the override row and returns the charge to base-intent behavior.
  • Override rows persist their own invoice_at; invoice-state calculations still use the base/original intent timing in this PR.

Deletion Rules

Flat-fee and usage-based charges track deletion intent separately for the base intent and override intent:

  • Intent.IntentDeletedAt marks the base/original intent as deleted.
  • IntentOverride.IntentDeletedAt marks the override intent as deleted.
  • If no override row exists, adapters derive the charge's effective DeletedAt from Intent.IntentDeletedAt.
  • If an override row exists, adapters derive the charge's effective DeletedAt from IntentOverride.IntentDeletedAt.

This allows subscription/system state to delete the base intent while an API override remains effective, and allows API override deletion without mutating the base intent.

Summary by CodeRabbit

  • New Features
    • Added charge intent override support for flat-fee and usage-based charges (create/delete), with correct effective deletion timestamp behavior.
    • Charge lists/search now include the effective base intent-deleted timestamp for supported charge types.
  • Bug Fixes
    • Charge update/delete logic now resolves and persists DeletedAt and intent-deleted timestamps consistently (UTC-normalized), including when overrides exist.
    • Reads handle override associations correctly and ignore stale override fields; credit-purchase remains excluded from override semantics.
    • Credit-then-invoice extend/shrink now reconciles invoicing state more reliably.
  • Documentation
    • Added “intent deletion rules” documentation for effective intent-deleted timestamp resolution.
  • Tests
    • Added end-to-end coverage for the full intent-override lifecycle and key edge cases for both flat-fee and usage-based charges.

@coderabbitai

coderabbitai Bot commented Jun 23, 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

This PR adds explicit intent-override storage and adapter handling for flat-fee and usage-based charges, updates effective deletion timestamp resolution, refreshes the search view and Ent schemas, and adds integration coverage for override create/update/delete flows.

Changes

Charge Intent Override Feature

Layer / File(s) Summary
Docs and generator guidance
.agents/skills/charges/SKILL.md, .agents/skills/ent/SKILL.md
Adds intent deletion rules and expands Ent upsert/regeneration guidance in the skill docs.
Schema and search contracts
tools/migrate/migrations/20260624043300_charge_intent_override_ddl.up.sql, tools/migrate/migrations/20260624043300_charge_intent_override_ddl.down.sql, tools/migrate/views.sql, openmeter/ent/schema/chargesflatfee.go, openmeter/ent/schema/chargesusagebased.go, openmeter/ent/schema/charges.go, openmeter/billing/charges/models/intentoverride/mixin.go, openmeter/billing/charges/models/intentoverride/flatfee.go, openmeter/billing/charges/models/intentoverride/usagebased.go, openmeter/ent/schema/taxcode.go
Adds override Ent schemas and parent edges, adds base intent deletion timestamps, updates the override mixin schema, and extends the search view and tax-code wiring for override records.
Charge models and validation
openmeter/billing/charges/flatfee/charge.go, openmeter/billing/charges/usagebased/charge.go, pkg/timeutil/closedperiod.go
Adds intent override fields and effective deletion helpers to both charge models and adds required closed-period validation for override periods.
Adapter contracts and shared timestamp handling
openmeter/billing/charges/flatfee/adapter.go, openmeter/billing/charges/usagebased/adapter.go, openmeter/billing/charges/models/chargemeta/mixin.go, openmeter/billing/charges/flatfee/service/creditheninvoice.go, openmeter/billing/charges/flatfee/adapter/mapper.go, openmeter/billing/charges/usagebased/adapter/mapper.go, openmeter/billing/charges/flatfee/adapter/charge.go, openmeter/billing/charges/usagebased/adapter/charge.go
Adds override create/delete adapter methods, removes generic deleted-at mutation from chargemeta updaters, and updates shared mapping and update/delete paths to load and persist UTC-normalized intent deletion timestamps.
Flat-fee adapter and override persistence
openmeter/billing/charges/flatfee/adapter/intentoverride.go
Implements flat-fee intent override mapping plus transactional create, update, and delete operations backed by the new override table.
Usage-based adapter and override persistence
openmeter/billing/charges/usagebased/adapter/intentoverride.go
Implements usage-based intent override mapping plus transactional create, update, and delete operations backed by the new override table.
Flat-fee and usage-based integration coverage
openmeter/billing/charges/flatfee/adapter/intentoverride_test.go, openmeter/billing/charges/usagebased/adapter/intentoverride_test.go
Adds Postgres-backed integration suites that cover override create, update, delete, stale-column handling, and charge-deletion timestamp behavior for both charge types.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ChargeAdapter
  participant EntDB
  participant Postgres

  Caller->>ChargeAdapter: CreateChargeOverride(ctx, charge)
  ChargeAdapter->>ChargeAdapter: validate charge and IntentOverride
  ChargeAdapter->>EntDB: createIntentOverride(...)
  EntDB->>Postgres: INSERT override row
  ChargeAdapter->>EntDB: update charge DeletedAt from GetIntentDeletedAt()
  EntDB->>Postgres: UPDATE charge row
  ChargeAdapter-->>Caller: ChargeBase with IntentOverride

  Caller->>ChargeAdapter: DeleteChargeOverride(ctx, charge)
  ChargeAdapter->>EntDB: delete override row
  EntDB->>Postgres: DELETE override row
  ChargeAdapter->>EntDB: persist effective DeletedAt
  EntDB->>Postgres: UPDATE charge row
  ChargeAdapter-->>Caller: ChargeBase with DeletedAt
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • openmeterio/openmeter#4333: Main PR’s changes to openmeter/billing/charges/usagebased/service/creditheninvoice.go overlap with this PR’s same state-machine flow.
  • openmeterio/openmeter#4351: Both PRs touch the flat-fee credit-then-invoice path in openmeter/billing/charges/flatfee/service/creditheninvoice.go.
  • openmeterio/openmeter#4542: Both PRs work on the flat-fee and usage-based intent-override model, adapter, and mapper surfaces.

Suggested reviewers

  • tothandras
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: database support for flat-fee and usage-based charge intent overrides.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/flat-fee-api-updates

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 force-pushed the feat/invoice-line-engine-api-edits branch from e09d4a5 to 1aa2076 Compare June 23, 2026 10:24
Base automatically changed from feat/invoice-line-engine-api-edits to main June 23, 2026 10:34
@turip
turip force-pushed the feat/flat-fee-api-updates branch 7 times, most recently from 9c50c77 to 98290d6 Compare June 24, 2026 11:55
@turip
turip changed the base branch from main to feat/remove-legacy-charge-overrides June 24, 2026 11:56
@turip
turip force-pushed the feat/remove-legacy-charge-overrides branch from 5de2f2c to 156e06f Compare June 24, 2026 12:04
@turip
turip force-pushed the feat/flat-fee-api-updates branch from 98290d6 to c73becd Compare June 24, 2026 12:08
Base automatically changed from feat/remove-legacy-charge-overrides to main June 24, 2026 12:14
@turip
turip force-pushed the feat/flat-fee-api-updates branch from c73becd to 557ccda Compare June 24, 2026 12:17
@turip turip added release-note/feature Release note: Exciting New Features area/billing labels Jun 24, 2026
@turip turip changed the title feat: simplify charge intent overrides feat: add db support for flatfee/usagebased charge intent overrides Jun 24, 2026
@turip
turip marked this pull request as ready for review June 24, 2026 12:26
@turip
turip requested a review from a team as a code owner June 24, 2026 12:26
@greptile-apps

greptile-apps Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces dedicated charge_flat_fee_overrides and charge_usage_based_overrides tables to replace the old inline override columns on base charge tables, completing a clean model where override presence is determined by a dedicated row rather than a nullable column flag. Both adapter packages gain CreateChargeOverride and DeleteChargeOverride operations alongside updates to UpdateCharge and DeleteCharge to correctly route the effective deleted_at and intent_deleted_at columns through the base-intent vs override-intent split.

  • New dedicated override tables with cascade-on-base-charge-delete FK and correct nullable tax_code_id FK (ON DELETE SET NULL); the migration drops the stale override_kind column and adds intent_deleted_at + deprecated sentinel columns on both base charge tables.
  • GetIntentDeletedAt() helper centralises effective-deletion resolution on both ChargeBase types; DeleteCharge and UpdateCharge in both adapters now correctly write intent_deleted_at (base) and deleted_at (effective) with full override awareness.
  • creditheninvoice.go renames generateInvoicePatches → reconcileInvoicingState (no logic change); end-to-end tests for create/update/delete override lifecycle are added for both charge types.

Confidence Score: 5/5

The change is safe to merge; the override model is correctly wired end-to-end with no data-corrupting paths found.

All previously flagged issues (affected-row guard in DeleteChargeOverride, nil-pointer dereferences on Price/Discounts, ambiguous error messages) have been addressed. The intent-deletion routing through GetIntentDeletedAt() is consistent across CreateChargeOverride, UpdateCharge, and DeleteCharge in both adapters. The migration correctly drops the stale override_kind column and adds the new intent_deleted_at column; the down migration is symmetric. No new logic regressions were found in the creditheninvoice.go rename, and the test coverage spans the full create/update/delete lifecycle for both charge types.

No files require special attention.

Important Files Changed

Filename Overview
openmeter/billing/charges/flatfee/adapter/intentoverride.go Implements CreateChargeOverride, DeleteChargeOverride, createIntentOverride, and updateIntentOverride for flat-fee charges; affected-row guard added to DeleteChargeOverride and UpdateIntentOverride, nil pointer risks addressed with lo.FromPtr.
openmeter/billing/charges/usagebased/adapter/intentoverride.go Parallel implementation for usage-based charges; Price and Discounts mapped with lo.FromPtr; logic is symmetric with flatfee adapter.
openmeter/billing/charges/flatfee/adapter/charge.go UpdateCharge and DeleteCharge updated to correctly route intent_deleted_at (base intent) and deleted_at (effective) through the override split; updateIntentOverride called when charge.IntentOverride is non-nil.
openmeter/billing/charges/usagebased/adapter/charge.go Same override-aware update/delete pattern as flatfee; GetIntentDeletedAt correctly returns override.IntentDeletedAt when override is present.
tools/migrate/migrations/20260624043300_charge_intent_override_ddl.up.sql Creates charge_flat_fee_overrides and charge_usage_based_overrides tables with correct CASCADE/SET NULL FKs; drops override_kind and adds intent_deleted_at on base tables; recreates charges_search_v1s view with base_intent_deleted_at column.
openmeter/ent/schema/chargesflatfee.go Adds intent_deleted_at field to ChargeFlatFee and defines the new ChargeFlatFeeOverride schema with full field set and charge/tax_code edges; override edge on ChargeFlatFee is correctly set to cascade-delete.
openmeter/ent/schema/chargesusagebased.go Mirrors chargesflatfee.go pattern; adds intent_deleted_at to ChargeUsageBased and defines ChargeUsageBasedOverride schema with price/discounts fields.
openmeter/billing/charges/flatfee/charge.go Adds IntentOverride field to ChargeBase, IntentDeletedAt to Intent, new IntentOverride type with Validate/Normalized, and GetIntentDeletedAt() helper that routes through the override when present.
openmeter/billing/charges/flatfee/service/creditheninvoice.go Pure rename of generateInvoicePatches → reconcileInvoicingState and generateInvoicePatchesInput → reconcileInvoicingStateInput; no logic changes.
openmeter/billing/charges/models/intentoverride/mixin.go All inline override fields (override_present, override_name, etc.) marked as deprecated with a message pointing to dedicated override tables; override_intent_deleted_at field added as deprecated.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Caller
    participant Adapter
    participant DB_Base as charge_flat_fees / charge_usage_based
    participant DB_Override as charge_*_overrides

    Note over Caller,DB_Override: CreateChargeOverride
    Caller->>Adapter: CreateChargeOverride(charge w/ IntentOverride)
    Adapter->>DB_Override: INSERT override row (charge_id, intent_deleted_at, ...)
    Adapter->>DB_Base: "UPDATE deleted_at = override.IntentDeletedAt"
    Adapter-->>Caller: "ChargeBase{IntentOverride: &override, DeletedAt: ...}"

    Note over Caller,DB_Override: UpdateCharge (with override)
    Caller->>Adapter: "UpdateCharge(charge{IntentOverride != nil})"
    Adapter->>DB_Base: "UPDATE intent_deleted_at, deleted_at=GetIntentDeletedAt()"
    Adapter->>DB_Override: UPDATE override row fields incl. intent_deleted_at
    Adapter-->>Caller: ChargeBase (with updated override edge)

    Note over Caller,DB_Override: DeleteChargeOverride
    Caller->>Adapter: DeleteChargeOverride(charge)
    Adapter->>DB_Override: "DELETE WHERE charge_id = ?"
    Adapter->>DB_Base: "UPDATE deleted_at = base.Intent.IntentDeletedAt"
    Adapter-->>Caller: "ChargeBase{IntentOverride: nil}"

    Note over Caller,DB_Override: DeleteCharge (with override)
    Caller->>Adapter: "DeleteCharge(charge{IntentOverride != nil})"
    Adapter->>DB_Base: "UPDATE intent_deleted_at(base unchanged), deleted_at=now()"
    Adapter->>DB_Override: "UPDATE intent_deleted_at = now()"
    Adapter-->>Caller: (void)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Caller
    participant Adapter
    participant DB_Base as charge_flat_fees / charge_usage_based
    participant DB_Override as charge_*_overrides

    Note over Caller,DB_Override: CreateChargeOverride
    Caller->>Adapter: CreateChargeOverride(charge w/ IntentOverride)
    Adapter->>DB_Override: INSERT override row (charge_id, intent_deleted_at, ...)
    Adapter->>DB_Base: "UPDATE deleted_at = override.IntentDeletedAt"
    Adapter-->>Caller: "ChargeBase{IntentOverride: &override, DeletedAt: ...}"

    Note over Caller,DB_Override: UpdateCharge (with override)
    Caller->>Adapter: "UpdateCharge(charge{IntentOverride != nil})"
    Adapter->>DB_Base: "UPDATE intent_deleted_at, deleted_at=GetIntentDeletedAt()"
    Adapter->>DB_Override: UPDATE override row fields incl. intent_deleted_at
    Adapter-->>Caller: ChargeBase (with updated override edge)

    Note over Caller,DB_Override: DeleteChargeOverride
    Caller->>Adapter: DeleteChargeOverride(charge)
    Adapter->>DB_Override: "DELETE WHERE charge_id = ?"
    Adapter->>DB_Base: "UPDATE deleted_at = base.Intent.IntentDeletedAt"
    Adapter-->>Caller: "ChargeBase{IntentOverride: nil}"

    Note over Caller,DB_Override: DeleteCharge (with override)
    Caller->>Adapter: "DeleteCharge(charge{IntentOverride != nil})"
    Adapter->>DB_Base: "UPDATE intent_deleted_at(base unchanged), deleted_at=now()"
    Adapter->>DB_Override: "UPDATE intent_deleted_at = now()"
    Adapter-->>Caller: (void)
Loading

Reviews (4): Last reviewed commit: "fix(charges): keep invoice timing on bas..." | Re-trigger Greptile

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

🧹 Nitpick comments (2)
openmeter/billing/charges/usagebased/adapter/intentoverride_test.go (1)

290-291: 📐 Maintainability & Code Quality | 🔵 Trivial

Tiny nit: these s.True(...Equal(...)) checks are a bit opaque on failure. If you want richer diffs here, s.Equal(...) would be easier to read.

🤖 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/charges/usagebased/adapter/intentoverride_test.go` around
lines 290 - 291, The test assertions in the intent override check are using
opaque boolean equality calls, which make failures harder to read. Update the
assertions in the test that validates override pricing/discounts to use the test
suite’s direct equality helper instead of wrapping Equal inside s.True, so
failures show richer diffs while keeping the same verification for Price and
Discounts.
openmeter/billing/charges/flatfee/charge.go (1)

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

Document the override-vs-base precedence here.

A short docstring would make this a lot easier to read at call sites, since the method quietly prefers the override intent timestamp over the base intent timestamp. As per coding guidelines, "Add a docstring to Go domain helpers when the name compresses important business semantics that are easy to misread at call sites"; this helper now carries the new effective-deletion contract from the override feature.

🤖 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/charges/flatfee/charge.go` around lines 75 - 81, Add a
short docstring to ChargeBase.GetIntentDeletedAt explaining the effective
deletion timestamp contract: it returns IntentOverride.IntentDeletedAt when
IntentOverride is present, otherwise it falls back to Intent.IntentDeletedAt.
This helper in ChargeBase should explicitly document the override-vs-base
precedence so call sites understand the business semantics without reading the
implementation.

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 @.agents/skills/ent/SKILL.md:
- Line 43: The regeneration section has two small grammar issues that should be
corrected for readability. Update the wording in the sentence with generators
needs and the later sentence with something have changed so both read naturally,
while keeping the rest of the instructions in SKILL.md unchanged.
- Around line 43-49: The regeneration guidance in SKILL.md should be updated to
match the repo’s preferred workflow: make `make generate` the primary command
after Ent schema changes instead of presenting `go generate ./openmeter/ent/...`
as the usual path. Adjust the instructions around the Ent schema regeneration
section so they direct users to edit files under `openmeter/ent/schema/` and run
`make generate`, keeping `go generate` only if you need to mention a lower-level
fallback or removing it entirely if not needed.

In `@openmeter/billing/charges/flatfee/adapter/intentoverride.go`:
- Around line 111-211: The shared Ent helper methods createIntentOverride and
updateIntentOverride should be transaction-aware like the rest of the adapter
layer. Wrap the Ent access in these helpers with entutils.TransactingRepo(...)
so they reuse an existing transaction from ctx instead of opening direct DB
operations. Keep the change localized to the adapter methods in
intentoverride.go and ensure the create/save/query flow still uses the same
symbols (createIntentOverride, updateIntentOverride, a.db.ChargeFlatFeeOverride,
and mapIntentOverrideFromDB) under the repo transaction wrapper.
- Around line 97-105: The DeletedAt value returned from intentoverride.go is not
the same UTC-normalized timestamp that gets persisted. In ChargeBase update
flow, use the same converted value produced by
convert.TimePtrIn(charge.Intent.IntentDeletedAt, time.UTC) when assigning
charge.DeletedAt, so the returned response matches the database representation
even if the input timestamp was non-UTC.

In `@openmeter/billing/charges/usagebased/adapter/intentoverride.go`:
- Around line 109-199: The shared Ent helper methods createIntentOverride and
updateIntentOverride are doing direct DB writes/queries without being
transaction-aware. Wrap the Ent access in entutils.TransactingRepo(...) so these
helpers participate in the existing transaction from ctx and can be safely
reused without bypassing the adapter transaction pattern. Keep the transaction
boundary inside these helper functions rather than only at their callers, and
ensure both the create/save path and the update/query path use the
transaction-aware repo.
- Around line 95-103: The delete-override flow in intentoverride.go is
persisting a UTC-normalized timestamp via UpdateOneID/SetOrClearDeletedAt, but
ChargeBase is still returned with the original IntentDeletedAt pointer. Update
the assignment after the save so the returned charge.DeletedAt uses the same
UTC-normalized value produced by convert.TimePtrIn (or the saved value), keeping
the immediate response consistent with a later DB read.

In `@openmeter/ent/schema/chargesflatfee.go`:
- Around line 193-198: Mirror the TaxCode foreign key on the flat-fee override
schema by updating the tax_code_id field in chargesflatfee.go and the related
override definition to use the same referential constraint as the base flat-fee
charge TaxCode relationship. Keep the field optional/nillable as-is, but add the
FK/edge wiring so overrides cannot reference a missing tax code, matching the
existing TaxCode intent validation on the main charge model.

In `@openmeter/ent/schema/chargesusagebased.go`:
- Around line 195-200: The usage-based override schema currently exposes
tax_code_id as a plain field without the TaxCode relationship, so it can point
to a missing record. Update the override schema in the charges usage-based
definition to add the same tax code FK/edge used by the base usage-based charge
schema, and apply the same fix to the other override block referenced by the
comment so both override paths enforce the TaxCode relationship consistently.

In `@tools/migrate/migrations/20260624043300_charge_intent_override_ddl.up.sql`:
- Around line 2-4: Add a guard or backfill around the ALTER TABLE changes in
20260624043300_charge_intent_override_ddl.up.sql before dropping override_kind.
In the migration for charge_flat_fees and charge_usage_based, either
preflight-check for any rows where override_kind is not NULL and fail fast, or
populate the new override tables/columns first via the relevant migration path
before removing the old marker. Make sure the change is tied to the
charge_flat_fees and charge_usage_based DDL so existing override data is not
silently lost.

---

Nitpick comments:
In `@openmeter/billing/charges/flatfee/charge.go`:
- Around line 75-81: Add a short docstring to ChargeBase.GetIntentDeletedAt
explaining the effective deletion timestamp contract: it returns
IntentOverride.IntentDeletedAt when IntentOverride is present, otherwise it
falls back to Intent.IntentDeletedAt. This helper in ChargeBase should
explicitly document the override-vs-base precedence so call sites understand the
business semantics without reading the implementation.

In `@openmeter/billing/charges/usagebased/adapter/intentoverride_test.go`:
- Around line 290-291: The test assertions in the intent override check are
using opaque boolean equality calls, which make failures harder to read. Update
the assertions in the test that validates override pricing/discounts to use the
test suite’s direct equality helper instead of wrapping Equal inside s.True, so
failures show richer diffs while keeping the same verification for Price and
Discounts.
🪄 Autofix (Beta)

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

Run ID: d3165e81-f068-417c-86d2-93f9231ded6f

📥 Commits

Reviewing files that changed from the base of the PR and between e134c32 and 557ccda.

⛔ Files ignored due to path filters (42)
  • openmeter/ent/db/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/chargeflatfee.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfee_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeeoverride.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeeoverride/chargeflatfeeoverride.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeeoverride/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeeoverride_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeeoverride_delete.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeeoverride_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeflatfeeoverride_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/chargessearchv1.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargessearchv1/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/chargeusagebased.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebased_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedoverride.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedoverride/chargeusagebasedoverride.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedoverride/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedoverride_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedoverride_delete.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedoverride_query.go is excluded by !**/ent/db/**
  • openmeter/ent/db/chargeusagebasedoverride_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/client.go is excluded by !**/ent/db/**
  • openmeter/ent/db/ent.go is excluded by !**/ent/db/**
  • openmeter/ent/db/entmixinaccessor.go is excluded by !**/ent/db/**
  • openmeter/ent/db/expose.go is excluded by !**/ent/db/**
  • openmeter/ent/db/hook/hook.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/paginate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/predicate/predicate.go is excluded by !**/ent/db/**
  • openmeter/ent/db/runtime.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • openmeter/ent/db/tx.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (26)
  • .agents/skills/charges/SKILL.md
  • .agents/skills/ent/SKILL.md
  • openmeter/billing/charges/flatfee/adapter.go
  • openmeter/billing/charges/flatfee/adapter/charge.go
  • openmeter/billing/charges/flatfee/adapter/intentoverride.go
  • openmeter/billing/charges/flatfee/adapter/intentoverride_test.go
  • openmeter/billing/charges/flatfee/adapter/mapper.go
  • openmeter/billing/charges/flatfee/charge.go
  • openmeter/billing/charges/flatfee/service/creditheninvoice.go
  • openmeter/billing/charges/models/chargemeta/mixin.go
  • openmeter/billing/charges/models/intentoverride/flatfee.go
  • openmeter/billing/charges/models/intentoverride/mixin.go
  • openmeter/billing/charges/models/intentoverride/usagebased.go
  • openmeter/billing/charges/usagebased/adapter.go
  • openmeter/billing/charges/usagebased/adapter/charge.go
  • openmeter/billing/charges/usagebased/adapter/intentoverride.go
  • openmeter/billing/charges/usagebased/adapter/intentoverride_test.go
  • openmeter/billing/charges/usagebased/adapter/mapper.go
  • openmeter/billing/charges/usagebased/charge.go
  • openmeter/ent/schema/charges.go
  • openmeter/ent/schema/chargesflatfee.go
  • openmeter/ent/schema/chargesusagebased.go
  • pkg/timeutil/closedperiod.go
  • tools/migrate/migrations/20260624043300_charge_intent_override_ddl.down.sql
  • tools/migrate/migrations/20260624043300_charge_intent_override_ddl.up.sql
  • tools/migrate/views.sql
💤 Files with no reviewable changes (1)
  • openmeter/billing/charges/models/chargemeta/mixin.go

Comment thread .agents/skills/ent/SKILL.md Resolved
Comment thread .agents/skills/ent/SKILL.md Resolved
Comment thread openmeter/ent/schema/chargesflatfee.go Resolved
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

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

Other then the two question I sent the code looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants