Repository navigation
Description
Summary
Uvicorn workers continue to die intermittently despite upgrading to uvicorn 0.37.0 and setting --timeout-worker-healthcheck 120. Workers are SIGKILL'd every few hours with no traceback or OOM indication, causing in-flight async tasks (scheduled execution launches) to be silently dropped. This results in executions stuck in "running" state with no Claude session ever created.
Component
Backend / Uvicorn Worker Management
Priority
P2
Error
INFO: Waiting for child process [PID]
INFO: Child process [PID] died
(trapped) error reading bcrypt version
No traceback, no OOM, no application-level error logged before the death.
Observed Behavior
With --workers 2 --timeout-worker-healthcheck 120, worker deaths observed at irregular intervals:
| Worker | Died After | Notes |
|---|---|---|
| Worker A | ~4.5h | |
| Worker B | ~1h | |
| Worker C | ~7h | |
| Worker D | ~19.5h | Was handling scheduled execution launch |
| Worker E | ~16h | Was handling scheduled execution launch |
- No container memory limit set
- Container using 1GB / 31GB RAM (3%)
- No kernel OOM killer entries in dmesg
- Workers die silently — only the parent process logs the death
Impact
When a worker dies while handling an async execution launch:
- The execution record is created in the DB with status "running"
- A Redis capacity slot is acquired
- The background task that runs
docker execto start Claude is lost - The execution is stuck forever — no session, no completion, slot held
The scheduler then polls for up to 1 hour before giving up with "Polling deadline exceeded".
Location
- File: Uvicorn process management (external dependency)
- Config:
--workers 2 --timeout-worker-healthcheck 120in backend container CMD
Root Cause
The --timeout-worker-healthcheck 120 raised the threshold but didn't eliminate the problem. Something is still blocking the Python GIL for >120 seconds occasionally, causing the uvicorn parent to SIGKILL the unresponsive worker. Possible causes:
- Long-running synchronous
docker execcalls via the Docker SDK blocking the GIL - SQLite write locks causing contention between the 2 workers
passlib/bcryptoperations (the(trapped) error reading bcrypt versionon restart hints at bcrypt issues)- Synchronous HTTP calls to agent containers during execution launch
Reproduction Steps
- Deploy backend with
--workers 2 --timeout-worker-healthcheck 120 - Run multiple agents with hourly scheduled tasks
- Monitor worker deaths:
docker logs trinity-backend 2>&1 | grep "Child process.*died" - Correlate with stuck executions: query
schedule_executionswherestatus='running' AND claude_session_id IS NULL
Suggested Fix
Options (in order of preference):
Option A: Switch to --workers 1
Eliminates GIL contention between workers entirely. Since async operations (FastAPI) handle concurrency via the event loop, a single worker may be sufficient. This also eliminates SQLite multi-writer issues.
Option B: Increase timeout further
--timeout-worker-healthcheck 300
May just delay the problem rather than fix it.
Option C: Make execution launch fully async
Move the docker exec call to a proper async task queue (or use asyncio.create_subprocess_exec) so it doesn't block the worker's event loop / GIL. This would prevent worker deaths from dropping in-flight execution launches.
Option D: Add execution recovery on worker restart
When a new worker starts (detected via Application startup complete), scan for executions in "running" state with no claude_session_id and either retry or fail them immediately instead of waiting for the polling deadline.
Environment
- Trinity version:
ccf573d - Uvicorn version: 0.37.0
- Docker version: 28.3.3
- OS: Debian GNU/Linux 12 (bookworm)
- Python: 3.11.15
Related
- Previous fix:
--timeout-worker-healthcheck 120(reduced frequency but didn't eliminate) - Issue bug: Executions stuck in 'running' state due to scheduler/backend database split #90 (scheduler/backend database split)
- Downstream impact: Scheduler creates duplicate execution records (skipped + success) for single trigger #91 (APScheduler max_instances skip — see companion issue)
Activity
vybe commentedon Mar 14, 2026
Related: #132 (APScheduler max_instances skip — downstream impact when a stuck execution from this bug blocks the scheduler's polling loop)
vybe commentedon Mar 21, 2026
Closing — resolved by dedicated scheduler service (trinity-scheduler). Scheduled task execution no longer runs in uvicorn workers, eliminating the root cause of worker deaths.