Priority: P1 (High)
Category: Reliability / Background Processing
Issue
TranslationBackgroundService acquires a semaphore permit and then starts untracked Task.Run workers. During shutdown, cancellation can happen between permit acquisition and worker execution. In that case the worker may never reach its finally block and the permit is never released, causing shutdown waits and possible job loss.
Location
src/Chat.Web/Services/TranslationBackgroundService.cs
Risk
- Graceful shutdown can hang until timeout
- In-flight jobs may be dropped or requeued inconsistently
- Semaphore state can become detached from actual worker state
- Service behavior becomes brittle during app recycle or deployment
Proposed Fix
Replace untracked Task.Run fire-and-forget workers with explicit worker tracking or a bounded worker loop that owns semaphore lifetime deterministically.
Suggested implementation direction:
- Maintain a concurrent set of active worker tasks and await them during shutdown
- Acquire and release permits inside the tracked worker lifecycle only
- Avoid passing the host stopping token to
Task.Run as the only worker coordination mechanism
- Add tests that simulate shutdown while jobs are being dequeued
Effort Estimate
2-3 hours
Acceptance Criteria
Reference
Static review finding from architecture and reliability review of src on 2026-05-02
Priority: P1 (High)
Category: Reliability / Background Processing
Issue
TranslationBackgroundServiceacquires a semaphore permit and then starts untrackedTask.Runworkers. During shutdown, cancellation can happen between permit acquisition and worker execution. In that case the worker may never reach itsfinallyblock and the permit is never released, causing shutdown waits and possible job loss.Location
src/Chat.Web/Services/TranslationBackgroundService.csRisk
Proposed Fix
Replace untracked
Task.Runfire-and-forget workers with explicit worker tracking or a bounded worker loop that owns semaphore lifetime deterministically.Suggested implementation direction:
Task.Runas the only worker coordination mechanismEffort Estimate
2-3 hours
Acceptance Criteria
Reference
Static review finding from architecture and reliability review of
srcon 2026-05-02