Skip to content

Fix: Enforce fail-fast output_dir validation with argparse and OS W_O…#2753

Open
gagandhakrey wants to merge 1 commit into
openai:mainfrom
gagandhakrey:fix-output-dir-validation
Open

Fix: Enforce fail-fast output_dir validation with argparse and OS W_O…#2753
gagandhakrey wants to merge 1 commit into
openai:mainfrom
gagandhakrey:fix-output-dir-validation

Conversation

@gagandhakrey

@gagandhakrey gagandhakrey commented Mar 31, 2026

Copy link
Copy Markdown

Problem
Currently, Whisper does not eagerly validate if the destination --output_dir provided by the user is valid, accessible, or capable of being created. Because directory creation (os.makedirs) and file writing operations execute lazily deep within the pipeline, passing an invalid destination causes the application to:

Load multiple gigabytes of models into memory unnecessarily.
In the case of API consumers, successfully finish an entire 10+ minute ML transcription process only to immediately crash and lose all generated data with a massive Python stack trace (FileNotFoundError or PermissionError) right as it attempts to save the subtitle files.

Solution
This PR strictly enforces "fail-fast" behavior for output configuration to protect against wasted compute time and poor CLI UX.

Key Changes:

(CLI) Native Argparse Validation: Created a valid_output_dir type boundary inside whisper/transcribe.py.
argparse now safely intercepts the os.makedirs() step during argument parsing.
If creation fails or write-permissions are missing, the CLI exits instantly before touching torch, providing a clean POSIX-standard whisper: error: argument --output_dir/-o output rather than an unhandled traceback.
(API) Robust Access Bitmasking: Updated whisper/utils.py:ResultWriter to validate upon instantiation. It strictly validates both os.W_OK | os.X_OK, which guarantees the running process genuinely has traversing and writing permissions on Unix/Linux file systems before consumers initiate heavy tasks.

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