Skip to content

fix(media): bill a completed fal generation even when a Stop ends its download - #9106

Merged
waleedlatif1 merged 4 commits into
stagingfrom
fix/fal-cost-after-abort
Oct 16, 2026
Merged

waleedlatif1 merged 4 commits into
stagingfrom
fix/fal-cost-after-abort

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • A Stop or deadline that landed after fal completed a generation (during the media download or the cost lookup) threw before recordServiceCost ran, so a generation fal charged for was never billed. The cost lookup and the download both took the caller's abort signal, and the cost was recorded only after both.
  • generateFalAudio / generateFalVideo now take an onCost recorder and bill through it once fal has returned the result, before the download that a Stop can still end. The mothership audio/video tools wire onCost to recordServiceCost inside the meter scope and no longer record afterwards, so each generation is billed exactly once.
  • The cost lookup no longer takes the caller's signal. getFalAICostMetadata now has its own 10s bound (via the existing withinDeadline), and past it the fallback floor is billed instead of nothing. A Stop during the lookup waits at most that bound, then the generation fails without downloading.
  • No change for requests stopped before fal completes them (cancelled, nothing billed) or for completions whose result fetch fails.

Type of Change

  • Bug fix

Testing

  • lib/media/falai.test.ts runs the real queue, pricing and download path with stubbed fal HTTP. It covers a Stop during the download after completion (audio and video, billed once), a Stop during the cost lookup (lookup finishes, billed once, no download), a lookup that hangs (floor billed once at the bound), the success path (billed exactly once), and a Stop before completion (cancelled, nothing billed). The first four fail on staging.
  • model-boundaries.test.ts: the tools bill once through onCost even when the generation then fails.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 16, 2026 3:17am UTC

Request Review

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 8 files

Confidence score: 4/5

  • In falai-video.ts, a completed Fal request can incur a charge without recording it if the output URL is missing or unrecognized. Record the cost immediately after runFalQueue, before validating the URL.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/media/falai-video.ts">

<violation number="1" location="apps/sim/lib/media/falai-video.ts:185">
P2: A completed request with a missing or unrecognized output URL throws before `recordFalCost` runs, leaving Fal’s charge unrecorded. Record the cost immediately after `runFalQueue`, before validating the media URL.</violation>
</file>

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/media/falai-video.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR records completed fal audio and video costs before reading or downloading media. Cost lookups have their own 10-second limit and return a fallback charge when that limit expires.

  • Completed Fal.ai media runs are billed before downloads.
  • Fal.ai cost lookups stop after ten seconds and use a price floor.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Fal returns generation result] --> B[Look up cost with independent deadline]
  B --> C{Cost available?}
  C -->|Yes| D[Record cost once]
  C -->|Lookup fails or expires| E[Choose fallback charge]
  E --> D
  D --> F[Read media URL and download]
  F --> G[Return media or stop]
Loading

Reviews (3) · Last reviewed commit: "fix(media): bill the fal floor when the ..." · Reviewed by Greptile

Comment thread apps/sim/lib/media/falai.test.ts Outdated
Comment thread apps/sim/lib/media/falai.test.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 8 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/media/falai.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 9 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit f3cb7a1 into staging Oct 16, 2026
53 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/fal-cost-after-abort branch October 16, 2026 03:49

This branch was previously deployed

1 inactive deployment
Preview — 60201638 Deployed Oct 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant