Skip to content

fix(backend): unblock 202 fast path from storage_executor saturation - #7372

Merged
beastoin merged 2 commits into
BasedHardware:mainfrom
beastoin:fix/storage-executor-sizing
May 18, 2026
Merged

beastoin merged 2 commits into
BasedHardware:mainfrom
beastoin:fix/storage-executor-sizing

Conversation

@beastoin

@beastoin beastoin commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Hotfix for 202 fast-path latency regression discovered post-deploy of PR #7362 (executor bulkhead).

Root cause: The sync v2 fast path calls run_blocking(storage_executor, _retrieve_file_paths_v2, ...) to save uploaded files before returning 202. When background pipeline work saturated storage_executor (queue depth peaked at 301), this blocked the 202 response — P50 went from 0.1s to 48.3s.

Fix (2 changes):

  1. Pool separation (routers/sync.py): Fast-path file save now uses sync_executor (12w, idle during file-save phase) instead of storage_executor
  2. Pool sizing (utils/executors.py): storage_executor bumped 16 → 32 workers to reduce background queue depth

Closes #7361

Changed paths

Path ID Changed path Description
P1 routers/sync.py:sync_local_files_v2 Fast-path pool switch: storage→sync executor
P2 utils/executors.py:storage_executor max_workers 16 → 32
P3 CLAUDE.md Docs: pool size update (non-executable)
P4 tests/unit/test_sync_v2.py New test assertions (test-only)

Test evidence

172 tests pass (test_sync_v2.py + test_executors.py):

  • test_v2_fast_path_uses_sync_executor — asserts run_blocking(sync_executor in fast path, asserts storage_executor NOT used
  • test_executor_worker_counts — asserts storage_executor._max_workers == 32
  • All 148 existing sync v2 tests + 24 executor tests pass

Live test (L1 + L2):

  • beast omi dev boot-check --full: import clean + uvicorn health OK
  • Runtime pool verification: storage_executor.max_workers=32, sync_executor.max_workers=12
  • Source verification: fast path uses sync_executor, not storage_executor

Pre-existing failure: test_process_conversation_usage_context.py fails on main (upstream find_similar_action_items import error) — not related to this PR.

Codex review

PR_APPROVED_LGTM — no blocking issues. Reviewer confirmed pool separation correctly addresses the saturation cascade and thread safety is maintained.

Risk

  • Low: Only changes which thread pool runs the file save — no API contract, no behavior change
  • Reviewer note: sync_executor could theoretically saturate under heavy concurrent VAD/STT work, but background pipeline is capped/chunked. A dedicated fast-path upload executor would be the next hardening step if metrics show sync queueing.

by AI for @beastoin

Post-deploy monitoring showed storage_executor (16 workers) at 100%
utilization with queue depth 301. The 202 fast-path file save was
queued behind background pipeline cleanup/GCS work, causing P50 48s
on the new revision.

Two fixes:
- Move fast-path file save from storage_executor to sync_executor
  (75% util, zero queue — local disk I/O completes in ms)
- Bump storage_executor 16 → 32 workers (I/O-bound work, safe to
  increase — handles GCS uploads, audio precaching, file cleanup)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@greptile-apps

greptile-apps Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This hotfix addresses a production bottleneck where the 202 fast-path response time ballooned to 48s because storage_executor (16 workers) was saturated with background pipeline cleanup and GCS tasks, causing incoming file saves to queue behind 300+ pending storage operations.

  • routers/sync.py: Redirects _retrieve_file_paths_v2 (local disk write only) from the saturated storage_executor to sync_executor, which had available headroom at the time of the incident.
  • utils/executors.py: Doubles storage_executor from 16 to 32 workers to relieve GCS/cleanup saturation, with a matching docs update in CLAUDE.md.

Confidence Score: 4/5

Safe to merge as a hotfix; changes are small, well-motivated by production monitoring data, and carry no risk of data loss or correctness regressions.

The file-save and pool-size changes are correct and directly address the observed bottleneck. The one concern is that sync_executor now serves dual duty for both fast-path file saves and compute-intensive pipeline work (VAD, STT, decode), so if pipeline load grows it could recreate the same queuing problem in a different pool. The headroom is currently 3 of 12 slots, which is thin for a high-traffic service.

backend/routers/sync.py — the reassignment of _retrieve_file_paths_v2 to sync_executor is the only change worth a second look.

Important Files Changed

Filename Overview
backend/routers/sync.py Fast-path file save moved from storage_executor to sync_executor; correct and effective for the immediate bottleneck, but sync_executor now has dual responsibility for pipeline and fast-path I/O, creating potential future contention.
backend/utils/executors.py storage_executor max_workers bumped from 16 to 32 — straightforward scaling for I/O-bound GCS work; no logic changes.
backend/CLAUDE.md Docs updated to reflect new storage_executor worker count (16 → 32); consistent with the code change.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Handler as sync_local_files_v2
    participant SE as sync_executor (12w)
    participant DE as db_executor
    participant BG as Background Task
    participant StorE as storage_executor (32w)

    Client->>Handler: POST /v2/sync-local-files
    Handler->>SE: _retrieve_file_paths_v2 (local disk write)
    SE-->>Handler: paths[]
    Handler->>DE: create_sync_job
    DE-->>Handler: ok
    Handler->>BG: start_background_task(_run_full_pipeline_background_async)
    Handler-->>Client: "202 Accepted {job_id}"

    BG->>SE: decode_files_to_wav
    SE-->>BG: wav_paths
    BG->>SE: _run_vad_bg (per file)
    SE-->>BG: segmented_paths
    BG->>SE: _process_one_segment (per segment)
    SE-->>BG: results
    BG->>StorE: _cleanup_files / shutil.rmtree
    StorE-->>BG: done
Loading

Reviews (1): Last reviewed commit: "fix(backend): unblock 202 fast path from..." | Re-trigger Greptile

Comment thread backend/routers/sync.py
paths = await run_blocking(storage_executor, _retrieve_file_paths_v2, files, uid, job_id)
# Use sync_executor, NOT storage_executor — storage is saturated with
# background pipeline cleanup/GCS work and would queue the 202 response.
paths = await run_blocking(sync_executor, _retrieve_file_paths_v2, files, uid, job_id)

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.

P2 Fast-path and pipeline work now share the same pool

sync_executor (12 workers) is already used for the compute-intensive background pipeline — decode_files_to_wav, _run_vad_bg, and _process_one_segment. At high concurrency those pipeline tasks fill the pool, and fast-path file saves would queue behind them — reproducing the original problem in a different pool. The PR description notes 75% utilization (≈ 9 of 12 slots busy) with zero queue depth right now, so headroom is only 3 slots. A dedicated small executor (e.g. 4 workers) for fast-path local disk writes, or a direct asyncio.to_thread call (since these are simple shutil.copyfileobj writes without pool-sharing concerns), would avoid the coupling entirely and make the fast path immune to future pipeline growth.

…tions (BasedHardware#7372)

Tester found 2 coverage gaps:
- Fast-path file save must use sync_executor, not storage_executor
- storage_executor._max_workers must be 32

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@beastoin
beastoin merged commit 14d5f83 into BasedHardware:main May 18, 2026
1 check passed
@beastoin

Copy link
Copy Markdown
Collaborator Author

lgtm

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.

fix(backend-sync): 202 accept path regression from executor bulkhead PR #7343

1 participant