gui: refresh on agent disconnect instead of showing red

When an agent connection drops (killed or server restart), refresh
the session model from idx rather than immediately marking the
session as disconnected. This avoids a transient red indicator
when an agent is killed but the session is still alive.

The daemon disconnect handler (server down) still correctly marks
everything as disconnected.
This commit is contained in:
Levi Neely 2026-08-03 11:31:02 +02:00
parent 5e22545b2e
commit 379afd81bf
1 changed files with 8 additions and 1 deletions

View File

@ -189,6 +189,7 @@ void Ollie9pClient::setAgentConnected(const QString &key, bool connected)
const bool cached = m_agentConnected.value(key, false);
m_agentConnected[key] = connected;
bool modelChanged = false;
bool foundInModel = false;
// Update the in-memory model without starting another round of probes.
for (QVariant &value : m_sessions) {
QVariantMap session = value.toMap();
@ -196,6 +197,7 @@ void Ollie9pClient::setAgentConnected(const QString &key, bool connected)
for (QVariant &agentValue : agents) {
QVariantMap agent = agentValue.toMap();
if (agentKey(session["id"].toString(), agent["id"].toString()) == key) {
foundInModel = true;
if (agent.value("connected").toBool() != connected)
modelChanged = true;
agent["connected"] = connected;
@ -205,6 +207,9 @@ void Ollie9pClient::setAgentConnected(const QString &key, bool connected)
session["agents"] = agents;
value = session;
}
// Ignore stale disconnects for agents no longer in the model (killed).
if (!foundInModel && !connected)
return;
if (cached != connected || modelChanged)
emit sessionsChanged();
}
@ -245,7 +250,9 @@ void Ollie9pClient::reconcileAgentConnections()
}
});
connect(connection, &NinePConnection::disconnected, this, [this, key]() {
setAgentConnected(key, false);
// Agent may have been killed — refresh to get authoritative state
// rather than showing a transient red indicator.
refreshSessions();
});
// Use immutable IDs in path — aliases in the 9P namespace resolve
// these to the correct session/agent regardless of display name.