Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-fal-failed-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/ai-fal': patch
---

fix: handle FAILED queue status from fal.ai to prevent infinite polling

Added `FAILED` to `FalQueueStatus` type and mapped it to `'failed'` status. Changed the default case in status mapping from `'processing'` to `'failed'` so unknown statuses don't cause infinite polling. Error details from the fal response are now surfaced in `VideoStatusResult.error`.
2 changes: 1 addition & 1 deletion packages/typescript/ai-fal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"video-generation"
],
"dependencies": {
"@fal-ai/client": "^1.9.1"
"@fal-ai/client": "^1.9.4"
},
"devDependencies": {
"@tanstack/ai": "workspace:*",
Expand Down
8 changes: 6 additions & 2 deletions packages/typescript/ai-fal/src/adapters/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import type {
} from '../model-meta'
import type { FalClientConfig } from '../utils'

type FalQueueStatus = 'IN_QUEUE' | 'IN_PROGRESS' | 'COMPLETED'
type FalQueueStatus = 'IN_QUEUE' | 'IN_PROGRESS' | 'COMPLETED' | 'FAILED'

interface FalStatusResponse {
status: FalQueueStatus
queue_position?: number
logs?: Array<{ message: string }>
error?: string
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

interface FalVideoResultData {
Expand All @@ -42,8 +43,10 @@ function mapFalStatusToVideoStatus(
return 'processing'
case 'COMPLETED':
return 'completed'
case 'FAILED':
return 'failed'
default:
return 'processing'
return 'failed'
}
}

Expand Down Expand Up @@ -110,6 +113,7 @@ export class FalVideoAdapter<TModel extends FalModel> extends BaseVideoAdapter<
statusResponse.queue_position != null
? Math.max(0, 100 - statusResponse.queue_position * 10)
: undefined,
error: statusResponse.error,
}
}

Expand Down
26 changes: 26 additions & 0 deletions packages/typescript/ai-fal/tests/video-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,32 @@ describe('Fal Video Adapter', () => {

expect(result.status).toBe('completed')
})

it('returns failed status with error for failed jobs', async () => {
mockQueueStatus.mockResolvedValueOnce({
status: 'FAILED',
error: 'Validation error: invalid input',
})

const adapter = createAdapter()

const result = await adapter.getVideoStatus('job-failed')

expect(result.status).toBe('failed')
expect(result.error).toBe('Validation error: invalid input')
})

it('returns failed status for unknown statuses', async () => {
mockQueueStatus.mockResolvedValueOnce({
status: 'UNKNOWN_STATUS',
})

const adapter = createAdapter()

const result = await adapter.getVideoStatus('job-unknown')

expect(result.status).toBe('failed')
})
})

describe('getVideoUrl', () => {
Expand Down
Loading
Loading