[PR #379] [MERGED] Fix pricing calculations and preserve model field during preflight operations processing #685

Closed
opened 2026-03-13 21:03:43 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/379
Author: @AJaySi
Created: 3/5/2026
Status: Merged
Merged: 3/5/2026
Merged by: @AJaySi

Base: mainHead: codex/review-subscription-system-for-production-readiness


📝 Commits (5)

  • 81052d0 Fix preflight model mapping when skipping invalid providers
  • 45dbf09 Add Stripe webhook idempotency persistence guard
  • 81f49f4 Add explicit usage summary uniqueness and billing indexes
  • 7d530b3 Preserve full provider breakdown in billing UI coercion
  • 01bf568 Fix unlimited video limit display in usage rings

📊 Changes

6 files changed (+246 additions, -136 deletions)

View changed files

📝 backend/api/subscription/routes/preflight.py (+14 -7)
📝 backend/models/subscription_models.py (+21 -1)
📝 backend/services/subscription/stripe_service.py (+88 -19)
📝 frontend/src/components/billing/CompactBillingDashboard/components/UsageLimitRings.tsx (+37 -14)
📝 frontend/src/services/billingService.ts (+85 -90)
📝 frontend/src/types/billing.ts (+1 -5)

📄 Description

Motivation

  • Prevent incorrect cost estimates by fixing token/audio pricing math which was previously scaled by 1/1000.
  • Ensure model lookups remain consistent when invalid providers are skipped by preserving the originating model field in the validated operations list.
  • Avoid index drift when iterating validated operations after filtering by iterating directly over the validated list.

Description

  • Add model to each entry in operations_to_validate and keep request fields together to ensure stable model lookup.
  • Change the loop to iterate over operations_to_validate directly and use op.get('model') when fetching pricing.
  • Adjust pricing calculations to treat cost_per_input_token as a cost-per-token unit and multiply by tokens_requested without dividing by 1000, and add clarifying comments.
  • Preserve special-case audio model pricing logic and apply rounding of per-operation costs to 4 decimal places, while keeping existing fallback default costs.

Testing

  • Ran the backend subscription/pricing unit tests via pytest (including preflight pricing checks) and the tests completed successfully.

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/379 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/5/2026 **Status:** ✅ Merged **Merged:** 3/5/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/review-subscription-system-for-production-readiness` --- ### 📝 Commits (5) - [`81052d0`](https://github.com/AJaySi/ALwrity/commit/81052d06b430d7b9ca98ed9e5aab8ae14ec06280) Fix preflight model mapping when skipping invalid providers - [`45dbf09`](https://github.com/AJaySi/ALwrity/commit/45dbf095f6470958db14ca9b9c71b959089e9534) Add Stripe webhook idempotency persistence guard - [`81f49f4`](https://github.com/AJaySi/ALwrity/commit/81f49f4ebd204bef3b6f349b4e853bd218e315d6) Add explicit usage summary uniqueness and billing indexes - [`7d530b3`](https://github.com/AJaySi/ALwrity/commit/7d530b3220711282444b0ddb188a92aac3091197) Preserve full provider breakdown in billing UI coercion - [`01bf568`](https://github.com/AJaySi/ALwrity/commit/01bf56837fbacb37a2f85881a67e585a4daa81ea) Fix unlimited video limit display in usage rings ### 📊 Changes **6 files changed** (+246 additions, -136 deletions) <details> <summary>View changed files</summary> 📝 `backend/api/subscription/routes/preflight.py` (+14 -7) 📝 `backend/models/subscription_models.py` (+21 -1) 📝 `backend/services/subscription/stripe_service.py` (+88 -19) 📝 `frontend/src/components/billing/CompactBillingDashboard/components/UsageLimitRings.tsx` (+37 -14) 📝 `frontend/src/services/billingService.ts` (+85 -90) 📝 `frontend/src/types/billing.ts` (+1 -5) </details> ### 📄 Description ### Motivation - Prevent incorrect cost estimates by fixing token/audio pricing math which was previously scaled by 1/1000. - Ensure model lookups remain consistent when invalid providers are skipped by preserving the originating `model` field in the validated operations list. - Avoid index drift when iterating validated operations after filtering by iterating directly over the validated list. ### Description - Add `model` to each entry in `operations_to_validate` and keep request fields together to ensure stable model lookup. - Change the loop to iterate over `operations_to_validate` directly and use `op.get('model')` when fetching pricing. - Adjust pricing calculations to treat `cost_per_input_token` as a cost-per-token unit and multiply by `tokens_requested` without dividing by 1000, and add clarifying comments. - Preserve special-case audio model pricing logic and apply rounding of per-operation costs to 4 decimal places, while keeping existing fallback default costs. ### Testing - Ran the backend subscription/pricing unit tests via `pytest` (including preflight pricing checks) and the tests completed successfully. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69a844ade6848328ba473afa2f4dd0c1) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 21:03:43 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#685
No description provided.