diff --git a/gui/ollie9pclient.cpp b/gui/ollie9pclient.cpp index 70a6492..7b1c565 100644 --- a/gui/ollie9pclient.cpp +++ b/gui/ollie9pclient.cpp @@ -163,6 +163,12 @@ bool Ollie9pClient::kill() bool Ollie9pClient::killSession(const QString &sessionId) { if (sessionId.isEmpty()) return false; + + // If killing the active session, shut down its streams first + if (sessionId == m_activeSessionId) { + stopStreams(); + } + QString path = "session/" + sessionId + "/ctl"; QProcess proc; proc.start(ninepBin(), {"-a", serverAddr(), "write", path}); @@ -396,15 +402,21 @@ void Ollie9pClient::startChatStream() void Ollie9pClient::startStateStream() { if (m_stateProc) return; + + // Check if session still exists before starting + if (m_activeSessionId.isEmpty()) return; + // Re-discover agent ID — directory may have been renamed QByteArray out = run9p({"ls", "session/" + m_activeSessionId + "/agent"}); QString agents = QString::fromUtf8(out).trimmed(); - if (!agents.isEmpty()) { - QString newId = agents.split('\n').first().trimmed(); - if (newId != m_agentId) { - m_agentId = newId; - emit activeAgentIdChanged(); - } + if (agents.isEmpty()) { + // Session or agent directory gone — don't start + return; + } + QString newId = agents.split('\n').first().trimmed(); + if (newId != m_agentId) { + m_agentId = newId; + emit activeAgentIdChanged(); } m_stateProc = new QProcess(this);