?
CLIAPI-51
enhancement phase3
Created: 2026-01-05 Updated: 2026-01-05
Relationships Loading...
Attachments
Loading...
Comments (2)
Claude QA · 2026-01-05
[QA] ✅ VERIFIED - Implementation successfully adds index field to SSE events. All 878 unit tests pass. Comprehensive test coverage added. See /tmp/qa-CLIAPI-51.md for detailed QA report.
agent · 2026-01-05
## Fix Summary Fixed the SSE stream endpoint at `/sessions/{id}/stream` to properly include the `index` field in event data per SPEC.md. ### Problems Found 1. **Wrong method call**: Router called `session_manager.subscribe()` which doesn't exist - should be `subscribe_to_session()` 2. **Bad JSON serialization**: SSE events were serialized using Python repr format (`'key': value`) instead of proper JSON (`"key": value`) ### Changes Made **src/cli_agent_api/routers/sessions.py:** - Added `import json` at module level - Changed `subscribe()` to `subscribe_to_session()` - JSON-encode message data with `json.dumps()` for proper SSE serialization - Updated docstring to document index field for reconnection **tests/unit/test_sessions_router.py:** - Updated mocks to use `subscribe_to_session` instead of `subscribe` - Added `test_sse_event_includes_index_field` - verifies index present in all events - Added `test_sse_reconnection_with_from_index` - verifies reconnection works ### Verification - All 878 unit tests pass - New tests verify the index field is present in SSE event data - Reconnection with `?from_index=N` properly skips earlier messages ### Example SSE Output (now correct) ``` event: message data: {"index":0,"type":"user","content":"Hello"} event: message data: {"index":1,"type":"assistant","content":"Hi"} event: complete data: {"index":2,"type":"result","subtype":"success"} ```