Skip to content

fix(media): auto-skip tiny/empty audio files before transcription (#8127)#8388

Merged
steipete merged 5 commits intoopenclaw:mainfrom
Glucksberg:fix/8127-whisper-skip-empty-audio
Mar 2, 2026
Merged

fix(media): auto-skip tiny/empty audio files before transcription (#8127)#8388
steipete merged 5 commits intoopenclaw:mainfrom
Glucksberg:fix/8127-whisper-skip-empty-audio

Conversation

@Glucksberg
Copy link
Contributor

@Glucksberg Glucksberg commented Feb 4, 2026

Fixes #8127

When tiny or empty audio files are sent for transcription, the Whisper API returns unhelpful errors.

Changes:

  • Added MIN_AUDIO_FILE_BYTES = 1024 constant
  • Added "tooSmall" to MediaUnderstandingSkipReason
  • File size guard in both provider path (runProviderEntry) and CLI path (runCliEntry)
  • Files below 1KB are skipped with a descriptive MediaUnderstandingSkipError
  • 3 new tests (tiny file skip, empty file skip, valid file proceeds)
  • Updated existing test fixtures to use buffers above the threshold

Greptile Overview

Greptile Summary

Adds a minimum-audio-size guard (MIN_AUDIO_FILE_BYTES = 1024) so tiny/empty audio attachments are skipped before being sent to transcription providers/CLI, returning a MediaUnderstandingSkipError with new reason tooSmall. Updates existing media-understanding tests to use buffers above the threshold and adds a dedicated test suite covering tiny, empty, and valid audio inputs.

This integrates at the runner layer (runProviderEntry and runCliEntry) so both provider-based transcription and local CLI transcription paths avoid unhelpful upstream errors for near-empty files.

Confidence Score: 4/5

  • This PR is likely safe to merge; the core guard is simple and well-covered by tests.
  • The change is localized (a constant, a new skip reason, and two size checks) and has targeted test coverage for tiny/empty/valid local audio. Remaining concerns are mostly around test robustness/coverage for URL-based attachments rather than runtime correctness.
  • src/media-understanding/runner.skip-tiny-audio.test.ts (assertion robustness), src/media-understanding/apply.test.ts (remote/URL tiny-audio coverage)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +66 to +69
expect(result.outputs).toHaveLength(0);
expect(result.decision.outcome).toBe("skipped");
expect(result.decision.attachments[0]?.attempts[0]?.outcome).toBe("skipped");
expect(result.decision.attachments[0]?.attempts[0]?.reason).toContain("tooSmall");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Optional chaining makes the assertions here non-failing if attachments[0] / attempts[0] is missing.

Right now expect(result.decision.attachments[0]?.attempts[0]?.outcome) will evaluate to undefined if the arrays are empty, which can hide regressions where no attempt is recorded. Consider asserting the array lengths first and then indexing without ?..

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/media-understanding/runner.skip-tiny-audio.test.ts
Line: 66:69

Comment:
[P2] Optional chaining makes the assertions here non-failing if `attachments[0]` / `attempts[0]` is missing.

Right now `expect(result.decision.attachments[0]?.attempts[0]?.outcome)` will evaluate to `undefined` if the arrays are empty, which can hide regressions where no attempt is recorded. Consider asserting the array lengths first and then indexing without `?.`.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a583faf — replaced optional chaining with strict assertions that verify array lengths before indexing.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 4, 2026

Additional Comments (1)

src/media-understanding/apply.test.ts
[P3] apply.test.ts mocks fetchRemoteMedia to always return a 2048-byte buffer (see beforeEach), so the URL-only audio test can’t exercise the new tiny/empty audio skip behavior for remote attachments.

If the intent is to cover #8127 for URL attachments too, add a small-buffer mock in a dedicated test (or override the mock for this test) to assert the decision is skipped with reason tooSmall.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/media-understanding/apply.test.ts
Line: 175:179

Comment:
[P3] `apply.test.ts` mocks `fetchRemoteMedia` to always return a 2048-byte buffer (see beforeEach), so the URL-only audio test can’t exercise the new tiny/empty audio skip behavior for remote attachments.

If the intent is to cover #8127 for URL attachments too, add a small-buffer mock in a dedicated test (or override the mock for this test) to assert the decision is `skipped` with reason `tooSmall`.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@Glucksberg
Copy link
Contributor Author

Fixed in 8e67960e4:

[P2] Optional chaining in test assertions: The assertions at lines 69-71 actually use direct property access, not optional chaining. The preceding toHaveLength(1) check on line 68 ensures attachments[0] exists before the subsequent assertions.

[P3] URL-only audio test: Added a dedicated test "skips URL-only audio when remote file is too small" in apply.test.ts that overrides the fetchRemoteMedia mock with a 100-byte buffer and verifies the transcription provider is never called.

@mudrii

This comment was marked as spam.

Glucksberg and others added 5 commits March 2, 2026 10:56
…cription

Add a minimum file size guard (MIN_AUDIO_FILE_BYTES = 1024) before
sending audio to transcription APIs. Files below this threshold are
almost certainly empty or corrupt and would cause unhelpful errors
from Whisper/Deepgram/Groq providers.

Changes:
- Add 'tooSmall' skip reason to MediaUnderstandingSkipError
- Add MIN_AUDIO_FILE_BYTES constant (1024 bytes) to defaults
- Guard both provider and CLI audio paths in runner.ts
- Add comprehensive tests for tiny, empty, and valid audio files
- Update existing test fixtures to use audio files above threshold
Increase test audio file sizes to meet MIN_AUDIO_FILE_BYTES (1024) threshold
introduced by the skip-empty-audio feature. Fix localPathRoots in skip-tiny-audio
tests so temp files pass path validation. Remove undefined loadApply() call
in apply.test.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm vitest src/media-understanding/apply.test.ts src/media-understanding/runner.skip-tiny-audio.test.ts
  • Land commit: 4740ef3daf0e25ff140f5adb8bcb4a6f305166ab
  • Merge commit: f7b0378

Thanks @Glucksberg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Auto-skip tiny/empty audio files in whisper skills

3 participants