Problem
When using claude-agent-acp (v0.22.2) with weixin-acp, every other message returns empty text. The response text exists in message.result but is never forwarded to the client via agent_message_chunk.
Debug findings
Adding logging to the result handler reveals:
[debug] result: subtype=success is_error=false result="**3**。" output_tokens=0 promptReplayed=true
The answer is correct (**3**) but output_tokens=0 and no agent_message_chunk events were emitted before the result. The client receives [no text].
Root Cause
When Claude Code SDK returns a cached or short response, it skips streaming and puts the text directly in message.result with output_tokens=0. The current code in acp-agent.js only emits text via stream_event → streamEventToAcpNotifications, so if no stream events occur, the client gets nothing.
Suggested Fix
In the result / success handler, add a fallback to emit the result text as an agent_message_chunk when output_tokens === 0 but message.result is non-empty:
case "success": {
// ... existing checks ...
// Fallback: emit result text if no stream chunks were sent
if (message.result && message.usage.output_tokens === 0) {
await this.client.sessionUpdate({
sessionId: params.sessionId,
update: {
sessionUpdate: "agent_message_chunk",
content: { type: "text", text: message.result },
},
});
}
return { stopReason: "end_turn", usage };
}
Environment
Related
wong2/weixin-agent-sdk#13
Problem
When using
claude-agent-acp(v0.22.2) withweixin-acp, every other message returns empty text. The response text exists inmessage.resultbut is never forwarded to the client viaagent_message_chunk.Debug findings
Adding logging to the
resulthandler reveals:The answer is correct (
**3**) butoutput_tokens=0and noagent_message_chunkevents were emitted before theresult. The client receives[no text].Root Cause
When Claude Code SDK returns a cached or short response, it skips streaming and puts the text directly in
message.resultwithoutput_tokens=0. The current code inacp-agent.jsonly emits text viastream_event→streamEventToAcpNotifications, so if no stream events occur, the client gets nothing.Suggested Fix
In the
result/successhandler, add a fallback to emit the result text as anagent_message_chunkwhenoutput_tokens === 0butmessage.resultis non-empty:Environment
claude-agent-acp: 0.22.2@anthropic-ai/claude-code: 2.1.81weixin-acp(https://github.com/wong2/weixin-agent-sdk)Related
wong2/weixin-agent-sdk#13