Skip to content

bug: Agent execution failures show 'Unknown error' instead of actual error from Claude Code #58

Closed

Description

@vybe

Summary

When agent executions fail due to Claude Code errors (e.g. billing errors, auth failures), the backend logs Unknown error and returns a 500 to the caller. The actual error message from Claude Code's stream-json output (e.g. Credit balance is too low, Invalid API key) is not captured or surfaced. This makes debugging execution failures difficult without manual SSH into the agent container.

Component

Agent Runtime / Headless Task Execution

Priority

P2

Error

What the backend logs:

ERROR:agent_server.services.claude_code:[Headless Task] Task {id} failed (exit 1): Unknown error
INFO:     172.28.0.5:xxxxx - "POST /api/task HTTP/1.1" 500 Internal Server Error

What Claude Code actually returns (visible only when running manually inside the container):

{"type":"result","subtype":"success","is_error":true,"result":"Credit balance is too low","error":"billing_error"}

Or in auth failure case:

{"type":"result","subtype":"success","is_error":true,"result":"Invalid API key · Fix external API key","error":"authentication_failed"}

Root Cause

The agent server's claude_code service parses Claude Code's stream-json output but does not extract the error message from failed executions. When Claude Code exits with code 1, the final result event contains the actual error in the result and error fields, but the agent server discards this and reports "Unknown error".

Reproduction Steps

  1. Set an invalid or zero-balance ANTHROPIC_API_KEY on any agent
  2. Send a task to the agent (via UI, API, or schedule)
  3. Execution fails in ~2 seconds
  4. Check backend/agent logs — only "Unknown error" is shown
  5. Manually run claude --print --verbose --output-format stream-json "hello" inside the agent container to see the real error

Expected Behavior

  • The execution log should capture and display the actual error from Claude Code (billing_error, authentication_failed, etc.)
  • The execution record in the database should store the error message
  • The UI/API should show the real error instead of "Unknown error"
  • The backend scheduler log should include the error detail: Task execution failed: Credit balance is too low instead of Task execution failed: Unknown error

Suggested Fix

Parse the final result event from Claude Code's stream-json output. When is_error is true, extract the result (human-readable message) and error (error type) fields and use them in the failure log and execution record.

Environment

  • Trinity version: a453e32
  • Claude Code version: 2.1.62

Related

  • Agent server claude_code service (headless task execution)
  • Scheduler service (reports same "Unknown error" for scheduled tasks)

Activity

  1. vybe commented on Mar 21, 2026

    @vybe
    ContributorAuthor

    Closing — fixed by commit 7d37316. _diagnose_exit_failure() now provides meaningful error messages with exit codes, rate limit detection, and actionable hints instead of generic 'Unknown error'.

  2. added
    complexity-low
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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