Repository navigation
fix(billing): settle hosted fal generations to their exact cost - #9750
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
[Critical impact] The reviewed changes appear safe to merge. SummaryAdds delayed settlement for hosted fal generations initially billed from estimates.
|
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
All reported issues were addressed across 19 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
falai-cost-settlementTrigger task: a generation billed on an estimate schedules a settlement (2 min delay, retried with backoff for about an hour) that reads fal's billing event for the request and records the shortfall as one ledger row. The row's event key is the fal request id, so retries never bill twice; an estimate above the exact charge stays billed, since the ledger records charges onlyvideo_falai,image_generate, through a declarativehosting.exactCostSettlement: 'falai'read byexecuteTool, at the tool's markup) and Chat'sgenerate_video/generate_audio(at cost, matching how Mothership bills fal media). The hosted key travels as its env var name, never its value, so the task reads the key that created the requestcancelFalRequestType of Change
Testing
lib/tools/falai-settlement.integration.ts(real Postgres, fal billing-events stubbed): the shortfall is billed exactly once across repeated settlements (fails with a per-attempt ledger key), nothing is billed while fal has no receipt, and a missing hosted key refuses without calling fallib/internal/image/operations.test.ts: polling that stops before completion cancels the fal request (fails without the cancel)lib/media/falai.test.ts,lib/mothership/tools/server/media/*,lib/internal/video,tools/index.test.ts: existing suites updated for the cost recorder's hosted-key argumentcheck:unused-exports,check:test-patterns,check:source-conventions,check:comment-hygiene,check:utils,check:explicit-any,check:file-names,check:boundaries,check:client-boundary,check:tool-registry-boundary; type-check and full audits in CIChecklist
test-auditauthoring gate)