Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

perf(replay-vision): read scanner spend from the receipt ledger (#123449)

Tue Haulund575f9eec24e6
diff --git a/products/replay_vision/backend/api/scanners.py b/products/replay_vision/backend/api/scanners.py
index 8be666cfea7c..e24b18961336 100644
--- a/products/replay_vision/backend/api/scanners.py
+++ b/products/replay_vision/backend/api/scanners.py
@@ -86,11 +86,7 @@ from products.replay_vision.backend.api.trigger import (
check_team_in_flight_capacity,
start_apply_scanner_workflow,
)
-from products.replay_vision.backend.billing import (
- observation_credits_case,
- observation_credits_for_model,
- projected_monthly_credits,
-)
+from products.replay_vision.backend.billing import observation_credits_for_model, projected_monthly_credits
from products.replay_vision.backend.built_in_scans import BUILT_IN_SCANS, BuiltInScanKey
from products.replay_vision.backend.consent import AI_CONSENT_REQUIRED_CODE
from products.replay_vision.backend.impact import (
@@ -145,9 +141,11 @@ from products.replay_vision.backend.quota import (
org_credit_cap,
quota_state,
quota_state_for_cap,
+ scanner_period_receipts,
spend_projection,
)
from products.replay_vision.backend.scanner_access import (
+ accessible_experiment_ids,
accessible_observations,
is_experiment_accessible,
readable_observation_scanner_ids,
@@ -564,12 +562,12 @@ class ReplayScannerSerializer(TaggedItemSerializerMixin, UserAccessControlSerial
)
credits_this_month = serializers.SerializerMethodField(
help_text=(
- "Credits this scanner's succeeded observations consumed in the current billing period "
- "(1 credit = $0.01). Matches the window of the org-wide quota meter."
+ "Credits billed for this scanner's observations created in the current billing period "
+ "(1 credit = $0.01), each at the price frozen when it succeeded. Deleted observations still count."
),
)
observations_this_month = serializers.SerializerMethodField(
- help_text="Succeeded observations this scanner produced in the current billing period.",
+ help_text="Billed observations this scanner created in the current billing period, including deleted ones.",
)
credits_used_against_limit = serializers.SerializerMethodField(
help_text=(
@@ -701,10 +699,15 @@ class ReplayScannerSerializer(TaggedItemSerializerMixin, UserAccessControlSerial
def get_estimated_monthly_credits(self, scanner: ReplayScanner) -> int | None:
return projected_monthly_credits(scanner.model, scanner.estimated_monthly_observations, scanner.credit_limit)
- def _page_scanner_ids(self, scanner: ReplayScanner) -> list[UUID]:
+ def _page_scanners(self) -> list[ReplayScanner] | None:
+ """The list page's scanners, or None when serializing a single scanner."""
root = self.root
instance = root.instance if isinstance(root, serializers.ListSerializer) else None
- return [s.id for s in instance] if instance is not None else [scanner.id]
+ return list(instance) if instance is not None else None
+
+ def _page_scanner_ids(self, scanner: ReplayScanner) -> list[UUID]:
+ page = self._page_scanners()
+ return [s.id for s in page] if page is not None else [scanner.id]
def _scanner_spend(self, scanner: ReplayScanner) -> ScannerSpend:
# The context dict is shared across the list's children, so the page's totals are computed once.
@@ -717,8 +720,8 @@ class ReplayScannerSerializer(TaggedItemSerializerMixin, UserAccessControlSerial
return totals.get(scanner.id, ScannerSpend(0, 0))
def _scanner_budget(self, scanner: ReplayScanner) -> ScannerBudget:
- """The limit-facing figure. Separate from `_scanner_spend` on purpose: that one is the displayed
- spend read from observation rows, this one is the delete-proof ledger draw the cap is enforced on."""
+ """The limit-facing figure. Separate from `_scanner_spend` on purpose: that one counts settled
+ receipts only, this one also reserves in-flight observations, as the cap enforcement does."""
budgets = self.context.get("_scanner_budgets")
if budgets is None:
budgets = compute_scanner_budgets(
@@ -1026,8 +1029,30 @@ class ReplayScannerSerializer(TaggedItemSerializerMixin, UserAccessControlSerial
get_team = self.context.get("get_team")
if get_team is None: # no request context (e.g. internal serialization); don't over-redact
return True
+ page_access = self._page_experiment_access(get_team().id)
+ if experiment_id in page_access:
+ return page_access[experiment_id]
return is_experiment_accessible(self.user_access_control, get_team().id, experiment_id)
+ def _page_experiment_access(self, team_id: int) -> dict[int, bool]:
+ """Whether the caller may view each experiment the list page targets, checked in one query.
+
+ Shared through the context like `_scanner_spend`, so a page of experiment scanners costs one
+ access check instead of one per row. Outside a list it is empty and callers check one id.
+ """
+ cached = self.context.get("_page_experiment_access")
+ if cached is not None:
+ return cached
+ page_ids = {
+ scope["experiment_id"]
+ for scanner in self._page_scanners() or ()
+ if (scope := scanner.experiment_scope()) and isinstance(scope.get("experiment_id"), int)
+ }
+ accessible = accessible_experiment_ids(self.user_access_control, team_id, page_ids) if page_ids else set()
+ page_access = {experiment_id: experiment_id in accessible for experiment_id in page_ids}
+ self.context["_page_experiment_access"] = page_access
+ return page_access
+
def create(self, validated_data: dict[str, Any]) -> ReplayScanner:
team = self.context["get_team"]()
user = acting_user(self.context)
@@ -1180,21 +1205,17 @@ class _ScannerOrderByFilter(OrderByFilter):
def _handle(self, qs: QuerySet[ReplayScanner], key: str, descending: bool) -> QuerySet[ReplayScanner]:
if key == "credits_this_month":
- # Same window and pricing as `credits_this_month`, in SQL so the database can order by it.
+ # Same receipts and window as `credits_this_month`, in SQL so the database can order by it.
organization_id = qs.values_list("team__organization_id", flat=True).first()
if organization_id is None:
return qs.order_by(self._tiebreaker)
period = current_period_bounds(organization_id)
spend = (
- ReplayObservation.objects.filter(
- scanner_id=OuterRef("pk"),
- status=ObservationStatus.SUCCEEDED,
- created_at__gte=period.start,
- created_at__lt=period.end,
- )
+ scanner_period_receipts(organization_id, period)
+ .filter(scanner_id=OuterRef("pk"))
.order_by()
.values("scanner_id")
- .annotate(total=Sum(observation_credits_case()))
+ .annotate(total=Sum("credits"))
.values("total")
)
qs = qs.annotate(
diff --git a/products/replay_vision/backend/billing.py b/products/replay_vision/backend/billing.py
index 68bc7b819d4b..0ac13395f039 100644
--- a/products/replay_vision/backend/billing.py
+++ b/products/replay_vision/backend/billing.py
@@ -10,7 +10,7 @@ from dataclasses import dataclass
from datetime import datetime
from typing import Literal, cast
-from django.db.models import Case, Count, IntegerField, Sum, Value, When
+from django.db.models import Count, IntegerField, Sum
from django.db.models.functions import Coalesce
import structlog
@@ -134,18 +134,6 @@ def observation_credits_for_model(model: str) -> int:
return credits
-def observation_credits_case() -> Case:
- """SQL mirror of `observation_credits_for_model`, for pricing observations inside a query."""
- return Case(
- *(
- When(scanner_snapshot__model=model, then=Value(credits))
- for model, credits in OBSERVATION_CREDITS_BY_MODEL.items()
- ),
- default=Value(_FALLBACK_CREDITS),
- output_field=IntegerField(),
- )
-
-
def get_replay_vision_credits_by_team(begin: datetime, end: datetime) -> list[tuple[int, int]]:
# Bucket by receipt write time so a late receipt is never dropped from an already-run daily report.
rows = (
diff --git a/products/replay_vision/backend/quota.py b/products/replay_vision/backend/quota.py
index 8b343b5ec0e8..28c714d4fee8 100644
--- a/products/replay_vision/backend/quota.py
+++ b/products/replay_vision/backend/quota.py
@@ -7,7 +7,7 @@ from dataclasses import dataclass, replace
from datetime import UTC, date, datetime, timedelta
from uuid import UUID
-from django.db.models import IntegerField, Sum, Value
+from django.db.models import Count, IntegerField, QuerySet, Sum, Value
from django.db.models.functions import Coalesce, TruncDay
import structlog
@@ -23,11 +23,7 @@ from products.replay_vision.backend.billing import (
FREE_TIER_MONTHLY_CREDITS,
observation_credits_for_model,
)
-from products.replay_vision.backend.models.replay_observation import (
- IN_FLIGHT_STATUSES,
- ObservationStatus,
- ReplayObservation,
-)
+from products.replay_vision.backend.models.replay_observation import IN_FLIGHT_STATUSES, ReplayObservation
from products.replay_vision.backend.models.replay_observation_usage import ReplayObservationUsage
from products.replay_vision.backend.models.replay_scanner import ReplayScanner
from products.replay_vision.backend.models.replay_scanner_backfill import (
@@ -239,38 +235,37 @@ class ScannerSpend:
observations: int
-def credits_used_by_scanner(organization_id: UUID, scanner_ids: list[UUID]) -> dict[UUID, ScannerSpend]:
- """Credits and observation counts for each scanner's succeeded observations in the current billing period.
+def scanner_period_receipts(organization_id: UUID, period: BillingPeriod) -> QuerySet[ReplayObservationUsage]:
+ """Receipts in a period by observation create time: the per-scanner window. Billing buckets by receipt write time instead."""
+ return ReplayObservationUsage.objects.filter(
+ organization_id=organization_id,
+ observation_created_at__gte=period.start,
+ observation_created_at__lt=period.end,
+ )
- This is the displayed figure, deliberately read from observation rows rather than the receipt ledger:
- it is what the scanner list column and the `credits_this_month` sort both show, and receipts carry no
- `scanner_id` before that column existed. `compute_scanner_budgets` is the delete-proof figure the
- limit is enforced against.
- Priced at current rates from each observation's frozen snapshot model. Receipts freeze prices
- at success time, so these totals can drift from the billed ledger after a mid-period price
- change. Scanners with no spend are omitted.
+def credits_used_by_scanner(organization_id: UUID, scanner_ids: list[UUID]) -> dict[UUID, ScannerSpend]:
+ """Billed credits and observation counts for each scanner in the current billing period.
+
+ Read from the receipt ledger, so the figure matches what billing charged and what the credit limit
+ counts: deleting an observation does not lower it, and each observation keeps the price frozen when
+ it succeeded. Scanners with no spend are omitted.
"""
if not scanner_ids:
return {}
period = current_period_bounds(organization_id)
- pairs = Counter(
- ReplayObservation.objects.filter(
- scanner_id__in=scanner_ids,
- team__organization_id=organization_id,
- status=ObservationStatus.SUCCEEDED,
- created_at__gte=period.start,
- created_at__lt=period.end,
- ).values_list("scanner_id", "scanner_snapshot__model")
+ rows = (
+ scanner_period_receipts(organization_id, period)
+ .filter(scanner_id__in=scanner_ids)
+ .values("scanner_id")
+ .annotate(total_credits=Coalesce(Sum("credits"), 0), total_observations=Count("id"))
+ .values_list("scanner_id", "total_credits", "total_observations")
)
- totals: dict[UUID, ScannerSpend] = {}
- for (scanner_id, model), count in pairs.items():
- prev = totals.get(scanner_id, ScannerSpend(0, 0))
- totals[scanner_id] = ScannerSpend(
- credits=prev.credits + observation_credits_for_model(model or "") * count,
- observations=prev.observations + count,
- )
- return totals
+ return {
+ scanner_id: ScannerSpend(credits, observations)
+ for scanner_id, credits, observations in rows
+ if scanner_id is not None # `scanner_id__in` already excludes nulls; this narrows the type
+ }
@dataclass(frozen=True)
@@ -385,12 +380,8 @@ def compute_scanner_budgets(
in_flight = _scanner_in_flight_credits(organization_id, capped_ids, period)
settled = {
row["scanner_id"]: row["total_credits"] or 0
- for row in ReplayObservationUsage.objects.filter(
- organization_id=organization_id,
- scanner_id__in=capped_ids,
- observation_created_at__gte=period.start,
- observation_created_at__lt=period.end,
- )
+ for row in scanner_period_receipts(organization_id, period)
+ .filter(scanner_id__in=capped_ids)
.values("scanner_id")
.annotate(total_credits=Coalesce(Sum("credits"), Value(0), output_field=IntegerField()))
}
diff --git a/products/replay_vision/backend/scanner_access.py b/products/replay_vision/backend/scanner_access.py
index 336348ac48f7..e46269849195 100644
--- a/products/replay_vision/backend/scanner_access.py
+++ b/products/replay_vision/backend/scanner_access.py
@@ -46,15 +46,17 @@ def scanners_for_reading_observations(team_id: int) -> "QuerySet[ReplayScanner]"
return ReplayScanner.all_origins.filter(team_id=team_id)
-def _accessible_experiment_ids(
+def accessible_experiment_ids(
access: UserAccessControl | None, team_id: int, experiment_ids: set[int] | None
) -> set[int]:
"""The experiments the caller may view, through the experiments facade. Empty input, empty result."""
# Deferred: the experiments replay facade pulls in the recordings query modules, which circle
# back into this package's importers.
- from products.experiments.backend.facade.replay import accessible_experiment_ids # noqa: PLC0415
+ from products.experiments.backend.facade.replay import ( # noqa: PLC0415
+ accessible_experiment_ids as facade_accessible_experiment_ids,
+ )
- return accessible_experiment_ids(access, team_id, experiment_ids=experiment_ids)
+ return facade_accessible_experiment_ids(access, team_id, experiment_ids=experiment_ids)
def is_experiment_accessible(access: UserAccessControl | None, team_id: int, experiment_id: int) -> bool:
@@ -65,7 +67,7 @@ def is_experiment_accessible(access: UserAccessControl | None, team_id: int, exp
than disclosing the experiment through a scanner surface. `access` is None only outside request
context (internal serialization), where there is no viewer to gate on, so it passes.
"""
- return experiment_id in _accessible_experiment_ids(access, team_id, {experiment_id})
+ return experiment_id in accessible_experiment_ids(access, team_id, {experiment_id})
def scanner_experiment_scope_q(*, unrestricted: bool = False, experiment_ids: Iterable[int] = ()) -> Q:
@@ -127,7 +129,7 @@ def accessible_observations(
The accessible set comes from the team's experiments, which are few and indexed. The snapshot
path has no index, so reading the ids off the observations instead scans the whole scanner or team.
"""
- accessible = _accessible_experiment_ids(access, team_id, None)
+ accessible = accessible_experiment_ids(access, team_id, None)
# Keep rows whose snapshot names no experiment (untargeted, unrestricted) OR an accessible one,
# whichever snapshot store names it.
return observations.filter(snapshot_experiment_scope_q(unrestricted=True, experiment_ids=accessible))
@@ -142,7 +144,7 @@ def can_read_observation(access: UserAccessControl, team_id: int, observation: "
for store in ("experiment_targeting", "scanner_config")
if (experiment_id := (snapshot.get(store) or {}).get("experiment_id")) is not None
}
- return not experiment_ids or bool(_accessible_experiment_ids(access, team_id, experiment_ids) & experiment_ids)
+ return not experiment_ids or bool(accessible_experiment_ids(access, team_id, experiment_ids) & experiment_ids)
def readable_observation_scanner_ids(access: UserAccessControl, team_id: int) -> list[uuid.UUID]:
@@ -160,7 +162,7 @@ def readable_observation_scanner_ids(access: UserAccessControl, team_id: int) ->
)
)
targeted = {eid for s in scanners if (eid := (s.experiment_scope() or {}).get("experiment_id")) is not None}
- accessible = _accessible_experiment_ids(access, team_id, targeted)
+ accessible = accessible_experiment_ids(access, team_id, targeted)
return [
s.id
for s in scanners
diff --git a/products/replay_vision/backend/tests/test_access_control.py b/products/replay_vision/backend/tests/test_access_control.py
index 219cb7b942a0..57767affe96d 100644
--- a/products/replay_vision/backend/tests/test_access_control.py
+++ b/products/replay_vision/backend/tests/test_access_control.py
@@ -259,6 +259,28 @@ class TestReplayScannerAccessControl(_AccessControlTestCase):
resp = self.client.get(f"{self.scanners_url}{scanner.id}/")
self.assertEqual(resp.json()["experiment_targeting"], targeting)
+ @parameterized.expand([("column",), ("config",)])
+ def test_list_hides_only_the_experiments_the_viewer_cannot_access(self, location: str) -> None:
+ allowed = create_experiment(self.team, "allowed-flag", created_by=self.user)
+ denied = create_experiment(self.team, "denied-flag", created_by=self.user)
+ self._create_experiment_scoped_scanner("allowed", allowed.id, location)
+ self._create_experiment_scoped_scanner("denied", denied.id, location)
+ self._set_resource_default("replay_scanner", "viewer")
+ self._grant_object_access(self.other_user, "experiment", str(denied.id), "none")
+
+ self.client.force_login(self.other_user)
+ resp = self.client.get(self.scanners_url)
+ self.assertEqual(resp.status_code, 200, resp.json())
+ rows = {row["name"]: row for row in resp.json()["results"]}
+
+ def shown_experiment_id(row: dict) -> int | None:
+ if location == "column":
+ return (row["experiment_targeting"] or {}).get("experiment_id")
+ return row["scanner_config"].get("experiment_id")
+
+ self.assertEqual(shown_experiment_id(rows["allowed"]), allowed.id)
+ self.assertIsNone(shown_experiment_id(rows["denied"]))
+
def test_save_by_a_viewer_denied_the_experiment_keeps_the_targeting(self) -> None:
# The API redacts experiment_targeting to null for such an editor, and the editor form
# writes the whole object back on save. Without the write-side guard, renaming the scanner
diff --git a/products/replay_vision/backend/tests/test_api.py b/products/replay_vision/backend/tests/test_api.py
index 8f05841ad8e9..c8c9a3a429a1 100644
--- a/products/replay_vision/backend/tests/test_api.py
+++ b/products/replay_vision/backend/tests/test_api.py
@@ -1354,6 +1354,23 @@ class TestReplayScannerTags(_VisionAPITestCase):
self.assertEqual(self.client.get(self.scanners_url).status_code, 200)
self.assertEqual(len(one_row.captured_queries), len(five_rows.captured_queries))
+ def test_list_experiment_access_is_constant_queries(self) -> None:
+ first = create_experiment(self.team, "flag-0")
+ self._create_scanner(name="scanner-0", experiment_targeting={"experiment_id": first.id})
+ self.client.get(self.scanners_url) # Warm request-scoped caches so both captures compare cleanly.
+ with CaptureQueriesContext(connection) as one_row:
+ self.assertEqual(self.client.get(self.scanners_url).status_code, 200)
+ for i in range(1, 5):
+ experiment = create_experiment(self.team, f"flag-{i}")
+ self._create_scanner(
+ name=f"scanner-{i}",
+ scanner_type=ScannerType.EXPERIMENT,
+ scanner_config={"prompt": "p", "experiment_id": experiment.id},
+ )
+ with CaptureQueriesContext(connection) as five_rows:
+ self.assertEqual(self.client.get(self.scanners_url).status_code, 200)
+ self.assertEqual(len(one_row.captured_queries), len(five_rows.captured_queries))
+
class TestScannerExperimentTargeting(_VisionAPITestCase):
def setUp(self) -> None:
@@ -4169,7 +4186,9 @@ class TestReplayScannerEstimateAction(ClickhouseTestMixin, _VisionAPITestCase):
class TestScannerSpend(_VisionAPITestCase):
- def _succeeded_observation(self, scanner: ReplayScanner, session_id: str, created_at=None) -> ReplayObservation:
+ def _succeeded_observation(
+ self, scanner: ReplayScanner, session_id: str, created_at=None, credits: int | None = None
+ ) -> ReplayObservation:
observation = ReplayObservation.objects.create(
scanner=scanner,
session_id=session_id,
@@ -4180,16 +4199,30 @@ class TestScannerSpend(_VisionAPITestCase):
)
if created_at is not None:
ReplayObservation.objects.filter(pk=observation.pk).update(created_at=created_at)
+ observation.refresh_from_db()
+ ReplayObservationUsage.objects.create(
+ observation_id=observation.id,
+ organization_id=self.team.organization_id,
+ team_id=self.team.pk,
+ scanner_id=scanner.id,
+ observation_created_at=observation.created_at,
+ model=scanner.model,
+ credits=observation_credits_for_model(scanner.model) if credits is None else credits,
+ )
return observation
- def _credits_by_name(self, response_json: dict) -> dict[str, int]:
- return {row["name"]: row["credits_this_month"] for row in response_json["results"]}
+ def _spend_by_name(self, response_json: dict) -> dict[str, tuple[int, int]]:
+ return {
+ row["name"]: (row["credits_this_month"], row["observations_this_month"]) for row in response_json["results"]
+ }
- def test_credits_this_month_sums_current_period_succeeded_observations(self) -> None:
+ def test_spend_sums_current_period_receipts(self) -> None:
spender = self._create_scanner(name="spender")
self._create_scanner(name="idle")
- self._succeeded_observation(spender, "in-window-1")
- self._succeeded_observation(spender, "in-window-2")
+ cost = observation_credits_for_model(spender.model)
+ self._succeeded_observation(spender, "in-window")
+ self._succeeded_observation(spender, "repriced", credits=cost + 7)
+ self._succeeded_observation(spender, "deleted").delete()
ReplayObservation.objects.create(
scanner=spender,
session_id="failed-in-window",
@@ -4202,9 +4235,9 @@ class TestScannerSpend(_VisionAPITestCase):
resp = self.client.get(self.scanners_url)
self.assertEqual(resp.status_code, 200, resp.json())
- credits = self._credits_by_name(resp.json())
- self.assertEqual(credits["spender"], 2 * observation_credits_for_model(spender.model))
- self.assertEqual(credits["idle"], 0)
+ spend = self._spend_by_name(resp.json())
+ self.assertEqual(spend["spender"], (3 * cost + 7, 3))
+ self.assertEqual(spend["idle"], (0, 0))
def test_order_by_credits_matches_displayed_values(self) -> None:
low = self._create_scanner(name="low")
@@ -4220,39 +4253,6 @@ class TestScannerSpend(_VisionAPITestCase):
self.assertEqual(displayed, sorted(displayed, reverse=True))
self.assertEqual([row["name"] for row in rows[:2]], ["high", "low"])
- def test_receipts_without_a_scanner_do_not_zero_the_displayed_credits(self) -> None:
- # Receipts are never backfilled with a scanner_id, so the displayed column and its sort read
- # observation rows. Pointing either at the ledger silently zeroes both for a whole period.
- spender = self._create_scanner(name="spender")
- observation = self._succeeded_observation(spender, "unattributed")
- ReplayObservationUsage.objects.create(
- observation_id=observation.id,
- organization_id=self.team.organization_id,
- team_id=self.team.pk,
- scanner_id=None,
- observation_created_at=observation.created_at,
- model=spender.model,
- credits=observation_credits_for_model(spender.model),
- )
-
- resp = self.client.get(f"{self.scanners_url}?order_by=-credits_this_month")
- self.assertEqual(resp.status_code, 200, resp.json())
- self.assertEqual(self._credits_by_name(resp.json())["spender"], observation_credits_for_model(spender.model))
-
- def _spend_against_limit(self, scanner: ReplayScanner, session_id: str) -> None:
- """Ledger spend, which is what the limit is enforced on. `_succeeded_observation` deliberately
- writes no receipt, because it seeds the displayed column, which reads observation rows."""
- observation = self._succeeded_observation(scanner, session_id)
- ReplayObservationUsage.objects.create(
- observation_id=observation.id,
- organization_id=self.team.organization_id,
- team_id=self.team.pk,
- scanner_id=scanner.id,
- observation_created_at=observation.created_at,
- model=scanner.model,
- credits=observation_credits_for_model(scanner.model),
- )
-
def test_limit_reached_is_reported_per_scanner(self) -> None:
scanner = self._create_scanner()
cost = observation_credits_for_model(scanner.model)
@@ -4262,7 +4262,7 @@ class TestScannerSpend(_VisionAPITestCase):
self.assertEqual(resp.status_code, 200, resp.json())
self.assertIs(resp.json()["limit_reached"], False)
- self._spend_against_limit(scanner, "over-limit")
+ self._succeeded_observation(scanner, "over-limit")
resp = self.client.get(f"{self.scanners_url}{scanner.id}/")
self.assertEqual(resp.status_code, 200, resp.json())
@@ -4291,7 +4291,7 @@ class TestScannerSpend(_VisionAPITestCase):
cost = observation_credits_for_model(capped.model)
ReplayScanner.objects.filter(pk=capped.pk).update(credit_limit=cost)
ReplayScanner.objects.filter(pk=free.pk).update(free_only=True)
- self._spend_against_limit(capped, "capped-spend")
+ self._succeeded_observation(capped, "capped-spend")
resp = self.client.get(self.scanners_url)
self.assertEqual(resp.status_code, 200, resp.json())
@@ -4324,14 +4324,14 @@ class TestScannerSpend(_VisionAPITestCase):
# that preserves the property, and from passing on an N+1 that happens to be shaped differently.
one = self._create_scanner(name="scanner-0")
ReplayScanner.objects.filter(pk=one.pk).update(credit_limit=10_000)
- self._spend_against_limit(one, "seed-0")
+ self._succeeded_observation(one, "seed-0")
with CaptureQueriesContext(connection) as single_page:
self.assertEqual(self.client.get(self.scanners_url).status_code, 200)
for i in range(1, 5):
extra = self._create_scanner(name=f"scanner-{i}")
ReplayScanner.objects.filter(pk=extra.pk).update(credit_limit=10_000)
- self._spend_against_limit(extra, f"seed-{i}")
+ self._succeeded_observation(extra, f"seed-{i}")
with CaptureQueriesContext(connection) as five_page:
self.assertEqual(self.client.get(self.scanners_url).status_code, 200)
diff --git a/products/replay_vision/frontend/generated/api.schemas.ts b/products/replay_vision/frontend/generated/api.schemas.ts
index 2ae5737fcd09..d3ad5f3cc28a 100644
--- a/products/replay_vision/frontend/generated/api.schemas.ts
+++ b/products/replay_vision/frontend/generated/api.schemas.ts
@@ -1345,9 +1345,9 @@ export interface ReplayScannerApi {
* @nullable
*/
readonly estimated_monthly_credits: number | null
- /** Credits this scanner's succeeded observations consumed in the current billing period (1 credit = $0.01). Matches the window of the org-wide quota meter. */
+ /** Credits billed for this scanner's observations created in the current billing period (1 credit = $0.01), each at the price frozen when it succeeded. Deleted observations still count. */
readonly credits_this_month: number
- /** Succeeded observations this scanner produced in the current billing period. */
+ /** Billed observations this scanner created in the current billing period, including deleted ones. */
readonly observations_this_month: number
/** Credits counted against `credit_limit` for the current billing period: settled receipts plus in-flight observations, priced from their frozen snapshot model. This is what the limit gate measures, so it includes work still in progress. It is not the same as `credits_this_month`, which counts only succeeded observations. For a `free_only` scanner bound by the organization's free credits, this is the organization's usage, not the scanner's own. */
readonly credits_used_against_limit: number
@@ -1489,9 +1489,9 @@ export interface PatchedReplayScannerApi {
* @nullable
*/
readonly estimated_monthly_credits?: number | null
- /** Credits this scanner's succeeded observations consumed in the current billing period (1 credit = $0.01). Matches the window of the org-wide quota meter. */
+ /** Credits billed for this scanner's observations created in the current billing period (1 credit = $0.01), each at the price frozen when it succeeded. Deleted observations still count. */
readonly credits_this_month?: number
- /** Succeeded observations this scanner produced in the current billing period. */
+ /** Billed observations this scanner created in the current billing period, including deleted ones. */
readonly observations_this_month?: number
/** Credits counted against `credit_limit` for the current billing period: settled receipts plus in-flight observations, priced from their frozen snapshot model. This is what the limit gate measures, so it includes work still in progress. It is not the same as `credits_this_month`, which counts only succeeded observations. For a `free_only` scanner bound by the organization's free credits, this is the organization's usage, not the scanner's own. */
readonly credits_used_against_limit?: number
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index cabbd60bd8d8..79bd7c53789f 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -77800,9 +77800,9 @@ export namespace Schemas {
* @nullable
*/
readonly estimated_monthly_credits: number | null;
- /** Credits this scanner's succeeded observations consumed in the current billing period (1 credit = $0.01). Matches the window of the org-wide quota meter. */
+ /** Credits billed for this scanner's observations created in the current billing period (1 credit = $0.01), each at the price frozen when it succeeded. Deleted observations still count. */
readonly credits_this_month: number;
- /** Succeeded observations this scanner produced in the current billing period. */
+ /** Billed observations this scanner created in the current billing period, including deleted ones. */
readonly observations_this_month: number;
/** Credits counted against `credit_limit` for the current billing period: settled receipts plus in-flight observations, priced from their frozen snapshot model. This is what the limit gate measures, so it includes work still in progress. It is not the same as `credits_this_month`, which counts only succeeded observations. For a `free_only` scanner bound by the organization's free credits, this is the organization's usage, not the scanner's own. */
readonly credits_used_against_limit: number;
@@ -90183,9 +90183,9 @@ export namespace Schemas {
* @nullable
*/
readonly estimated_monthly_credits?: number | null;
- /** Credits this scanner's succeeded observations consumed in the current billing period (1 credit = $0.01). Matches the window of the org-wide quota meter. */
+ /** Credits billed for this scanner's observations created in the current billing period (1 credit = $0.01), each at the price frozen when it succeeded. Deleted observations still count. */
readonly credits_this_month?: number;
- /** Succeeded observations this scanner produced in the current billing period. */
+ /** Billed observations this scanner created in the current billing period, including deleted ones. */
readonly observations_this_month?: number;
/** Credits counted against `credit_limit` for the current billing period: settled receipts plus in-flight observations, priced from their frozen snapshot model. This is what the limit gate measures, so it includes work still in progress. It is not the same as `credits_this_month`, which counts only succeeded observations. For a `free_only` scanner bound by the organization's free credits, this is the organization's usage, not the scanner's own. */
readonly credits_used_against_limit?: number;