fix: clear active agent when killed, stop statewait loop
refreshSessions now checks if the active session/agent still exist after updating the list. If the agent was killed, clears m_agentId and stops streams. The statewait guard will then return false, stopping the loop.
This commit is contained in:
parent
414143955f
commit
0c47e1163a
|
|
@ -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();
|
||||
|
|
|
|||
Reference in New Issue