Skip to content

fix: serialize advertising spend cap checks - #11824

Merged
lalalune merged 1 commit into
developfrom
fix/11800-ad-spend-cap
Jul 3, 2026
Merged

lalalune merged 1 commit into
developfrom
fix/11800-ad-spend-cap

Conversation

@lalalune

@lalalune lalalune commented Jul 3, 2026

Copy link
Copy Markdown
Member

Fixes #11800

Summary

  • serialize account spend-cap allocation checks with per-account transaction advisory locks for campaign create, budget increases, and cap updates
  • lock the ad account row during serve debits so concurrent campaigns cannot write-skew the account cap
  • add service coverage for a provider-accepted budget increase that loses the serialized cap race and verifies refund + provider revert

Evidence

  • .github/issue-evidence/11800-ad-spend-cap/README.md

Verification

  • bun install - pass after rebase; artifact sync side effects removed from branch
  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-campaign-credit-reconciliation.test.ts - pass, 14 tests
  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-account-approval.test.ts - pass, 20 tests
  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-inventory.test.ts - pass
  • bun run --cwd packages/cloud/shared lint - pass
  • bun run --cwd packages/cloud/shared typecheck - pass
  • git diff --check - pass
  • bun run verify - fails before workspace lint/typecheck on existing audit:type-safety-ratchet: ?? "" is 616 / 615

Evidence N/A

  • Frontend screenshots/video: N/A - backend concurrency fix
  • Real LLM trajectories: N/A - no agent, prompt, model, or provider behavior changed

@greptile-apps greptile-apps Bot 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ceceae06-0cd5-426c-8ceb-eeabbe72345a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/11800-ad-spend-cap

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lalalune
lalalune force-pushed the fix/11800-ad-spend-cap branch from 8e5b72f to 5c6f128 Compare July 3, 2026 04:32

@greptile-apps greptile-apps Bot 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@lalalune

lalalune commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Rebased #11824 onto current origin/develop after #11822 and revalidated on 5c6f1288e2.

Validation:

  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-campaign-credit-reconciliation.test.ts -> 14 pass
  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-account-approval.test.ts -> 20 pass
  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-inventory.test.ts -> 17 pass
  • bun run --cwd packages/cloud/shared typecheck -> pass
  • bunx biome check on touched repository/service/test files -> pass
  • git diff --check origin/develop...HEAD -> pass

Reviewed the money-path behavior: allocation/cap updates now serialize per account, serve debits lock the account row before the aggregate cap check, and provider-accepted budget/create operations refund and revert/delete the provider object if the final serialized local cap check loses a race.

@lalalune

lalalune commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Local validation after rebase onto current develop:

  • bun run install:light
  • bun run --cwd packages/core build
  • bun run --cwd packages/shared build
  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-campaign-credit-reconciliation.test.ts — pass, 14 tests
  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-account-approval.test.ts — pass, 20 tests
  • bun test packages/cloud/shared/src/lib/services/__tests__/ad-inventory.test.ts — pass
  • bun run --cwd packages/cloud/shared lint — pass
  • bun run --cwd packages/cloud/shared typecheck — pass
  • git diff --check HEAD — pass

@claude

claude Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

advertising: account-level spend cap bypassable under concurrency (allocation TOCTOU + SSP serve write-skew) — follow-up to #11779

2 participants