diff --git a/gui/ollie9pclient.cpp b/gui/ollie9pclient.cpp index a706426..60a5a6d 100644 --- a/gui/ollie9pclient.cpp +++ b/gui/ollie9pclient.cpp @@ -330,6 +330,44 @@ void Ollie9pClient::refreshSessions() reconcileAgentConnections(); emit sessionsChanged(); + // Check if the currently active session/agent still exist + if (!m_activeSessionId.isEmpty()) { + bool sessionFound = false; + bool agentFound = false; + for (const QVariant &v : std::as_const(m_sessions)) { + const QVariantMap session = v.toMap(); + if (session.value("id").toString() == m_activeSessionId) { + sessionFound = true; + if (!m_agentId.isEmpty()) { + for (const QVariant &av : session.value("agents").toList()) { + if (av.toMap().value("id").toString() == m_agentId) { + agentFound = true; + break; + } + } + } + break; + } + } + if (!sessionFound) { + // Session was killed — clear both and stop streams + stopStreams(); + m_activeSessionId.clear(); + m_agentId.clear(); + m_activeState = "idle"; + emit activeSessionIdChanged(); + emit activeAgentIdChanged(); + emit activeStateChanged(); + } else if (!m_agentId.isEmpty() && !agentFound) { + // Agent was killed but session still exists — clear agent only + stopStreams(); + m_agentId.clear(); + m_activeState = "idle"; + emit activeAgentIdChanged(); + emit activeStateChanged(); + } + } + // Auto-select first session and its first agent if none active if (m_activeSessionId.isEmpty() && !m_sessions.isEmpty()) { const QVariantMap firstSession = m_sessions.first().toMap();