Skip to content

fix(billing): preserve fetch_subscription flag through Redis queue serialization#3225

Open
firecrawl-spring[bot] wants to merge 2 commits intomainfrom
fix/browser-webhook-billing-race
Open

fix(billing): preserve fetch_subscription flag through Redis queue serialization#3225
firecrawl-spring[bot] wants to merge 2 commits intomainfrom
fix/browser-webhook-billing-race

Conversation

@firecrawl-spring
Copy link
Copy Markdown
Contributor

@firecrawl-spring firecrawl-spring Bot commented Mar 25, 2026

Summary

  • Fixes a race condition where browser sessions destroyed via webhook are never billed against the team's subscription
  • The webhook path passes subscription_id: undefined (meaning "look it up"), but queueBillingOperation coerces it to null before serializing to Redis. When supaBillTeam deserializes, null === undefined is false, so fetch_subscription is set to false. The RPC gets sub_id=null with fetch_subscription=false — credits are logged in credit_usage but never deducted from the subscription balance
  • Adds an explicit fetch_subscription boolean to BillingOperation and GroupedBillingOperation, captured before the undefined→null coercion, propagated through grouping, and passed into supaBillTeam

Test plan

  • Verify existing browser sessions destroyed via user DELETE still bill correctly (subscription_id present, fetch_subscription=false)
  • Verify browser sessions destroyed via webhook now bill correctly (subscription_id=null, fetch_subscription=true → RPC looks up subscription)
  • Confirm credit_usage rows from webhook destruction now have a non-null subscription_id
  • Check dashboard reflects accurate credit usage for teams using browser sessions

Open with Devin

Summary by cubic

Fixes a billing gap where webhook-destroyed browser sessions were logged but not charged by preserving the intent to fetch a subscription through Redis queuing and batching. Ensures bill_team_6 receives the correct fetch_subscription signal so credits are deducted.

  • Bug Fixes
    • Added an explicit fetch_subscription boolean to BillingOperation and GroupedBillingOperation, captured before the undefined→null coercion, propagated during grouping (group flag becomes true if any op needs lookup), and passed into supaBillTeam.
    • Updated supaBillTeam to respect the preserved fetch_subscription flag even when subscription_id is null, and pass it through to the RPC without an implicit fallback that could override the flag.

Written for commit b4db2ac. Summary will update on new commits.

…rialization

Browser sessions destroyed via webhook pass subscription_id as undefined,
signaling that bill_team_6 should look up the subscription. However,
queueBillingOperation coerces undefined to null before serializing to
Redis. When supaBillTeam deserializes the operation, it checks
subscription_id === undefined (which is now false, since it's null),
so fetch_subscription is set to false. The RPC receives sub_id=null
with fetch_subscription=false — it has no subscription to bill and
isn't told to look one up. Credits are logged in credit_usage with
a null subscription_id but never deducted from the subscription balance.

Fix: capture the fetch_subscription intent as an explicit boolean before
the undefined→null coercion, propagate it through the grouped operation,
and pass it into supaBillTeam. Also add a defensive fallback in
supaBillTeam: if subscription_id is null and fetch_subscription wasn't
explicitly set, default to fetching.

Co-Authored-By: devhims <himanshu@sideguide.dev>
@firecrawl-spring firecrawl-spring Bot requested a review from devhims March 25, 2026 12:12
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

@nickscamara nickscamara self-requested a review March 27, 2026 16:50
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.

2 participants