fix: correct message ordering after task cancellation — v0.50.163 (#883) Fixes the message-ordering glitch from #882: clicking Cancel while the agent is responding could cause a subsequent response to render above the "*Task cancelled.*" marker. Root cause: the cancel handler pushed the marker only to local S.messages without persisting to the server. When the done event fired shortly after and replaced S.messages from server state, the marker disappeared from client state while the next response anchored to the server-authoritative position. Fix has three parts: - Server (cancel_stream): append *Task cancelled.* to session.messages with _error:True + timestamp, then save. _error ensures _sanitize_messages_for_api() strips it from conversation_history on the next agent turn, so the LLM never sees it as a prior assistant turn. Precedent: same flag used for the apperror marker at line 1343. - Client (SSE cancel handler): fetch /api/session instead of pushing locally (same pattern as the done handler). Falls back to local push if the fetch fails. - Tests: fix test window width for cancel handler (1200→dynamic); add two regression tests pinning _error flag and _sanitize invariant. 1941 tests passing. Co-authored-by: piliang <piliang1@jd.com>
78 KiB
78 KiB