Bug: Agent responses disappear from chat while remaining in activity panel
Bug Description
After some time, agent (leader) responses disappear from the chat panel. Only user messages remain visible. However, the activity panel still shows the full history including agent responses.
Steps to Reproduce
- Create and start a team
- Send messages to the team via the chat panel
- Agent responds (visible initially in both chat and activity)
- Wait some time (possibly after page navigation or refresh)
- Return to the team monitor page
- Chat only shows user messages — agent responses are gone
- Activity panel still shows all events including the agent responses
Expected Behavior
ALL messages (user + agent) should persist in the chat view at all times. Per project requirements: "When entering a chat, ALL previous messages MUST load immediately."
Investigation Notes
The chat uses messagesApi.list() which filters by message_type IN ('user_message', 'leader_response'). Possible causes:
- Message type mismatch: Agent responses may be stored with a different
message_type(e.g.,task_result,activity_event, oragent_response) instead ofleader_response - Payload structure: The leader's response may be wrapped in a NATS envelope that changes its message_type
- Frontend filtering: The chat filter may be too restrictive, excluding valid agent responses
- Cursor pagination bug: The
beforecursor may skip messages if timestamps collide
Evidence from Activity Panel
The activity shows task_result messages from the leader with full response content:
[task_result]
claude-code → user
23:14:17
{
"status": "completed",
"result": "Zero referencias a Tenerife en el proyecto..."
}
This task_result type is NOT in the chat filter (user_message, leader_response), so it won't appear in chat.
Likely Fix
Update chat message retrieval to include task_result type (or ensure leader responses are stored as leader_response). The root cause needs investigation in:
- Backend:
handlers_chat.go— how leader responses are stored - Backend: NATS bridge — how leader messages are relayed and their type is set
- Frontend:
TeamMonitorPage.tsx— chat message filtering logic
Acceptance Criteria
- [ ] Agent responses persist in chat across page loads
- [ ] All message types that represent agent-to-user communication appear in chat
- [ ] Full chat history loads immediately when entering the team monitor
- [ ] No regression: activity panel continues working correctly
- [ ] E2E test validates chat persistence
Fixed in b71db31 (backend) and 2fc6ecb (frontend). Leader responses were stored as task_result instead of leader_response, causing them to be filtered out of the chat endpoint. Added backward compatibility for existing records.