You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Malformed SSE chunk drops already-streamed text from history #62
`GenericProvider._stream` (`pycodeloop/providers/generic.py:397`) does `chunk = json.loads(payload)` with no `try/except`. If an OpenAI-compatible endpoint sends a truncated/corrupt `data: ` line mid-stream (network blip, proxy cutting the body, etc.), that `json.loads` raises.
Trace
By that point, `on_delta(...)` (lines 413-424) has already fired for every prior chunk — those `chat/textDelta` notifications already reached the client and rendered in the UI. But the exception propagates up through `Agent._complete`; since it's not `TimeoutError`/`ConnectionError` it isn't retried, the turn fails, and `session.add_assistant(...)` is never called. The text the user already saw on screen never enters the persisted session — reloading the session shows the conversation without that reply.
Fix
Wrap the malformed-chunk case so streaming degrades gracefully instead of losing already-shown text — e.g. catch the JSON decode error, stop consuming the stream, and still persist whatever text/tool-calls were accumulated so far (similar to how a clean `stop_reason` is handled), rather than letting the exception discard everything.
Activity
🪲 BUG-#62: Don't let a trailing malformed chunk clobber a clean finis…
❤️ TEST-#62: Cover finish_reason precedence over trailing malformed c…