When the client clock is ahead of the server, user message IDs (generated
client-side) sort after assistant message IDs (generated server-side).
This broke the prompt loop exit check and the UI message pairing logic.
- Extract shouldExitLoop() into a pure function that uses parentID matching
instead of relying on ID ordering
- Extract findAssistantMessages() with forward+backward scan to handle
messages sorted out of expected order due to clock skew
- Remove debug console.log statements added during investigation
- Add tests for both extracted functions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>