# MED-001: Enhanced Typing Indicator Implementation ## Overview Enhanced Discord typing indicator to provide continuous visual feedback during long-running Claude operations (30s-5min). ## Problem Discord automatically cancels typing indicators after 10 seconds, but Claude operations can take much longer. Users had no feedback that the bot was still working on their request. ## Solution Implemented persistent typing loop that re-triggers every 8 seconds (before Discord's 10s timeout) until Claude responds. ## Implementation ### New Method: _maintain_typing Continuously loops typing indicator until stop event is set: - Enters typing state via async context manager - Waits for stop_event with 8-second timeout - On timeout, loops to re-enter typing - On stop event, exits immediately - Handles exceptions gracefully without crashing ### Updated _handle_claude_request - Creates asyncio.Event() to control typing lifecycle - Starts _maintain_typing as background task - Stops typing in finally block (ensures cleanup on success, error, or timeout) ## Testing Added 8 comprehensive tests: 1. **test_typing_starts_on_request_begin** - Verifies typing starts immediately 2. **test_typing_loops_for_long_operations** - Verifies 20s operation triggers 2+ typing cycles 3. **test_typing_stops_on_successful_completion** - No hang on success 4. **test_typing_stops_on_error** - Typing cleaned up on Claude error 5. **test_typing_stops_on_timeout** - Typing cleaned up on asyncio.TimeoutError 6. **test_typing_stops_on_exception** - Typing cleaned up on unexpected exception 7. **test_maintain_typing_loops_until_stopped** - Direct method test (12s = 2+ cycles) 8. **test_maintain_typing_stops_immediately_on_event** - Event stop < 2s (not full 8s wait) **All tests passing (27/27)** ## UX Improvements - Users now see continuous typing indicator for operations >10s - Clear visual feedback that bot is working - No false "bot stopped responding" confusion - Typing automatically stops when response arrives ## Edge Cases Handled - Claude timeout → typing stops, error shown - Claude error → typing stops, error shown - Bot restart mid-request → typing naturally stops - Multiple messages queued → HIGH-004 locks handle sequencing ## Files Changed - `/opt/projects/claude-coordinator/claude_coordinator/bot.py` - Added `_maintain_typing` method (22 lines) - Enhanced `_handle_claude_request` with typing task management - `/opt/projects/claude-coordinator/tests/test_bot.py` - Added 8 new test cases - Removed old single typing test (superseded by new comprehensive tests) ## Deployment No breaking changes. Existing functionality preserved. Safe to deploy immediately. ```bash # Tests pass pytest tests/test_bot.py -v # 27 passed # Restart bot to apply changes pkill -f "python -m claude_coordinator.bot" python -m claude_coordinator.bot & ``` ## Future Enhancements (Optional - Not Implemented) Could add status messages for very long operations (>30s): - "⏳ Still processing..." after 30s - "⏳ Still processing (1m elapsed)..." every 30s - Delete status message when response arrives This was considered but not implemented to keep the enhancement focused on the core typing indicator improvement.