Skip to content

bug: stale execution cleanup loses original error context — no way to diagnose failure cause #286

Closed

Description

@vybe

Summary

When the cleanup service recovers stale/zombie executions, it replaces the original failure reason with generic messages like "Stale execution — slot TTL expired" or "Execution completed on agent but status not reported — recovered by watchdog." The actual error from Claude Code (e.g., expired token, OOM, crash) is lost, making it impossible for operators to diagnose fleet-wide failures from execution history alone.

Component

Backend / Cleanup Service

Priority

P2

Error

Examples of generic error messages that replace the real cause:

Stale execution — slot TTL expired for agent 'cleon', cleaned by cleanup service
Execution completed on agent but status not reported — recovered by watchdog
Task execution timed out after 3600 seconds

In all these cases, the underlying cause was an expired subscription token, but the operator has to SSH into the instance and grep backend logs to discover that — the execution record itself gives no hint.

Location

  • File: src/backend/services/cleanup_service.py
  • Function: Cleanup cycle / stale execution marking

Root Cause

The cleanup service marks executions as failed with a cleanup-specific error message. It does not attempt to retrieve the last known output or error from the agent container before marking the execution. Any partial output, stderr, or exit code information that existed on the agent is discarded.

Reproduction Steps

  1. Cause an agent execution to fail in a way that doesn't report back cleanly (e.g., expired token causing a hang)
  2. Wait for the cleanup service cycle (5 min interval)
  3. Check execution result via API or MCP (get_execution_result)
  4. Observe: error field contains generic cleanup message, not the actual failure cause
  5. The execution_log field is also null — no transcript preserved

Suggested Fix

When the cleanup service detects a stale execution, before marking it failed:

# 1. Try to retrieve the last output from the agent container
try:
    # Check if agent container has any stderr/stdout from the execution
    agent_output = await get_agent_execution_output(agent_name, execution_id)
    error_message = f"Recovered by cleanup: {agent_output.last_error or 'no output captured'}"
except Exception:
    error_message = "Stale execution — slot TTL expired (no agent output available)"

# 2. Store the combined context
execution.error = error_message

Additionally, consider:

  • Capturing Claude Code's stderr at the agent container level and making it queryable
  • Adding a cleanup_reason field separate from error so both are preserved
  • Logging the original error to a structured log before overwriting with cleanup message

Environment

  • Trinity version: 2798ca9
  • Docker version: 29.3.0
  • OS: Ubuntu (GCP VM)

Related

  • src/backend/services/cleanup_service.py — cleanup cycle logic
  • src/backend/services/task_execution_service.py — execution lifecycle
  • src/backend/services/slot_service.py — slot TTL expiry

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p2type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions