Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
backendBackend Task (python)enhancementNew feature or requestintelligenceLayer: Summaries, insights, action itemsp3Priority: Backlog (score <14)
Description
Context
PR #7362 fixed sync pool starvation (#7361) by replacing submit_with_context(postprocess_executor, pipeline) with start_background_task(async_pipeline). This eliminates thread pool slot holding during 60-300s pipelines.
However, in-process asyncio.create_task has known production risks on Cloud Run:
Problem
- Scale-down kills in-flight tasks — Cloud Run sends SIGTERM with 10s grace. A 300s pipeline is lost.
- No persistence — deploy/restart = all in-flight pipelines silently dropped.
- No retry — transient DG/LLM failures = permanent failure.
- CPU throttling — Cloud Run may throttle CPU after HTTP response unless
--no-cpu-throttlingis set. - No cross-instance backpressure — 25 instances × 12 concurrency = 300 slots with no global coordination.
Proposal
Move sync pipelines (and other long-running background work) to an async-native Redis-backed task queue:
| Option | Pros | Cons |
|---|---|---|
| arq | Async-native, lightweight, established | Maintenance-mode, polling-based (~500ms latency) |
| SAQ | Async-native, event-based (<5ms), built-in web UI, actively maintained | Smaller ecosystem |
| Dramatiq | Reliable delivery, simpler than Celery | Less async-native |
Recommended: arq or SAQ — both are async-native and fit the existing FastAPI/asyncio stack. SAQ has lower dispatch latency and a monitoring UI.
Architecture
FastAPI handler → validate → write job record → enqueue to Redis → return 202
↓
Worker process(es)
↓
async pipeline (decode → VAD → STT → LLM)
each step: await run_blocking(pool, fn)
- Pipelines must be idempotent (Redis redelivery on worker crash)
- Job status already tracked in Firestore (
sync_jobscollection) — no new state store needed - Workers can scale independently from API instances
References
- Python asyncio docs: strong-reference set + done_callback pattern
- CPython issue #104091:
create_taskfire-and-forget considered bad practice - Cloud Run CPU throttling: blog post
- FastAPI docs: recommends Celery/arq for heavy background work
- aiohttp: recommends
aiojobsover barecreate_task
Acceptance Criteria
- Choose arq vs SAQ (spike: deploy both with a test pipeline, compare latency + ops)
- Redis instance provisioned (or reuse existing cache Redis)
- Sync pipeline runs as queue worker task with retry/backoff
- Job status updates continue to Firestore (existing polling API unchanged)
- Graceful shutdown: worker drains in-flight tasks before exit
- Monitoring: queue depth, worker count, task duration metrics
- No regression in sync v2 latency (P50/P90/P99)
- Cloud Run scale-down no longer loses in-flight pipelines
Metadata
Metadata
Assignees
Labels
backendBackend Task (python)enhancementNew feature or requestintelligenceLayer: Summaries, insights, action itemsp3Priority: Backlog (score <14)
Activity
beastoin commentedon Jun 10, 2026
Closing as not planned per CTO directive (2026-06-10).
by AI for @beastoin