mirror of
https://github.com/davidkaya/aryx.git
synced 2026-07-27 23:18:46 +02:00
The sidecar's fire-and-forget event handler pattern (invokeRunTurnHandler) causes events to arrive out of order: message-complete and status:idle can arrive before all message-delta events have been emitted. Additionally, deltas from multiple messages (thinking, response, sub-agent) were naively concatenated into a single string, producing garbled output. Replace the single-string accumulation with a proper message tracking model (Map<messageId, TrackedMessage>) that mirrors the main app's SessionRecord.messages approach: - Track each message independently by messageId - Use message-complete event's content field as the authoritative final text, replacing any garbled intermediate streaming state - Mark messages as finalized on message-complete to skip late arriving deltas that would corrupt the final content - Derive display from the last non-thinking message's content - Only transition to 'complete' when all tracked messages are not-pending AND at least one non-thinking message has content, preventing premature completion from setup/init events Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>