From b3432cd76fb837fe7bb526359894b1ce858cf37d Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Thu, 13 Nov 2025 00:56:41 +0100 Subject: [PATCH] fix: Clean resources after finish request --- ChatView/ClientInterface.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ChatView/ClientInterface.cpp b/ChatView/ClientInterface.cpp index 21f0e39..185fbc8 100644 --- a/ChatView/ClientInterface.cpp +++ b/ChatView/ClientInterface.cpp @@ -337,12 +337,18 @@ void ClientInterface::handleFullResponse(const QString &requestId, const QString LOG_MESSAGE(QString("Some edits for request %1 were not auto-applied: %2") .arg(requestId, applyError)); } - - m_activeRequests.erase(it); - m_accumulatedResponses.remove(requestId); - LOG_MESSAGE("Message completed. Final response for message " + ctx.originalRequest["id"].toString() + ": " + finalText); + LOG_MESSAGE( + "Message completed. Final response for message " + ctx.originalRequest["id"].toString() + + ": " + finalText); emit messageReceivedCompletely(); + + if (it != m_activeRequests.end()) { + m_activeRequests.erase(it); + } + if (m_accumulatedResponses.contains(requestId)) { + m_accumulatedResponses.remove(requestId); + } } void ClientInterface::handleRequestFailed(const QString &requestId, const QString &error) @@ -354,8 +360,12 @@ void ClientInterface::handleRequestFailed(const QString &requestId, const QStrin LOG_MESSAGE(QString("Chat request %1 failed: %2").arg(requestId, error)); emit errorOccurred(error); - m_activeRequests.erase(it); - m_accumulatedResponses.remove(requestId); + if (it != m_activeRequests.end()) { + m_activeRequests.erase(it); + } + if (m_accumulatedResponses.contains(requestId)) { + m_accumulatedResponses.remove(requestId); + } } void ClientInterface::handleCleanAccumulatedData(const QString &requestId)