Repository navigation
fix(backend): unblock 202 fast path from storage_executor saturation - #7372
Conversation
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 SummaryThis hotfix addresses a production bottleneck where the 202 fast-path response time ballooned to 48s because
Confidence Score: 4/5Safe 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
Sequence DiagramsequenceDiagram
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
Reviews (1): Last reviewed commit: "fix(backend): unblock 202 fast path from..." | Re-trigger Greptile |
| 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) |
There was a problem hiding this comment.
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]>
|
lgtm |
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 saturatedstorage_executor(queue depth peaked at 301), this blocked the 202 response — P50 went from 0.1s to 48.3s.Fix (2 changes):
routers/sync.py): Fast-path file save now usessync_executor(12w, idle during file-save phase) instead ofstorage_executorutils/executors.py):storage_executorbumped 16 → 32 workers to reduce background queue depthCloses #7361
Changed paths
routers/sync.py:sync_local_files_v2utils/executors.py:storage_executorCLAUDE.mdtests/unit/test_sync_v2.pyTest evidence
172 tests pass (test_sync_v2.py + test_executors.py):
test_v2_fast_path_uses_sync_executor— assertsrun_blocking(sync_executorin fast path, assertsstorage_executorNOT usedtest_executor_worker_counts— assertsstorage_executor._max_workers == 32Live test (L1 + L2):
beast omi dev boot-check --full: import clean + uvicorn health OKstorage_executor.max_workers=32,sync_executor.max_workers=12sync_executor, notstorage_executorPre-existing failure:
test_process_conversation_usage_context.pyfails on main (upstreamfind_similar_action_itemsimport 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
by AI for @beastoin