Skip to content

improvement(media): record a hosted-key auth failure when fal refuses Sim's account - #9593

Merged
waleedlatif1 merged 2 commits into
stagingfrom
improvement/fal-hosted-key-failure-metric
Nov 3, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
improvement/fal-hosted-key-failure-metric

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Mothership's generate_audio and generate_video call fal through runFalQueue on Sim's hosted keys (getFalApiKey). They don't go through the tool executor, so they never wrote the Sim/HostedKey series the executor tools write. If fal refused the account (a revoked key, or a lock for an exhausted balance), every generation failed, and the only trace was an ERROR log line nothing alerts on.

Now, when the submit gets a 401, 402 or 403, it records one Failed point with Provider=falai, Tool=<generate_audio|generate_video> and Reason=auth. That is the same metric and reason the executor records through classifyHostedKeyFailure. The existing hosted-key dashboard picks it up, and one alarm on Reason = 'auth' would cover fal as well as every executor hosted key.

A 422 or any other input rejection records nothing, so a bad prompt can't look like an account problem. The request and the error message are unchanged.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: observability

Testing

  • lib/media/falai-hosted-key-metrics.test.ts drives runFalQueue against a stubbed fal submit and captures what PutMetricData sends. Only the CloudWatch SDK is mocked; the real metrics buffer and flush run.
    • A 403 "locked" or a 401 sends one Failed point with Reason=auth.
    • A 422 sends none.
  • Red check: with the status guard disabled, the 403 and 401 cases fail. With 422 added to the refusal set, the 422 case fails.
  • bun run --cwd apps/sim test lib/media passes (66 tests). Biome, check:test-patterns, check:comment-hygiene and check:explicit-any pass.

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)

… Sim's account

Mothership's generate_audio and generate_video call fal on Sim's hosted keys
outside the tool executor, so a refused account (revoked key, or a lock for an
exhausted balance) only reached logs. The submit path now records a
Sim/HostedKey Failed point with reason auth on a 401, 402 or 403, the same
series the hosted-key dashboard already plots for executor tools, so an
alarm on that reason covers fal too.
@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs Ready Ready Preview Nov 3, 2026 2:40am 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.

All reported issues were addressed across 5 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 Resolved
@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no blocking issues remain.

Summary

Records hosted fal submit failures for 401, 402, and 403 responses in the existing Sim/HostedKey metrics.

  • Fal.ai account refusals now show up as hosted-key auth failures.

Reviews (2) · Last reviewed commit: "improvement(media): label fal auth failu..." · Reviewed by Greptile

Comment thread apps/sim/lib/media/falai.ts Resolved
…use the shared env-flags mock

getFalApiKey now returns the env var its key came from, so a refused key in the
numbered pool is named on the metric. The metrics module reads isHosted on each
call instead of copying it at import, and the test sets it through the central
env-flags mock under fake timers.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@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 7 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 260de05 into staging Nov 3, 2026
81 checks passed
@waleedlatif1
waleedlatif1 deleted the improvement/fal-hosted-key-failure-metric branch November 3, 2026 03:45

This branch was successfully deployed

1 active deployment
Preview — 79870522 Deployed Nov 3, 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