Skip to content

feat(billing): expose netRemainingRaw in useMeter — show negative quota for in-flight jobs #4060

Closed

Description

@PierreBrisorgueil

Audit finding (LOW — post-launch)

src/modules/billing/composables/billing.useMeter.js:100:

const totalRemaining = computed(() => Math.max(0, quota.value - used.value) + extras.value);

The Math.max(0, ...) clamp prevents the UI from displaying a negative quota. Memo edge case 1: "Quota négatif autorisé pour jobs en cours, bloque nouveaux. Affichage du négatif en UI".

Currently a user whose attribution has pushed meterUsed > meterQuota (long-running scrap finishing past quota) sees totalRemaining = 0 + extras instead of e.g. -150 + 5000 = 4850 with the negative debt visible.

Proposed fix

Expose both:

const totalRemaining = computed(() => Math.max(0, quota.value - used.value) + extras.value);
const netRemainingRaw = computed(() => quota.value - used.value + extras.value);
const overage = computed(() => Math.max(0, used.value - quota.value));

return {
  // ...existing
  totalRemaining,
  netRemainingRaw,
  overage,
};

UI components decide which to display:

  • MeterProgress: keep clamped (visual progress bar, 0-100%)
  • Drawer / detail views: show overage chip when overage > 0
  • ExtrasLedger: show netRemainingRaw when displaying the bottom-line balance (can be negative when in-flight job runs past quota)

Tests required

  • totalRemaining >= 0 always (regression)
  • netRemainingRaw can be negative when used > quota and extras=0
  • overage is 0 when used <= quota, positive otherwise

Files

  • src/modules/billing/composables/billing.useMeter.js
  • Components consuming totalRemaining — review and decide which need raw vs clamped
  • tests/billing.useMeter.unit.tests.js (add scenarios)

Audit context

Source: codex billing audit. POST-LAUNCH — visual issue, not a billing correctness issue.

Activity

  1. added a commit that references this issue on May 1, 2026
    111e64b
  2. added a commit that references this issue on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    billingPhase 3 — Stripe billing integration

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions