Skip to content

fix(billing): release the reporting prefix lease once its prefix is stored - #9108

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/reporting-prefix-lease-release
Oct 16, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/reporting-prefix-lease-release

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The reporting-usage prefix refresh lease was never released after a successful refresh, so when an epoch bump discarded the stored prefix inside the lease window, every reader on every process summed the whole reporting window until the lease expired
  • The lease now holds a per-acquisition token and is released through the existing compare-and-delete releaseLock once the new prefix is stored, so the next read refreshes the prefix once
  • A failed prefix sum or write keeps the lease until expiry as before, as a backoff; a lease that expired and was taken by another process is never deleted by the old holder

Type of Change

  • Bug fix

Testing

  • New integration case in reporting-usage-cache.integration.ts (real Postgres/Redis): after a top-up discards the prefix, two reads sum the window twice in total instead of three times; it fails on the current code, where the lease is never released
  • Ran biome on both files; lint, check:audits, type-check and the integration suite run in CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 16, 2026 4:46am UTC

Request Review

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge.

Summary

Releases the reporting prefix lease after Redis stores the refreshed prefix.

  • A refreshed reporting prefix frees its lease for the next read.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Prefix needs refresh] --> B{Lease acquired?}
  B -->|No| C[Use stored prefix or sum whole window]
  B -->|Yes| D[Sum new prefix]
  D -->|Success| E[Store prefix in Redis]
  E -->|Success| F[Release lease only if token matches]
  D -->|Failure| G[Lease expires naturally]
  E -->|Failure| G
Loading

Reviews (1) · Last reviewed commit: "fix(billing): release the reporting pref..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit e25a6cf into staging Oct 16, 2026
53 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/reporting-prefix-lease-release branch October 16, 2026 07:53

This branch was previously deployed

1 inactive deployment
Preview — efc48263 Deployed Oct 16, 2026 by vercel[bot]
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.

1 participant