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.

fix(signals): show refunded PRs next to the inbox PR count (#98098)

posthog[bot]428f2e7bc982
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 73761d60ad77..66b064275b70 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -9481,25 +9481,33 @@ snapshots:
scenes-app-inbox-tabs--runs-loading--light:
hash: v1.k794b7964.4eb178f9e66f29a39f3228c992661409215bf5b173ae458978b3c9876f14bb49.miH6CsWRVa_TkVCM3QJMhPicboUncrDXfrEEWYaVb24
scenes-app-inbox-usagewidget--approaching-limit--dark:
- hash: v1.k794b7964.f8a534cc7d33cc6ade581834f3992f6755fc206b3dceea50c8033aee9ebe87d3._FCVV4FR_QGjuJATWZfSKe1QQ7QmNKf0QHLoD2c1ygA
+ hash: v1.k794b7964.bb258067fd5e4c1d488979422df5eca9612e3e9cecbc19f78473b5de70abe215.-Uz5oqZ3DlprzO-dB1Ijq3JOZoQo5qKcUP_vI77q5GU
scenes-app-inbox-usagewidget--approaching-limit--light:
- hash: v1.k794b7964.f77cb537d1e355455806ffff9573cde023cf2d101c52bfb0664ba05f2c80c510.AJscbaOl4AOoZuwC1ACJBj_w8LTFu609VHV62-xON4M
+ hash: v1.k794b7964.9ce46e554d1f091544764f617297af317496b236fa7176ca7a83838905a804ee.H7yORek2WxrqrIsZXwNTpsEiUGnuM3RATvmXweHzpwQ
scenes-app-inbox-usagewidget--at-limit--dark:
- hash: v1.k794b7964.d15112e6a9c61e3089c62752a76de2007ae902584a7a84b6c8cb2cc120506c90.Zjw5oZKYgxxJvhtsWiw5TBc2zUdZj_AjvzfDJ-1OBQE
+ hash: v1.k794b7964.961c32717eac3dedef649e175f4d1bbbf3f09cdee27db645e19f2dd3f0c30e00.UJQqMjfNVcfx8dwE2H3JZfAeszOeX2WibYtRRGjBcLk
scenes-app-inbox-usagewidget--at-limit--light:
- hash: v1.k794b7964.629ef257681c62517d21a6e7a5ee8da0781405e2203999d3348eccf9d241c301.d8Z7OApu2INBqrhzdewR-JtoIXM2gD4w5rA8OcOQ5i8
+ hash: v1.k794b7964.3a9dca8716d871a737a0f2259d59860efee188e7c990b33bf7ea3cf03e5d73c6.YnB9i9BaUpBOWLtdKKgawewzH6_q-0V3U5J_4DryhQg
scenes-app-inbox-usagewidget--billable-usage--dark:
- hash: v1.k794b7964.9a33ec61e0041b48c2fd6c5db33dd6a27bf5df6414ea930daf7710255f839c91.WSh82lU2jtWoKYCMD-LkMnWfhvqezDUnuMkaqsv923w
+ hash: v1.k794b7964.98f8a82c736522bb85a01f1c777d0ca0b4b9b7cb72a9334cc5c3ec74796931c0.PSJRRwgJVLLXJEiAWbwAgXAPE4RVZkawlbsZDsOXUnM
scenes-app-inbox-usagewidget--billable-usage--light:
- hash: v1.k794b7964.b26a7353b9bfc1a96b836141330eb27807e580b0dc61907acbe930f73adaba50.spG4UevuXak5fAy6ODffGKuyaJMqga-PJA5jEjKBUlI
+ hash: v1.k794b7964.7465b1acab6836d36f3884d73ebcc126ab9d262bf0fa90404b72cdd35433e58e.02WU-qx6BZuF06cov9MX7Ok5WdjrYPqF06uHCGKOnSw
scenes-app-inbox-usagewidget--free-plan-zero-usage--dark:
- hash: v1.k794b7964.0aa9a743a200f15cd066a1249e1cf6ef9466df85c4c64bb887b620e8e9ab048a.mpJB9IS4LgIenK23siHiF-UtgwPcgvm8hyTqGUeegk8
+ hash: v1.k794b7964.73b24c2ad711ae1c47c71f6dd1fd9e945afe14a4cb07f86357a16469f2223083.GTvVgUxAQVwR9-fw_nfTA6k42IkLtt3jAmQ9PotAJ4Q
scenes-app-inbox-usagewidget--free-plan-zero-usage--light:
- hash: v1.k794b7964.03afdb95ee5db5dff05e5ccd8494971b23e2b1991a15e3a811429367de47571b.KpBW7ZZ56gc1aPTxe3nFmTT-wGk7kNhwdjdI_9jDo78
+ hash: v1.k794b7964.31669bfef40ed11472d5175dabd7c1a48eed92b1dd7d50cc78c295166e268f6f.EypQJCPD06mg1k0MTyckwpZcgk6iJonGS8lwLpF7vKs
+ scenes-app-inbox-usagewidget--over-limit--dark:
+ hash: v1.k794b7964.f60272307d66f5b06bc0acb9c7a886ff496d4efa191cc75446a79150a60ee72c.6EiSeX2uMXtUryheZiut1SqlhALDhmUh3LJZ4OMHMlc
+ scenes-app-inbox-usagewidget--over-limit--light:
+ hash: v1.k794b7964.d2fce435d5836f83b7682631fb6947918347bccca1eaac869540cc4b509c83ce.GqTDyFYonRUTsHIfyNOnlc2RGrjRSGzMFC5wIDOjESA
+ scenes-app-inbox-usagewidget--with-refunded-prs--dark:
+ hash: v1.k794b7964.875a77e4c83d0726353378669a938b7b5928eaa137efda007484d00484cf8e5f.pYGPbBYNBaZYERh18RBaf6p9KWZbXdDZWug_yO53BLk
+ scenes-app-inbox-usagewidget--with-refunded-prs--light:
+ hash: v1.k794b7964.0cc78324f3aa6647cd3ccfa532b7dad83cda5f38383ba88db0f0336998a3974b.-qwM4Vm72oEySk95eu10Kmi_dZ-3aRTzfeRhrpnUF1A
scenes-app-inbox-usagewidget--within-free-tier--dark:
- hash: v1.k794b7964.f4936fcab5d19e24e39b7357d24c643c328e82c47034adcf33502b3633e947c6.XqPeVTdmBJnXEJoF-pLRkGnvEg_7rSzZwKjW3Tc1AQk
+ hash: v1.k794b7964.f08e33da24a85604e6c034e0e75ea9aee591e95a89bd7f641d8e7fd14d035cba.jvSH7jzc9QVJhYUhHnmPZSZ6R4YZ3bIlaGEvQAGK5rA
scenes-app-inbox-usagewidget--within-free-tier--light:
- hash: v1.k794b7964.85e2806575ce497e93a6c3dc95a39e6093f85422566cf852ea3d518569d29fc8.M8JloRqQpx2F1SkNFosfCxdACXJGX7FCxiv4421FROU
+ hash: v1.k794b7964.648bee645e8d97ed41b88b2f64ad75bbb9d0e54f6bf5395483e6f69717a80dc9.lU5ww7_KZ4Zxgkg2mtj0PyFXeH_CCdGCUyWkUD0q7AQ
scenes-app-insights-error-empty-states--empty--dark:
hash: v1.k794b7964.ecb3db61cbdf2626fe76efc91c596d577bb4a290397a1f70fe67ab630fec601e.0G6XKBCX4pueOZEuUQsKvuhddVomaRRxOwLcSZt98T4
scenes-app-insights-error-empty-states--empty--light:
diff --git a/products/signals/frontend/inbox/components/shell/InboxUsageWidget.stories.tsx b/products/signals/frontend/inbox/components/shell/InboxUsageWidget.stories.tsx
index b06457e5015b..91be05bdd152 100644
--- a/products/signals/frontend/inbox/components/shell/InboxUsageWidget.stories.tsx
+++ b/products/signals/frontend/inbox/components/shell/InboxUsageWidget.stories.tsx
@@ -1,5 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
+import { FEATURE_FLAGS } from 'lib/constants'
+
import { useStorybookMocks } from '~/mocks/browser'
import { billingJson } from '~/mocks/fixtures/_billing'
import { BillingProductV2Type, BillingType } from '~/types'
@@ -16,6 +18,8 @@ interface InboxState {
freePrs: number
usedPrs: number
limitPrs: number | null
+ // Credited-path refunds inside `usedPrs`. Needs the refunds flag on the story to reach the widget.
+ refundedPrs?: number
}
function inboxProduct({ subscribed, freePrs, usedPrs, limitPrs }: InboxState): BillingProductV2Type {
@@ -49,6 +53,12 @@ function StateMocks({ state }: { state: InboxState }): JSX.Element {
useStorybookMocks({
get: {
'/api/billing/': billingFor(state),
+ '/api/projects/:team_id/signals/reports/refund-summary/': {
+ credited_refund_count: state.refundedPrs ?? 0,
+ credited_credits: state.refundedPrs ?? 0,
+ period_billable_credits: state.usedPrs,
+ quota_limited: false,
+ },
},
})
// Mimic the agents rail's narrow column so the widget lays out as it does in the scene.
@@ -91,3 +101,14 @@ export const ApproachingLimit: Story = {
export const AtLimit: Story = {
render: () => <StateMocks state={{ subscribed: true, freePrs: 3, usedPrs: 50, limitPrs: 50 }} />,
}
+
+// Usage runs past the limit while the quota cron catches up, so the count reports the overshoot.
+export const OverLimit: Story = {
+ render: () => <StateMocks state={{ subscribed: true, freePrs: 3, usedPrs: 53, limitPrs: 50 }} />,
+}
+
+// Refunded PRs stay in billing usage, so the count drops to 10 and the refund line names the 12.
+export const WithRefundedPrs: Story = {
+ parameters: { featureFlags: [FEATURE_FLAGS.SIGNALS_PR_REFUNDS] },
+ render: () => <StateMocks state={{ subscribed: true, freePrs: 3, usedPrs: 12, limitPrs: 50, refundedPrs: 2 }} />,
+}
diff --git a/products/signals/frontend/inbox/components/shell/InboxUsageWidget.tsx b/products/signals/frontend/inbox/components/shell/InboxUsageWidget.tsx
index 8853bd5d35e0..b094925f9a75 100644
--- a/products/signals/frontend/inbox/components/shell/InboxUsageWidget.tsx
+++ b/products/signals/frontend/inbox/components/shell/InboxUsageWidget.tsx
@@ -139,8 +139,10 @@ function EditLimitModal(): JSX.Element {
/**
* Compact PR-usage meter for the inbox agents rail: a status-coloured usage bar with USD spent so far
- * alongside it, then `X / Y PRs created` on the left and `Resets <date>` on the right. On a paid plan
- * the limit is editable (and the edit affordance escalates to "Increase limit" at the cap); on the
+ * alongside it, then `X / Y PRs used across your organization` on the left and `Resets <date>` on
+ * the right. That count is org-wide, uncapped, and net of refunds, on the same basis as the quota
+ * check. When refunds exist, a line under it names the gross count the billing page shows. On a paid
+ * plan the limit is editable (and the edit affordance escalates to "Increase limit" at the cap); on the
* free plan it shows an in-place upgrade instead. Renders nothing until billing has loaded and the
* inbox product is present. Deliberately billing-only: the team's daily report cap lives with the
* autonomy throttles in SelfDrivingSection, so a self-imposed cap never reads as a plan limit.
@@ -152,7 +154,9 @@ export function InboxUsageWidget(): JSX.Element | null {
isLoading,
isSubscribed,
canAccessBilling,
- usedPrsDisplay,
+ createdPrs,
+ usedPrs,
+ refundedPrs,
limitPrs,
freePrs,
status,
@@ -206,18 +210,25 @@ export function InboxUsageWidget(): JSX.Element | null {
</span>
)}
</div>
- <div className="flex items-center justify-between gap-2 text-xs">
- <Tooltip title="PRs opened by agents across your whole organization this billing period">
- {/* tabIndex so keyboard users can focus the count and get the org-wide scope */}
+ {/* Wraps rather than clips: the scope wording makes this row too wide for a narrow rail. */}
+ <div className="flex flex-wrap items-center justify-between gap-x-2 gap-y-0.5 text-xs">
+ <Tooltip title="PRs agents opened across your organization this billing period, minus refunded PRs. This is the count that goes toward your limit. It can run past the limit before agents pause.">
+ {/* tabIndex so keyboard users can reach the tooltip */}
<span className="text-secondary tabular-nums" tabIndex={0}>
- <span className="font-medium text-default">{usedPrsDisplay}</span>
- {limitPrs != null ? ` / ${limitPrs}` : ''} PRs created
+ <span className="font-medium text-default">{usedPrs}</span>
+ {limitPrs != null ? ` / ${limitPrs}` : ''} PRs used across your organization
</span>
</Tooltip>
{resetDate && (
<span className="text-tertiary tabular-nums">Resets {resetDate.format('MMM D')}</span>
)}
</div>
+ {/* Your billing page counts every created PR, so this line explains why it shows more. */}
+ {refundedPrs > 0 && (
+ <span className="text-xs text-tertiary tabular-nums">
+ {createdPrs} created, {refundedPrs} refunded. Refunded PRs don't count toward your limit.
+ </span>
+ )}
{quotaLimited && (
<span className="text-xs font-medium text-danger">
Agents are paused. They won't write new reports or open pull requests until the limit is raised
diff --git a/products/signals/frontend/inbox/logics/inboxUsageLogic.test.ts b/products/signals/frontend/inbox/logics/inboxUsageLogic.test.ts
index c135ed943bfa..fb07699d602f 100644
--- a/products/signals/frontend/inbox/logics/inboxUsageLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/inboxUsageLogic.test.ts
@@ -16,13 +16,23 @@ const CREDITS_PER_PR = 1500
const mockUsageEndpoints = (
currentUsage: number,
summary: Omit<SignalReportRefundSummaryResponseApi, 'credited_refund_count' | 'quota_limited'> &
- Partial<Pick<SignalReportRefundSummaryResponseApi, 'quota_limited'>>
+ Partial<Pick<SignalReportRefundSummaryResponseApi, 'quota_limited'>>,
+ usageLimit?: number
): void => {
useMocks({
get: {
'/api/billing': () => [
200,
- { products: [{ type: 'inbox', display_divisor: CREDITS_PER_PR, current_usage: currentUsage }] },
+ {
+ products: [
+ {
+ type: 'inbox',
+ display_divisor: CREDITS_PER_PR,
+ current_usage: currentUsage,
+ usage_limit: usageLimit,
+ },
+ ],
+ },
],
'/api/projects/:team_id/signals/reports/refund-summary/': () => [
200,
@@ -41,9 +51,10 @@ const setRefundsFlag = (): void => {
const mountWithUsage = async (
currentUsage: number,
summary: Omit<SignalReportRefundSummaryResponseApi, 'credited_refund_count' | 'quota_limited'> &
- Partial<Pick<SignalReportRefundSummaryResponseApi, 'quota_limited'>>
+ Partial<Pick<SignalReportRefundSummaryResponseApi, 'quota_limited'>>,
+ usageLimit?: number
): Promise<ReturnType<typeof inboxUsageLogic.build>> => {
- mockUsageEndpoints(currentUsage, summary)
+ mockUsageEndpoints(currentUsage, summary, usageLimit)
featureFlagLogic.mount()
setRefundsFlag()
const logic = inboxUsageLogic()
@@ -66,23 +77,53 @@ describe('inboxUsageLogic', () => {
logic?.unmount()
})
- // usedPrs must read `max(billing's recorded usage, live billable credits) − credited refunds`:
- // recorded usage lags up to a day, so a just-created PR (and its same-day excluded-path refund)
- // is only visible through the live count, while credited-path refunds stay in recorded usage
- // and must be netted out. Each row pins one side of that contract.
+ // createdPrs must read `max(billing's recorded usage, live billable credits)`, the gross total
+ // the billing page shows: recorded usage lags up to a day, so a just-created PR (and its same-day
+ // excluded-path refund) is only visible through the live count. usedPrs must subtract credited
+ // refunds, because the quota check does, so a refund frees a slot. Each row pins one side of that
+ // contract.
it.each([
- // [case, billing current_usage, live period credits, credited credits, expected PRs]
- ['counts a just-created PR that billing has not recorded yet', 1500, 3000, 0, 2],
- ['drops when a same-day refund removes the PR from live usage', 1500, 1500, 0, 1],
- ['nets credited-path refunds out of recorded usage', 9000, 9000, 1500, 5],
- ['clamps at zero when credited refunds exceed billed usage', 0, 1500, 3000, 0],
- ])('%s', async (_case, currentUsage, periodBillableCredits, creditedCredits, expectedPrs) => {
- logic = await mountWithUsage(currentUsage, {
- period_billable_credits: periodBillableCredits,
- credited_credits: creditedCredits,
- })
-
- expect(logic.values.usedPrs).toBe(expectedPrs)
+ // [case, billing current_usage, live period credits, credited credits, created, refunded, used]
+ ['counts a just-created PR that billing has not recorded yet', 1500, 3000, 0, 2, 0, 2],
+ ['drops when a same-day refund removes the PR from live usage', 1500, 1500, 0, 1, 0, 1],
+ ['nets credited-path refunds out of the limit count', 9000, 9000, 1500, 6, 1, 5],
+ ['clamps at zero when credited refunds exceed billed usage', 0, 1500, 3000, 1, 2, 0],
+ ])(
+ '%s',
+ async (
+ _case,
+ currentUsage,
+ periodBillableCredits,
+ creditedCredits,
+ expectedCreatedPrs,
+ expectedRefundedPrs,
+ expectedUsedPrs
+ ) => {
+ logic = await mountWithUsage(currentUsage, {
+ period_billable_credits: periodBillableCredits,
+ credited_credits: creditedCredits,
+ })
+
+ expect(logic.values).toMatchObject({
+ createdPrs: expectedCreatedPrs,
+ refundedPrs: expectedRefundedPrs,
+ usedPrs: expectedUsedPrs,
+ })
+ }
+ )
+
+ // The quota cron reacts after the fact, so usage runs past the limit before agents pause. The
+ // widget must report that overshoot instead of capping it at the limit.
+ it('reports usage past the limit instead of capping it', async () => {
+ logic = await mountWithUsage(
+ 53 * CREDITS_PER_PR,
+ { period_billable_credits: 53 * CREDITS_PER_PR, credited_credits: 0 },
+ 50 * CREDITS_PER_PR
+ )
+
+ expect(logic.values.usedPrs).toBe(53)
+ expect(logic.values.limitPrs).toBe(50)
+ expect(logic.values.status).toBe('limit')
})
// The refunds flag is keyed on the organization group, so on a fresh pageload it resolves
diff --git a/products/signals/frontend/inbox/logics/inboxUsageLogic.ts b/products/signals/frontend/inbox/logics/inboxUsageLogic.ts
index 234652aa5a70..98af7c0673ab 100644
--- a/products/signals/frontend/inbox/logics/inboxUsageLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxUsageLogic.ts
@@ -38,6 +38,7 @@ export interface inboxUsageLogicValues {
canAccessBilling: boolean // billingLogic
featureFlags: FeatureFlagsSet // featureFlagLogic
currentTeamId: number | null // teamLogic
+ createdPrs: number
creditsPerPr: number | null
customLimitUsd: number | null
estimatedBudgetUsd: number | null
@@ -76,6 +77,7 @@ export interface inboxUsageLogicValues {
quotaLimited: boolean
refundSummary: SignalReportRefundSummaryResponseApi | null
refundSummaryLoading: boolean
+ refundedPrs: number
refundsFlagEnabled: boolean
resetDate: Dayjs | null
showLimitFormErrors: boolean
@@ -83,7 +85,6 @@ export interface inboxUsageLogicValues {
status: InboxUsageStatus
summaryFlagEnabled: boolean
usedPrs: number
- usedPrsDisplay: number
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -181,11 +182,13 @@ export interface inboxUsageLogicMeta {
creditsPerPr: (product: BillingProductV2Type | null) => number | null
pricePerPrUsd: (product: BillingProductV2Type | null) => number | null
freePrs: (product: BillingProductV2Type | null) => number
- usedPrs: (
+ createdPrs: (
product: BillingProductV2Type | null,
creditsPerPr: number | null,
refundSummary: SignalReportRefundSummaryResponseApi | null
) => number
+ refundedPrs: (refundSummary: SignalReportRefundSummaryResponseApi | null) => number
+ usedPrs: (createdPrs: number, refundedPrs: number) => number
customLimitUsd: (billing: BillingType | null, product: BillingProductV2Type | null) => number | null
limitPrs: (
product: BillingProductV2Type | null,
@@ -196,7 +199,6 @@ export interface inboxUsageLogicMeta {
) => number | null
status: (usedPrs: number, limitPrs: number | null) => InboxUsageStatus
quotaLimited: (refundSummary: SignalReportRefundSummaryResponseApi | null) => boolean
- usedPrsDisplay: (usedPrs: number, limitPrs: number | null) => number
spentUsd: (usedPrs: number, freePrs: number, pricePerPrUsd: number | null) => number | null
percentage: (usedPrs: number, limitPrs: number | null, freePrs: number) => number
resetDate: (billing: BillingType | null) => Dayjs | null
@@ -220,8 +222,9 @@ export type inboxUsageLogicType = MakeLogicType<
/**
* Drives the PR-usage widget in the inbox agents rail. Reads the inbox/signals billing product and
* surfaces usage, limit, and reset date in PRs (the product bills in credits; `display_divisor`
- * converts credits → PRs). Editing the limit writes a USD spend cap to `custom_limits_usd`, the
- * same mechanism the billing page uses.
+ * converts credits → PRs). Usage is the quota's net count, not capped at the limit, and the widget
+ * names the gross count and refunds so it still reconciles with the billing page. Editing the limit
+ * writes a USD spend cap to `custom_limits_usd`, the same mechanism the billing page uses.
*/
export const inboxUsageLogic = kea<inboxUsageLogicType>([
path(['scenes', 'inbox', 'logics', 'inboxUsageLogic']),
@@ -243,8 +246,8 @@ export const inboxUsageLogic = kea<inboxUsageLogicType>([
loaders(({ values }) => ({
// Credited-path refund totals for the org's current billing period. Billing usage still
// contains credited-refunded PRs (the money comes back as an invoice credit, not lower
- // usage), so the widget subtracts these to show the net PR count. Excluded-path refunds
- // never reach billing usage and need no adjustment.
+ // usage), so the widget subtracts them to show the count the quota check uses, and names
+ // them next to it. Excluded-path refunds never reach billing usage and need no adjustment.
// Usage + refund summary are org-wide (billing allocates the free PR tier per org); the
// widget labels the count accordingly. Revisit if billing ever splits usage per project.
refundSummary: [
@@ -375,7 +378,8 @@ export const inboxUsageLogic = kea<inboxUsageLogicType>([
(product: BillingProductV2Type | null): number | null => derivePricePerPrUsd(product),
],
freePrs: [(s) => [s.product], (product: BillingProductV2Type | null): number => deriveFreePrs(product)],
- usedPrs: [
+ // Gross PRs on billing's own basis, so this matches the usage on the billing page.
+ createdPrs: [
(s) => [s.product, s.creditsPerPr, s.refundSummary],
(
product: BillingProductV2Type | null,
@@ -386,16 +390,27 @@ export const inboxUsageLogic = kea<inboxUsageLogicType>([
return 0
}
// Billing's recorded usage lags by up to a day; the refund summary carries the org's
- // live billable credits, so take the max — a just-created PR counts immediately and a
+ // live billable credits, so take the max. A just-created PR counts immediately and a
// same-day (excluded-path) refund visibly un-counts it.
const billedCredits = Math.max(product.current_usage ?? 0, refundSummary?.period_billable_credits ?? 0)
- const billedPrs = Math.round(billedCredits / creditsPerPr)
- // Credited-path refunds stay in billing usage; net them out so the widget counts
- // only PRs the user is actually paying (or using free allowance) for.
- const refundedPrs = refundSummary ? Math.floor(refundSummary.credited_credits / creditsPerPr) : 0
- return Math.max(0, billedPrs - refundedPrs)
+ return Math.round(billedCredits / creditsPerPr)
},
],
+ // Credited-path refunds stay in billing usage, so they are inside `createdPrs`.
+ refundedPrs: [
+ (s) => [s.refundSummary],
+ (refundSummary: SignalReportRefundSummaryResponseApi | null): number =>
+ refundSummary?.credited_refund_count ?? 0,
+ ],
+ // The PRs that count toward the limit. The quota check subtracts credited refunds from
+ // billing usage (see `_signals_credited_refund_offset` in ee/billing/quota_limiting.py), so
+ // a refund frees a slot. Keep this in step with that check, or the widget reports the org at
+ // its limit while agents still run. Not capped at the limit, because usage can run past it
+ // before the quota cron pauses agents.
+ usedPrs: [
+ (s) => [s.createdPrs, s.refundedPrs],
+ (createdPrs: number, refundedPrs: number): number => Math.max(0, createdPrs - refundedPrs),
+ ],
customLimitUsd: [
(s) => [s.billing, s.product],
(billing: null | import('~/types').BillingType, product: BillingProductV2Type | null): number | null => {
@@ -451,12 +466,6 @@ export const inboxUsageLogic = kea<inboxUsageLogicType>([
(refundSummary: SignalReportRefundSummaryResponseApi | null): boolean =>
refundSummary?.quota_limited === true,
],
- // Displayed usage caps at the limit — we never show "53 / 50" when usage runs over.
- usedPrsDisplay: [
- (s) => [s.usedPrs, s.limitPrs],
- (usedPrs: number, limitPrs: number | null): number =>
- limitPrs != null ? Math.min(usedPrs, limitPrs) : usedPrs,
- ],
// USD spent so far this period: PRs beyond the free allowance, at the per-PR price.
// Null when we can't price a PR (so the widget hides the figure rather than show "$0").
spentUsd: [
@@ -504,7 +513,7 @@ export const inboxUsageLogic = kea<inboxUsageLogicType>([
actions.setLimitFormValue('prs', values.limitPrs ?? values.freePrs)
},
// Refunds broadcast `reportStateChanged` after dismissing server-side; reload the summary so
- // the widget's netted PR count updates in-session (mirrors the reportListLogic reconcile
+ // the widget's PR and refund counts update in-session (mirrors the reportListLogic reconcile
// listener — a plain dismiss or resolve just makes this a cheap no-op reload).
[inboxBulkActionsLogic.actionTypes.reportStateChanged]: () => actions.loadRefundSummary(),
})),