1
0

fix: restore real-time chat responses via WebSocket (#98)

The chat WebSocket return path was broken by two bugs that prevented
Timmy's responses from appearing in the live chat feed:

1. Frontend checked msg.type instead of msg.event for 'timmy_response'
   events — the WSEvent dataclass uses 'event' as the field name.
2. Frontend accessed msg.response instead of msg.data.response — the
   response payload is nested in the data field.

Additional fixes:
- Queue acknowledgment ("Message queued...") no longer logged as an
  agent message in chat history; the real response is logged by the
  task processor when it completes, eliminating duplicate messages.
- Chat message template now carries data-task-id so the WS handler
  can find and replace the placeholder with the actual response.
- appendMessage() uses DOM APIs (textContent) instead of innerHTML
  for safer content insertion before markdown rendering.
- Fixed chat_message.html script targeting when queue-status div is
  present between the agent message and the inline script.

https://claude.ai/code/session_011cJfexqBBuGhSRQU8qwKcR

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Alexander Whitestone
2026-02-28 20:22:47 -05:00
committed by GitHub
parent d4acaefee9
commit 2e92838033
5 changed files with 68 additions and 19 deletions

View File

@@ -316,13 +316,16 @@ async def chat_timmy(request: Request, message: str = Form(...)):
logger.error("Failed to queue chat message: %s", exc)
error_text = f"Failed to queue message: {exc}"
# Log to message history (for context, even though async)
# Log user message to history. For chat_response tasks the real agent
# reply is logged by the task processor when it completes, so we only
# log the queue acknowledgment for explicit task_request commands.
message_log.append(role="user", content=message, timestamp=timestamp)
if response_text is not None:
if task_info and response_text is not None:
# Explicit task queue command — the acknowledgment IS the response
message_log.append(role="agent", content=response_text, timestamp=timestamp)
else:
elif error_text:
message_log.append(
role="error", content=error_text or "Unknown error", timestamp=timestamp
role="error", content=error_text, timestamp=timestamp
)
return templates.TemplateResponse(