From 374349622e283791fb45ebc2ee7dd5296071f39c Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Sat, 1 Aug 2026 18:27:55 +0200 Subject: [PATCH] gui: stop state stream when session is killed; don't restart if session gone --- gui/ollie9pclient.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) 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);