Repository navigation
Description
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
- Cause an agent execution to fail in a way that doesn't report back cleanly (e.g., expired token causing a hang)
- Wait for the cleanup service cycle (5 min interval)
- Check execution result via API or MCP (
get_execution_result) - Observe: error field contains generic cleanup message, not the actual failure cause
- The
execution_logfield 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_messageAdditionally, consider:
- Capturing Claude Code's stderr at the agent container level and making it queryable
- Adding a
cleanup_reasonfield separate fromerrorso 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 logicsrc/backend/services/task_execution_service.py— execution lifecyclesrc/backend/services/slot_service.py— slot TTL expiry
Activity
fix(cleanup): preserve original error context when recovering stale e…
fix(cleanup): preserve original error context when recovering stale e…
docs(planning): mark #286 as shipped in orchestration plan
docs(planning): Sprint A now 4/6 complete
feat(workspace): pick who is in a chat, and start a multi-agent one (…
feat(workspace): the multi-agent chat view (ent#361)
feat(workspace): absorb the Session surface, with continuity parity (…