Repository navigation
fix(tui): follow a daemon that restarted on a new port - #5318
Conversation
|
Verdict: Approve After a daemon restart lands on a new port, the TUI's Cancel, Respond, Confirm and similar calls now find the restarted daemon instead of failing with "connection refused" until the user relaunches. The retry only fires when the connection never opened, so nothing can run twice, and a test pins that. When no replacement daemon is recorded, the original error still reaches the user unchanged. I found no blocking issues. Real-world evidenceN/A: no evidence bundle was produced for this run. The change is in the TUI's daemon client, which this lane doesn't drive. The verdict rests on static review plus the new Go tests, which reproduce the restart against a fake daemon. A live check would be: start a session, restart 🔍 Technical detailsIssues
Strengths
|
|
Live check passed: after a daemon restart on a new port, turning on full access in the TUI reached the restarted daemon on this branch, while the same step on main failed with "connection refused". How it ran: the real TUI binary (one built from main, one from this branch merged with #5319) drove the installed-binary flagship over the daemon transport, with isolated
Also pushed since the review: a test for the "instance.json names a dead replacement" path, and wording that fits when only the token changed. 🔍 Technical details
|
|
Review follow-up: the restart case is now modelled the way the real daemon behaves. Run-scoped calls are no longer replayed; they say the restart ended the agent session.
My earlier live comment showed full access reaching the restarted daemon. That relied on the fake keeping the sidecar's state across the restart, which the real daemon never does, so that result no longer applies. |
|
Second review round: a daemon that restarts on the same port is handled like one on a new port. It shows up as a rotated token (401), not a refused connection, and that path now takes the same step: run-scoped calls get the restart message, and relayed calls ensure the agent first. Covered by
Separately, a commit by mistake added local preview entries to |
|
Third review round: the same-port token-refresh path already returns
|
After a daemon restart on a new port, Cancel, Respond and Confirm failed with "connection refused": the TUI re-read instance.json only after a 401, and a dead port never answers 401. - When a call cannot connect, the client re-reads instance.json once and, if it names a different daemon that passes the usual checks, sends the call there. A failed dial reached no server, so nothing can run twice; a call that reached a daemon and then lost its connection is never replayed. - If instance.json names nothing new, the original error stands; if it names a daemon that fails its checks, both reasons are reported. - The SSE client keeps the instance that answered, so later calls go straight to the new daemon.
…daemon The message now says instance.json was rewritten rather than naming "another daemon", which read oddly when only the token changed.
…g it to a daemon that never had it The real daemon stops its sidecars on shutdown and the next one starts fresh, so replaying Cancel, Respond, Confirm or a full-access toggle to the restarted daemon only got back a 503 "no running sidecar". - Calls about a run or session (cancel, answer, confirmation, follow-up, permission decision, full access) are marked run-scoped. When the daemon behind them restarted, they are not sent; the user is told the restart ended the agent session and to send the message again. - Other relayed calls ensure the agent on the restarted daemon before they are replayed. - A replacement daemon that fails its checks keeps its typed error (%w), so version and stale-instance checks still recognise it. - The log names the dial's own failure; the test fake now has no sidecar after a restart, as the real daemon does.
A daemon that comes back on the same port shows up as a rotated token instead of a refused connection. The 401 path replayed run-scoped calls there unchecked, without ensuring the agent the restarted daemon no longer had. - The dial-failure path and the token-rotation path now share one step: a run-scoped call returns DaemonRestartedError, and a relayed call ensures its agent first. The ensured instance is the one used. - ensureOn runs the agents-floor check that EnsureAgent ran before it, so a replacement too old for the relay is refused before the call. - The preflight rotation fake answers the ensure call the way the real daemon does.
The dropping fake now resets the connection (linger 0) instead of closing it cleanly, the failure a crashed daemon produces. Forcing isDialFailure to true makes the test fail, so it pins the rule.
b7eced9 to
093147b
Compare
Before: after the daemon restarted on a new port, Cancel, Respond, Confirm and the full-access toggle in the TUI failed with "connection refused", which says nothing about what happened. After: the TUI finds the restarted daemon and says plainly that the restart ended the agent session and nothing was sent; the next message starts a fresh session there. A run cannot be carried over, because the daemon stops its sidecars on shutdown and the next one starts fresh. Lands after v0.25.0.
Sending a new message already re-read
instance.json(throughEnsureAgent) before this change. What was broken was every call made against the session the TUI already held.Reproduced by
TestCancelAfterADaemonRestartSaysTheRunEndedandTestDoDoesNotCarryARunScopedCallToARestartedDaemon: on main the first fails with "connection refused", and the second can't compile because main has no way to tell run-scoped calls apart. Both pass here.Test plan
go vet ./...clean;go test -p 1 ./internal/daemon/ ./internal/client/ ./internal/ui/preflight/passesTestDoEnsuresTheAgentBeforeReplayingARelayCallToARestartedDaemon)TestDoNeverReplaysARequestThatReachedTheDaemon)VersionError/StaleErrorin the chain, plus the original failure/full-access confirmafter the restart said "GAIA's daemon restarted, which ended the agent session this belonged to. Nothing was sent", and the restarted daemon received no/bypass. The next message ensured the agent and was answered. Main says "actively refused it".🔍 Technical details
Client.Dore-readsinstance.jsononly on a dial failure (*net.OpErrorwithOp == "dial", reachable through the newRequestError.Unwrap). The new instance goes through the sameverifyandCheckVersionas attach.Request.RunScopedmarks calls about state in a running sidecar. They returnDaemonRestartedErrortogether with the new instance. Other/v1/<agent>/…calls runensureOn(split out ofEnsureAgent, with its agents-floor check) on the new daemon first.TestDoDoesNotCarryARunScopedCallAcrossASamePortRestart).SSEClient.dokeeps whichever instance answered, so the six calls that used to drop it also follow a plain token rotation.