Repository navigation
Description
Summary
When Claude Code emits a user message whose content field is a plain string (not an array), process_stream_line() in the agent-server crashes with AttributeError: 'str' object has no attribute 'get'. This exits the stdout reader thread early. Claude keeps running and writes output to the pipe, but nobody reads it. The final {\"type\":\"result\"} JSON is lost when the execution drains, producing a 502 "no result message" error on every affected execution.
Component
Agent Runtime — docker/base-image/agent_server/services/claude_code.py
Priority
P0 — every execution fails if the initial task prompt triggers this path (consistently reproducible)
Error
ERROR: [Headless Task] Error reading stdout: 'str' object has no attribute 'get'
ERROR: [Headless Task] Execution completed without a result message after 0 tool calls / 0 turns (raw_messages=5).
Location
- File:
docker/base-image/agent_server/services/claude_code.py - Lines:
process_stream_line()(~line 222) andparse_stream_json_output()(~line 399) - Pattern: Both functions iterate over
message.get("content", [])without anisinstanceguard
Root Cause
Claude Code's stream-json format allows message.content to be either a list of content blocks or a plain string (the initial user task message uses a string). The code assumes it is always a list:
message_content = message.get("content", [])
for content_block in message_content: # iterates over chars if content is a string
block_type = content_block.get("type") # AttributeError: 'str' has no attribute 'get'The process_stream_line() call is made outside the inner except json.JSONDecodeError block, so the AttributeError propagates to the outer except Exception handler in read_stdout(), which logs the error and returns — silently exiting the reader thread.
Reproduction Steps
- Create an agent and trigger any execution where the task prompt is a direct string (standard scheduled/manual tasks)
- The first
{\"type\":\"user\"}stream line from Claude Code will havecontentas a string process_stream_line()crashes immediately- Execution is recorded as 502 / "no result message"
Suggested Fix
Add an isinstance guard before iterating content in both process_stream_line() and parse_stream_json_output():
message_content = message.get("content", [])
if not isinstance(message_content, list):
message_content = []
for content_block in message_content:
block_type = content_block.get("type")
# ...This matches the Claude API spec where content can be a string or array.
Environment
- Trinity version:
f199383 - Affected:
docker/base-image/agent_server/services/claude_code.py
Related
- Same pattern exists at two locations in the same file (
process_stream_lineandparse_stream_json_output) - The outer reader function
read_stdout()silently swallows the exception and exits, making this failure mode difficult to diagnose without checking logs
Activity
vybe commentedon Apr 29, 2026
Duplicate of fix already merged in #542/#543 (commit 415017f, Apr 28). The
isinstance(content_block, dict)guard is in the current codebase at bothparse_stream_json_output(line 225) andprocess_stream_line(line 404). The symptom persists only because the base image hasn't been rebuilt since f199383. Closing — action needed is an image rebuild, not a code fix.