Skip to content

bug: Cleanup watchdog falsely kills long-running executions as stale before timeout expires #869

Closed

Description

@vybe

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

  1. Configure an agent with timeout_seconds=7200 (or any value >30 min) and max_parallel_tasks >= 2
  2. Start a scheduled execution that runs for >50 minutes (e.g. a long-running Claude Code task)
  3. Allow concurrent scheduled executions to start while the first is still running (filling slots)
  4. Observe the cleanup service's 5-minute cycle run
  5. The running execution(s) are killed with "slot reclaimed, agent unreachable during re-verify" well before timeout_seconds expires

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:

  1. The slot's TTL has expired, OR
  2. 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_tasks capacity 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

  1. vybe commented on May 17, 2026

    @vybe
    ContributorAuthor

    /claim

  2. added
    status-in-progress
    on May 17, 2026
  3. github-actions commented on May 17, 2026

    @github-actions

    Claimed by @vybe. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/869-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #869
  4. added
    status-in-dev
    and removed
    status-in-progress
    on May 17, 2026
  5. vybe commented on Jun 1, 2026

    @vybe
    ContributorAuthor

    Shipped in v0.6.0 (released via #998).

  6. removed
    status-in-dev
    on Jun 1, 2026
  7. added a commit that references this issue on Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p1type-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions