Skip to content

Commit c4eadc1

Browse files
fix(cli): ag run streaming output hangs — wrong response field names (#3368)
The read endpoint (/v1/sessions/:id/read) returns { messages, status }, not { lines/transcript, status }. The CLI was looking for non-existent fields, so it never received any entries and the stream appeared to hang. Also: - Skip non-text content types (thinking, tool_use, tool_result) in output - Added 'crashed' to terminal status detection - Show statusText when available for better end-of-session messages Fixes: #3368
1 parent 2567ecc commit c4eadc1

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/commands/run.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,18 @@ async function streamOutput(baseUrl: string, sessionId: string, authToken: strin
170170
}
171171

172172
const data = await res.json() as {
173-
lines?: Array<{ text: string; role?: string }>;
174-
transcript?: Array<{ text: string; role?: string }>;
173+
messages?: Array<{ text: string; role?: string; contentType?: string }>;
175174
status?: string;
175+
statusText?: string | null;
176176
};
177177

178-
// Support both `lines` and `transcript` response shapes
179-
const entries = data.lines || data.transcript || [];
178+
// #3368: Read endpoint returns `messages`, not `lines` or `transcript`
179+
const entries = data.messages || [];
180180
if (entries.length > lastLineCount) {
181181
const newEntries = entries.slice(lastLineCount);
182182
for (const entry of newEntries) {
183+
// Skip non-text content types (thinking, tool_use, tool_result, etc.)
184+
if (entry.contentType && entry.contentType !== 'text') continue;
183185
const prefix = entry.role === 'user' ? ' 👤 ' : entry.role === 'assistant' ? ' 🤖 ' : ' ';
184186
writeLine(io.stdout, `${prefix}${entry.text.slice(0, 500)}`);
185187
}
@@ -188,9 +190,9 @@ async function streamOutput(baseUrl: string, sessionId: string, authToken: strin
188190
}
189191

190192
// Check if session is done
191-
if (data.status === 'completed' || data.status === 'error' || data.status === 'killed') {
193+
if (data.status === 'completed' || data.status === 'error' || data.status === 'killed' || data.status === 'crashed') {
192194
writeLine(io.stdout);
193-
writeLine(io.stdout, ` Session ended: ${data.status}`);
195+
writeLine(io.stdout, ` Session ended: ${data.statusText || data.status}`);
194196
break;
195197
}
196198

0 commit comments

Comments
 (0)