Skip to content

feat: deliver billable usage to Polar idempotently - #1729

Merged
kang-heewon merged 1 commit into
trunkfrom
issue-1522-polar-usage-delivery
Aug 4, 2026
Merged

feat: deliver billable usage to Polar idempotently#1729
kang-heewon merged 1 commit into
trunkfrom
issue-1522-polar-usage-delivery

Conversation

@kang-heewon

Copy link
Copy Markdown
Member

Outcome

Polar can now deliver durable journaled billable usage through typed meter bindings. Each event carries a replay-safe Polar external ID; inserted and duplicate acknowledgements both resolve the local claim without a second provider increment. Delivery stays outside request handling, claims one bounded event at a time, and retains retryable or terminal failures with stable recovery Problems.

Usage delivery is bounded by a five-second provider attempt timeout, a 15-second provider retry window, and a minimum 30-second journal lease. Missing meter mappings and customers provide replay guidance, and a credential-gated live certification covers a deliberate usage event.

Fixes #1522

Verification

  • pnpm --filter @croco/billing-polar test — 98 passed; 3 credential-gated live tests skipped.
  • pnpm --filter @croco/billing-polar typecheck, lint, and build — passed.
  • pnpm public-api:check, pnpm problem-registry:check, pnpm docs:catalog:check, and pnpm docs:api-triggers:check — passed.
  • Pre-push workspace gates — 234/234 test tasks and 233/233 typecheck tasks passed.

Review notes

  • Live Polar certification is opt-in and requires the documented POLAR_USAGE_* environment variables; it was not run without credentials.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@kang-heewon, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 61698ad5-4ae2-40db-97d9-9f6ffe4bb275

📥 Commits

Reviewing files that changed from the base of the PR and between 7b1505b and 5d3b90b.

⛔ Files ignored due to path filters (2)
  • packages/problems-core/src/generated/problem-code-registry.ts is excluded by !**/generated/**
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (31)
  • .changeset/polar-usage-delivery.md
  • docs/problem-code-registry.json
  • packages/billing-polar/README.md
  • packages/billing-polar/package.json
  • packages/billing-polar/src/index.ts
  • packages/billing-polar/src/libs/PolarBillingProviderProfile.ts
  • packages/billing-polar/src/libs/PolarUsageBillingGateway.ts
  • packages/billing-polar/src/libs/PolarUsageDeliveryWorker.ts
  • packages/billing-polar/src/libs/problems/PolarBillingProblems.ts
  • packages/billing-polar/src/tests/PolarBillingDiagnosticsProvider.spec.ts
  • packages/billing-polar/src/tests/PolarBillingGateway.spec.ts
  • packages/billing-polar/src/tests/PolarBillingProviderProfile.spec.ts
  • packages/billing-polar/src/tests/PolarLiveSmoke.spec.ts
  • packages/billing-polar/src/tests/PolarUsageBillingGateway.spec.ts
  • packages/billing-polar/tsconfig.json
  • packages/billing-polar/vitest.config.ts
  • packages/docs/src/content/docs/api/billing-polar/src/classes/PolarUsageBillingGateway.md
  • packages/docs/src/content/docs/api/billing-polar/src/classes/PolarUsageCustomerNotFoundProblem.md
  • packages/docs/src/content/docs/api/billing-polar/src/classes/PolarUsageDeliveryWorker.md
  • packages/docs/src/content/docs/api/billing-polar/src/classes/PolarUsageMeterMappingProblem.md
  • packages/docs/src/content/docs/api/billing-polar/src/functions/bindPolarUsageMeter.md
  • packages/docs/src/content/docs/api/billing-polar/src/functions/normalizePolarBillingError.md
  • packages/docs/src/content/docs/api/billing-polar/src/type-aliases/PolarUsageDeliveryRunResult.md
  • packages/docs/src/content/docs/api/billing-polar/src/type-aliases/PolarUsageDeliveryWorkerOptions.md
  • packages/docs/src/content/docs/api/billing-polar/src/type-aliases/PolarUsageMeterBinding.md
  • packages/docs/src/content/docs/api/billing-polar/src/variables/POLAR_BILLING_PROVIDER_PROFILE.md
  • packages/docs/src/content/docs/api/problems-core/src/classes/Problem.md
  • packages/docs/src/content/docs/api/problems-core/src/variables/CROCO_PROBLEM_CODE_REGISTRY.md
  • packages/docs/src/content/docs/en/reference/problem-recovery-cookbook.md
  • packages/docs/src/content/docs/en/reference/provider-maturity.md
  • public-api-surface.snapshot.json

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.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

📊 Benchmark Results

✅ All benchmarks passed

Benchmark p75 Threshold Baseline vs Baseline Status Notes
CrocoApp constructor 38.1μs 30.0ms 8.2μs +366.1% -
CrocoApp lambdaHandler (10 controllers) 2.3ms 50.0ms 258.4μs +784.5% -
Lambda cold-start simulation 1.8ms 80.0ms 418.1μs +331.0% -
Lambda cold-start with headers 1.6ms 80.0ms 369.7μs +342.5% -
Lambda cold-start with binary body 1.7ms 80.0ms 339.1μs +394.0% -
Lambda cold-start with query params 1.6ms 80.0ms 301.3μs +434.2% -
Lambda cold-start with authorizer context 1.6ms 80.0ms 299.8μs +435.7% -
Lambda cold-start realistic scenario 1.6ms 80.0ms 299.2μs +430.2% -
EventBusConfig.start (10 handlers) 1.9μs 10.0ms 1.4μs +32.8% -
EventPublisher.publishNow single event 2.1μs 2.0ms 1.7μs +26.2% -
DefaultHandlerResolver.resolve × 10 0.1μs 5.0ms 0.1μs -12.5% -
Container.get singleton (cold) 76.9μs 5.0ms 70.3μs +9.5% -
Container.register × 50 components 3.5ms 10.0ms 3.2ms +9.4% -
Container.validate (50 components) 3.9ms 20.0ms 3.4ms +15.6% -
Container.get singleton (warm) 1.9μs 500.0μs 1.6μs +17.6% -
TelemetryRuntime.init (lambda preset) 2.3μs 200.0ms 1.1ms -99.8% -
lambdaPreset config creation 1.5μs 2.0ms 1.4μs +6.7% -

Updated: 2026-08-02T15:06:02.304Z · Commit: 60156ed

@kang-heewon
kang-heewon force-pushed the issue-1522-polar-usage-delivery branch 4 times, most recently from c4a5e69 to cac05f5 Compare August 2, 2026 01:26
@kang-heewon
kang-heewon force-pushed the issue-1522-polar-usage-delivery branch from cac05f5 to 5d3b90b Compare August 2, 2026 14:56
@kang-heewon
kang-heewon merged commit 31636bb into trunk Aug 4, 2026
12 checks passed
@kang-heewon
kang-heewon deleted the issue-1522-polar-usage-delivery branch August 4, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[billing-polar] Deliver billable usage events idempotently

1 participant