Repository navigation
Description
Summary
The cleanup service's active watchdog incorrectly marks legitimate, within-timeout agent executions as "stale" and kills them. Affected runs are mid-execution (50–66 min elapsed out of a 7200s timeout) with slots that haven't expired (TTL 7500s). The watchdog pings the agent to re-verify, the ping times out (agent is busy / at full slot capacity), and the execution is failed with pending_retry. This is a recurring false-positive: multiple executions on the same agent are consistently killed by this path, never completing normally.
Component
Backend / Cleanup Service / Slot Service
Priority
P1
Error
Backend logs at the time of kill:
WARNING [Slots] Cleaned up 1 stale slots for agent '{agent_name}'
INFO [Cleanup] Failed execution {execution_id} for agent '{agent_name}' (slot reclaimed, agent unreachable during re-verify)
Scheduler poll logs:
ERROR scheduler.service: Background poll: execution {id} failed: Execution completed on agent but status not reported — recovered by watchdog
Secondary symptom — on retry after concurrent-run memory accumulation:
ERROR [TaskExecService] Failed to execute task on {agent}: Execution terminated by SIGKILL after 0 tool calls / 0 turns (exit code -9). Likely cause: schedule/agent timeout exceeded, OOM kill, or operator cancel.
Root Cause
The cleanup service's stale-slot detection is triggering on executions that are legitimately still running, long before their configured timeout_seconds (7200s) or slot TTL (7500s) expire. The re-verify step pings the agent over HTTP; if the agent is at full slot capacity (max_parallel_tasks = 3/3) or under high CPU load, the ping times out, and the watchdog treats the running execution as unrecoverable. The execution is then transitioned to failed/pending_retry.
The stale-slot detection threshold appears to be significantly shorter than the agent's configured execution timeout — observed kills occur at ~50–66 min elapsed time, suggesting a hardcoded or misconfigured staleness window in the cleanup service that does not respect the per-agent timeout_seconds setting.
Reproduction Steps
- Configure an agent with
timeout_seconds=7200(or any value >30 min) andmax_parallel_tasks >= 2 - Start a scheduled execution that runs for >50 minutes (e.g. a long-running Claude Code task)
- Allow concurrent scheduled executions to start while the first is still running (filling slots)
- Observe the cleanup service's 5-minute cycle run
- The running execution(s) are killed with "slot reclaimed, agent unreachable during re-verify" well before
timeout_secondsexpires
Can also reproduce with a single slot (no concurrency): a solo execution running >50 min is killed by the watchdog even without concurrency pressure.
Suggested Fix
The stale-slot detection should respect the per-agent timeout_seconds configuration. A slot should only be considered stale when:
- The slot's TTL has expired, OR
now - execution.started_at > agent.timeout_seconds(execution has exceeded its configured timeout)
The re-verify HTTP ping should also use a generous timeout (e.g. 30–60s) rather than a short one, since agents under heavy load may be slow to respond without being dead. Consider retrying the ping once before declaring unreachable.
Additionally, if the agent is known to be at full slot capacity (all slots occupied), a failed re-verify should be treated with more skepticism — a busy agent is more likely to timeout a health ping than a dead one.
Environment
- Trinity version:
f11ae1b3 - Slot TTL at acquisition: 7500s
- Agent
timeout_seconds: 7200s max_parallel_tasks: 3- Observed kill time: 46–66 min into execution
Related
- Cleanup service:
src/backend/services/cleanup_service.py - Slot service:
src/backend/services/slot_service.py - Feature: Cleanup Service + Active Watchdog (introduced with background cleanup)
- Related:
max_parallel_taskscapacity config (CAPACITY-001) - Related issue: when multiple slots are killed simultaneously, retry executions may encounter OOM (SIGKILL, exit -9, 0 turns) due to memory not being fully released between concurrent runs
Activity
vybe commentedon May 17, 2026
/claim
github-actions commentedon May 17, 2026
Claimed by @vybe. Label
status-in-progressadded.Next steps:
feature/869-<short-slug>Fixes #869docs(feature-flows): sync cleanup-service and parallel-capacity for #869
fix(cleanup): per-slot TTL prevents false-kill of long-running execut…
test(slots): adopt sanctioned _STUBBED_MODULE_NAMES pattern (#871 lin…
test(slots): adopt sanctioned _STUBBED_MODULE_NAMES pattern (#871 lin…
test(slots): fix sys.modules lint regression from #871 (#881)
fix(config): forward SMTP + SendGrid env to backend container (#771) (#…
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).
Release: v0.7.0 (#1319)
fix(canary): stop three false-positive classes drowning the harness (…