gui: stop state stream when session is killed; don't restart if session gone

This commit is contained in:
Levi Neely 2026-08-01 18:27:55 +02:00
parent 363b2e95ed
commit 374349622e
1 changed files with 18 additions and 6 deletions

View File

@ -163,6 +163,12 @@ bool Ollie9pClient::kill()
bool Ollie9pClient::killSession(const QString &sessionId) bool Ollie9pClient::killSession(const QString &sessionId)
{ {
if (sessionId.isEmpty()) return false; 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"; QString path = "session/" + sessionId + "/ctl";
QProcess proc; QProcess proc;
proc.start(ninepBin(), {"-a", serverAddr(), "write", path}); proc.start(ninepBin(), {"-a", serverAddr(), "write", path});
@ -396,15 +402,21 @@ void Ollie9pClient::startChatStream()
void Ollie9pClient::startStateStream() void Ollie9pClient::startStateStream()
{ {
if (m_stateProc) return; 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 // Re-discover agent ID — directory may have been renamed
QByteArray out = run9p({"ls", "session/" + m_activeSessionId + "/agent"}); QByteArray out = run9p({"ls", "session/" + m_activeSessionId + "/agent"});
QString agents = QString::fromUtf8(out).trimmed(); QString agents = QString::fromUtf8(out).trimmed();
if (!agents.isEmpty()) { if (agents.isEmpty()) {
QString newId = agents.split('\n').first().trimmed(); // Session or agent directory gone — don't start
if (newId != m_agentId) { return;
m_agentId = newId; }
emit activeAgentIdChanged(); QString newId = agents.split('\n').first().trimmed();
} if (newId != m_agentId) {
m_agentId = newId;
emit activeAgentIdChanged();
} }
m_stateProc = new QProcess(this); m_stateProc = new QProcess(this);