The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(slack): replace a rewritten native-stream final in place instead of re-posting
kshitijk4poord5bddd7f007f
diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.pyindex 3ade2bad86b..1fc9774003a 100644--- a/plugins/platforms/slack/adapter.py+++ b/plugins/platforms/slack/adapter.py@@ -2622,11 +2622,17 @@ class SlackAdapter(BasePlatformAdapter):kind, delta = self._stream_relation(stream.get("sent", ""), text)if kind == "unrelated":if md.get("notify"):- # A turn-final that does not continue the stream (the model rewrote its answer):- # close the stale stream on what is visible so no live-typing indicator hangs,- # then let send() post the real final.+ # A turn-final that does not continue the stream (the model rewrote its answer,+ # e.g. mrkdwn conversion turned ``*Done:*`` into ``_Done:_``): close the stale+ # stream, then replace its content in place so the thread holds ONE answer.+ # Only when the in-place update fails does send() post the real final.self._active_streams.pop(key, None)- await self._seal_stream(chat_id, stream)+ if await self._seal_stream(chat_id, stream) and text.strip():+ replaced = await self.edit_message(+ chat_id, stream["ts"], text, finalize=True, metadata=metadata)+ if replaced.success:+ await self.stop_typing(chat_id, metadata)+ return SendResult(success=True, message_id=stream["ts"])return Noneif kind == "extends" and len(delta) > self.MAX_MESSAGE_LENGTH:# Tail too large for one append: close the stream on what is visible and let thediff --git a/tests/gateway/test_slack_native_streaming.py b/tests/gateway/test_slack_native_streaming.pyindex eed333fac46..730c916bf5b 100644--- a/tests/gateway/test_slack_native_streaming.py+++ b/tests/gateway/test_slack_native_streaming.py@@ -430,14 +430,25 @@ class TestSendFinalization:assert not _open_streams(adapter)@pytest.mark.asyncio- async def test_rewritten_turn_final_seals_stale_stream_then_posts(self):- """A turn-final (notify=True) that no longer continues the stream."""+ async def test_rewritten_turn_final_replaces_stream_in_place(self):+ """A mrkdwn-rewritten turn-final (notify=True) replaces the sealed stream; no 2nd post."""+ adapter, client = _make_adapter()+ await adapter.send_draft("D1", 7, "*Done:* all good", metadata=META)+ result = await adapter.send("D1", "_Done:_ all good", metadata=dict(META, notify=True))+ assert result.success+ client.chat_stopStream.assert_awaited_once()+ client.chat_update.assert_awaited()+ assert client.chat_update.await_args.kwargs["ts"] == result.message_id+ client.chat_postMessage.assert_not_awaited()+ assert not _open_streams(adapter)++ @pytest.mark.asyncio+ async def test_rewritten_turn_final_posts_when_update_fails(self):adapter, client = _make_adapter()await adapter.send_draft("D1", 7, "Draft answer that got rewritten", metadata=META)+ client.chat_update = AsyncMock(side_effect=Exception("update failed"))result = await adapter.send("D1", "Completely new answer", metadata=dict(META, notify=True))assert result.success- client.chat_stopStream.assert_awaited_once()- assert "markdown_text" not in client.chat_stopStream.await_args.kwargsclient.chat_postMessage.assert_awaited_once()assert not _open_streams(adapter)