Skip to content

feat: add first-class background billing - #1388

Open
pjb157 wants to merge 1 commit into
mainfrom
peter/background-billing-tier
Open

feat: add first-class background billing#1388
pjb157 wants to merge 1 commit into
mainfrom
peter/background-billing-tier

Conversation

@pjb157

@pjb157 pjb157 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add background as a first-class billing tier across credit transactions, batch aggregates, GenAI metrics, transaction responses, model pricing, and historical backfills
  • resolve pricing as explicit background tariff → 24h batch tariff only; requests remain identified as background throughout, and stay unbilled when neither price exists
  • expose background tariff configuration and effective pricing in the platform model dashboard independently of foreground SLA windows
  • allow authorized connection syncs, including S3, to submit native background batches while preserving model validation and bypassing foreground SLA capacity and unverified-volume admission
  • add an atomic, low-cost constraint migration that avoids scanning the large credits ledger

Why

Background dispatch is a distinct inference class, but billing and connector ingestion still treated it as an ordinary SLA batch in several paths. That could report the wrong tier, select realtime pricing, or reject/fail connector-created background work through foreground admission and completion-window parsing.

Impact

Platform managers can configure a dedicated background tariff per model. Without one, background work charges the model's 24h batch price without changing its accounting identity. Connection sync callers need the BackgroundInferenceUser role to select completion_window: "background"; accepted files become real background batches and do not consume foreground admission capacity.

Historical backfill scripts now classify file-backed and batchless background usage, including purged request rows recovered from analytics, without adding an extra analytics-table scan.

Validation

  • cargo test -p dwctl background_ --lib (31 passed)
  • cargo test -p dwctl test_compute_billing_tier --lib
  • cargo test -p dwctl test_billing_tier_label_maps_each_case --lib
  • just lint rust -- -D warnings
  • just lint ts
  • pnpm build
  • focused dashboard tests (75 passed, including the previously flaky user-management test in isolation)
  • live PostgreSQL migration and backfill SQL syntax checks
  • independent code review with no remaining findings

Copilot AI review requested due to automatic review settings July 29, 2026 18:56
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploying control-layer with  Cloudflare Pages  Cloudflare Pages

Latest commit: cc4ca3a
Status: ✅  Deploy successful!
Preview URL: https://0f676d11.control-layer.pages.dev
Branch Preview URL: https://peter-background-billing-tie.control-layer.pages.dev

View logs

Copilot AI 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.

Pull request overview

This PR makes “background” a first-class billing tier end-to-end (ledger, batch aggregates, pricing/tariffs, connection sync ingestion, metrics, and UI), with explicit pricing resolution rules that keep background requests labeled as background while preventing accidental realtime billing.

Changes:

  • Add background-aware service tier classification/backfills for credits ledger and batch aggregates.
  • Implement background-specific tariff resolution (explicit background tariff → 24h batch tariff only; otherwise unbilled) and expose it in APIs/UI.
  • Allow connection sync to submit native background batches (role-gated) while bypassing foreground SLA capacity + unverified-volume admission but still validating models.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.

Show a summary per file
File Description
scripts/backfill_credits_denorm.sh Extends ledger backfill classification to include background (file-backed + batchless) and updates Phase 2 to recover background/flex from analytics.
scripts/backfill_batch_aggregates_denorm.sh Backfills batch_aggregates.service_tier to include background based on fusillade batch metadata.
dwctl/src/request_logging/batcher.rs Adds background billing tier computation, factors tariff resolution into a helper, and adds integration tests for background pricing/tier behavior.
dwctl/src/metrics/gen_ai.rs Updates GenAI metrics tier labeling tests to include background.
dwctl/src/db/models/tariffs.rs Documents background as a supported batch completion window in tariff models.
dwctl/src/db/models/credits.rs Updates ledger response docs to include background service tier.
dwctl/src/db/handlers/tariffs.rs Implements background pricing fallback semantics (background → 24h only) and adds tests.
dwctl/src/connections/sync.rs Supports activating background batches from connection sync while skipping foreground admission/capacity reservation.
dwctl/src/api/models/transactions.rs Updates API docs to include background service tier in transaction responses.
dwctl/src/api/models/tariffs.rs Updates API docs to include background completion window for batch tariffs.
dwctl/src/api/models/deployments/mod.rs Keeps background tariff visibility independent of foreground SLA windows, with 24h fallback visibility rules.
dwctl/src/api/models/deployments/enrichment.rs Adds tests asserting background tariff and fallback aren’t filtered by foreground completion window config.
dwctl/src/api/models/connections.rs Documents completion_window: background for sync trigger requests (role-gated).
dwctl/src/api/handlers/connections.rs Enforces BackgroundInferenceUser role for background sync triggers and persists the completion window override.
dwctl/migrations/125_add_background_billing_tier.sql Adds background to service tier CHECK constraints using a NOT VALID approach to avoid scanning the large ledger.
dashboard/src/utils/formatters.ts Adds “Background” labeling and deterministic sort order for background tariffs.
dashboard/src/utils/formatters.test.ts Tests background display name and sorting behavior.
dashboard/src/components/features/models/manage/ModelTariffTable.tsx Allows selecting an explicit background tariff window even when foreground SLA windows are constrained.
dashboard/src/components/features/models/manage/ModelTariffTable.test.tsx Verifies background tariff option is available independent of foreground SLAs.
dashboard/src/components/features/models/manage/ModelsContent.tsx Surfaces background pricing independently and shows effective background pricing via 24h fallback when needed.
dashboard/src/api/control-layer/types.ts Extends frontend types to recognize background as a completion window value.

@pjb157
pjb157 force-pushed the peter/background-billing-tier branch from 8b678a7 to cc4ca3a Compare July 29, 2026 19:08
Introduce explicit background tariff resolution and accounting across the ledger, metrics, model pricing UI, and historical backfills. Allow authorized connector syncs to create native background batches while retaining model validation and bypassing foreground admission limits.
@pjb157
pjb157 force-pushed the peter/background-billing-tier branch from cc4ca3a to 3443523 Compare July 29, 2026 19:09
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