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)
{
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,16 +402,22 @@ 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()) {
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);
connect(m_stateProc, &QProcess::readyReadStandardOutput, this, &Ollie9pClient::onStateReadyRead);