Skip to content

fix(podcasts): guard stream when audio missing and share object store volume#1500

Merged
CREDO23 merged 8 commits into
MODSetter:mainfrom
CREDO23:fix/podcast-stream-missing-audio
Jun 16, 2026
Merged

fix(podcasts): guard stream when audio missing and share object store volume#1500
CREDO23 merged 8 commits into
MODSetter:mainfrom
CREDO23:fix/podcast-stream-missing-audio

Conversation

@CREDO23

@CREDO23 CREDO23 commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Guard authenticated and public podcast /stream endpoints with audio_exists() so a missing object returns 404/409 instead of an unhandled FileNotFoundError mid-stream (fixes [BUG] Podcast streaming fails when MP3 file is missing #1498).
  • Mount a shared persistent object_store volume on backend and celery_worker so the default local storage backend works across split containers.

Test plan

  • pytest tests/integration/podcasts/test_streaming.py tests/integration/podcasts/test_public_stream.py
  • pytest tests/integration/podcasts/ (45 passed)
  • Deploy with updated compose and verify podcast audio survives worker restart
  • Confirm existing prod deployments recreate containers to pick up the new volume

High-level PR Summary

This PR fixes two podcast streaming issues: it adds guards to the authenticated and public /stream endpoints to check if audio files exist before streaming (returning 404 for missing objects and 409 for in-flight podcasts instead of crashing with unhandled FileNotFoundError), and it configures a shared persistent object_store volume in Docker Compose so that audio files stored by the Celery worker are accessible to the backend API across separate containers.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/app/podcasts/storage.py
2 surfsense_backend/tests/integration/podcasts/conftest.py
3 surfsense_backend/app/podcasts/api/routes.py
4 surfsense_backend/app/routes/public_chat_routes.py
5 surfsense_backend/tests/integration/podcasts/test_streaming.py
6 surfsense_backend/tests/integration/podcasts/test_public_stream.py
7 docker/docker-compose.yml
8 docker/docker-compose.dev.yml

Need help? Join our Discord

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced podcast audio streaming error responses: 404 when audio is unavailable, 409 when still processing.
  • Infrastructure

    • Configured persistent volumes for podcast object storage, ensuring data durability across container restarts.

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

@CREDO23 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@CREDO23 CREDO23 changed the base branch from dev to main June 16, 2026 18:04
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 171df8e9-8145-4025-ba28-21492d2ab2d1

📥 Commits

Reviewing files that changed from the base of the PR and between 3e53931 and a7be41d.

📒 Files selected for processing (8)
  • docker/docker-compose.dev.yml
  • docker/docker-compose.yml
  • surfsense_backend/app/podcasts/api/routes.py
  • surfsense_backend/app/podcasts/storage.py
  • surfsense_backend/app/routes/public_chat_routes.py
  • surfsense_backend/tests/integration/podcasts/conftest.py
  • surfsense_backend/tests/integration/podcasts/test_public_stream.py
  • surfsense_backend/tests/integration/podcasts/test_streaming.py

📝 Walkthrough

Walkthrough

A persistent Docker volume (object_store) is added to both Compose files, mounting /app/.local_object_store for backend and celery_worker. An audio_exists helper is introduced in storage.py and wired into stream_podcast (routes.py) and stream_public_podcast (public_chat_routes.py) so missing audio returns 404 and in-flight podcasts return 409. Integration tests are updated to cover both new status codes.

Changes

Podcast streaming bug fix

Layer / File(s) Summary
Persistent object store volume
docker/docker-compose.yml, docker/docker-compose.dev.yml
Adds object_store volume mounts at /app/.local_object_store and FILE_STORAGE_LOCAL_PATH env var to backend and celery_worker services in both Compose files; declares the named top-level volumes (surfsense-object-store, surfsense-dev-object-store).
audio_exists helper and streaming route guards
surfsense_backend/app/podcasts/storage.py, surfsense_backend/app/podcasts/api/routes.py, surfsense_backend/app/routes/public_chat_routes.py
Adds async def audio_exists(podcast) -> bool to storage.py. stream_podcast calls it before streaming (404 if missing) and splits the no-audio error into 404 for terminal podcasts and 409 for in-flight ones. stream_public_podcast performs its own backend.exists(storage_key) check and returns 404 if the object is absent.
Integration tests for 404/409 outcomes
surfsense_backend/tests/integration/podcasts/conftest.py, surfsense_backend/tests/integration/podcasts/test_streaming.py, surfsense_backend/tests/integration/podcasts/test_public_stream.py
Extends FakeStorageBackend with exists; adds test_stream_409_while_in_flight; replaces the old no-audio 404 test with test_stream_404_when_object_missing; adds test_public_stream_404_when_object_missing.

Sequence Diagram

sequenceDiagram
  participant Client
  participant stream_podcast
  participant audio_exists
  participant StorageBackend

  Client->>stream_podcast: GET /podcasts/{id}/stream
  stream_podcast->>audio_exists: audio_exists(podcast)
  audio_exists->>StorageBackend: exists(storage_key)
  StorageBackend-->>audio_exists: bool
  alt storage object missing
    audio_exists-->>stream_podcast: False
    stream_podcast-->>Client: 404 Podcast audio not found
  else podcast status is non-terminal / in-flight
    stream_podcast-->>Client: 409 Podcast audio is not ready yet
  else audio present
    stream_podcast->>StorageBackend: open_stream(storage_key)
    StorageBackend-->>stream_podcast: audio bytes
    stream_podcast-->>Client: 200 StreamingResponse
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, hop through the object store,
No FileNotFoundError anymore!
A 404 or 409 — quite polite,
The volume is mounted, the path is right.
The rabbit checked the key before the stream,
Now missing MP3s won't crash the dream! 🎙️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the two main objectives: guarding streams when audio is missing and configuring a shared object store volume in Docker Compose.
Linked Issues check ✅ Passed All coding requirements from issue #1498 are met: the PR implements guard logic in streaming endpoints to check audio file existence and return appropriate status codes (404 for missing, 409 for in-flight), adds the audio_exists helper function, and configures persistent storage volume mounting.
Out of Scope Changes check ✅ Passed All code changes are directly aligned with issue #1498 requirements: stream guard logic, storage helper function, Docker Compose volume configuration, and corresponding test updates. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@CREDO23 CREDO23 changed the base branch from main to dev June 16, 2026 18:06
@CREDO23 CREDO23 changed the base branch from dev to main June 16, 2026 18:06
@CREDO23 CREDO23 changed the base branch from main to dev June 16, 2026 18:07
@CREDO23 CREDO23 force-pushed the fix/podcast-stream-missing-audio branch from 87e6026 to a7be41d Compare June 16, 2026 18:09
@CREDO23 CREDO23 changed the base branch from dev to main June 16, 2026 18:09
@CREDO23 CREDO23 merged commit 683a827 into MODSetter:main Jun 16, 2026
9 of 11 checks passed
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.

[BUG] Podcast streaming fails when MP3 file is missing

1 participant