Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
complexity-mediumComplexity: medium (board points 5-8)priority-p2Importanttheme-reliabilityTheme: Reliabilitytype-bugBug fix
Description
Summary
Agent containers develop excessive CPU usage (50%+ each) after running for several days. The agent-server.py process gets stuck in a futex spin loop, causing thread contention. Restarting the affected containers immediately resolves the issue.
Component
Agent Runtime / agent-server.py
Priority
P2 (workaround: restart containers)
Error
# strace output showing 100% time spent on futex with ~50% errors
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00 0.061633 32 1897 948 futex
0.00 0.000002 2 1 1 restart_syscall
------ ----------- ----------- --------- --------- ----------------
100.00 0.061635 32 1898 949 total
Location
- File:
src/agent-base/agent-server.py - Function/Class: Unknown - likely in async polling or thread pool logic
Root Cause
Unknown. The futex spin pattern (1897 calls with 948 errors in 5 seconds) suggests:
- Thread pool exhaustion with busy-wait fallback
- Accumulated orphaned async tasks
- Memory/connection leak causing GC pressure
- Race condition in the polling loop
The issue develops over time (2-6 days of uptime) and affects multiple containers simultaneously.
Reproduction Steps
- Deploy agents with scheduled tasks (runs every 2-6 hours)
- Let containers run for 2-6 days without restart
- Observe CPU usage gradually increasing
- Use
strace -p <pid> -cto confirm futex spin loop - Restart container to resolve
Suggested Fix
Investigation needed. Potential areas to examine:
- Thread pool management - Check for thread leaks or exhaustion
- Async task cleanup - Ensure completed/failed tasks are properly cleaned up
- Connection pooling - Check HTTP client connections aren't accumulating
- Polling backoff - Verify exponential backoff on repeated failures (e.g., 404s for operator-queue.json)
# Potential issue: polling loop without proper backoff
# If the loop doesn't sleep properly on failure, it could spin
# Current (suspected):
while True:
response = await fetch_operator_queue() # Returns 404
# No delay on failure → spins
# Should be:
while True:
response = await fetch_operator_queue()
if response.status == 404:
await asyncio.sleep(5) # Backoff on missing fileEnvironment
- Trinity version:
be35c64 - Docker version: 24.x
- OS: Ubuntu 22.04
- Container uptime when issue manifests: 2-6 days
Observed Behavior
- 7 agent containers simultaneously consuming 50%+ CPU each (~350% total)
- System load average: 8.5+ on 4-core system
- Container logs show repeated polling for
operator-queue.json(404) andchat/session(200) - No active executions running at the time
- Zombie claude processes present in some containers
Related
- Affected file:
src/agent-base/agent-server.py - May relate to operator queue polling logic (OPS-001)
Metadata
Metadata
Assignees
Labels
complexity-mediumComplexity: medium (board points 5-8)priority-p2Importanttheme-reliabilityTheme: Reliabilitytype-bugBug fix
Activity
dolho commentedon May 12, 2026
PR #807 ships defensible accumulator-leak hardening + a
/healthdiagnostics block. It does not claim to close this — root cause is still unproven.What shipped:
gemini_runtimeper-callThreadPoolExecutor→ module-level singleton (mirrorsclaude_code.py:63).state.conversation_historyFIFO-bounded (default 1000, override viaAGENT_HISTORY_LIMIT)./healthnow exposesthread_count,asyncio_task_count,running_executions, history size/limit. Next repro = onecurl, not strace.Why this stays open:
pthread_cond_timedwaitactivity — could be thread-pool, asyncio internals, anyio thread limiter, or leaked daemon reader threads from the subprocess teardown path. Without instrumented data from a live affected container, the culprit is speculation.Ask: if anyone hits 50%+ CPU on agent-server again, capture
curl http://<agent>:8000/healthover time (look for monotonic growth in any diagnostics field) plusstrace -p <pid> -cfor 5s, then drop the data here.fix(agent-server): bound accumulators + /health diagnostics (#333 har…
fix(agent-server): bound accumulators + /health diagnostics (#333 har…
docs(orchestration): execution-bug meta-analysis + target-arch result…
vybe commentedon Jun 9, 2026
Closing during 2026-06-09 reprioritization as stale/likely-irrelevant — filed 2026-04-14, never reproduced, and the agent-server execution path has changed substantially since (headless drain/finalize hardening #1025, heartbeat loop #307, stall-watchdog). Reopen with a fresh repro if a long-uptime futex spin recurs.
docs(target-arch): v2 — reframe side-effect handling to retry-with-tr…
docs(target-arch): v2 — reframe side-effect handling to retry-with-tr…