feat: restart a session's agent in place#25
Merged
Conversation
There was no way to recycle a wedged or stale agent without losing the
session: stop + dispatch creates a new identity and drops the provider
conversation.
Add Service.Restart: stop the running backend session (soft close, the
existing HUP-TERM-KILL escalation, record kept), then resume it under
the same name - same id, label, store record, and the provider's resume
args (claude/omp/opencode -c and equivalents) so the agent picks its
conversation back up. A session that is already stopped simply resumes
(idempotent). Surfaces:
- TUI: the Ctrl+X confirm dialog gains an `r` answer
("y / restart r / N"), with the same id-snapshot semantics as stop
(F29) so a refresh reorder cannot retarget it
- CLI: `uam restart <id>`
Known limits, accepted: the emulator scrollback resets (new host) and an
attached client sees "session ended" and re-attaches; hermes has no
resume mechanism, so its restart re-sends the original prompt - the same
behavior its resume always had.
The host's deferred listener Close unlinked the unix socket path when the process exited - 50ms AFTER the kill response had signalled `cleaned`. A replacement host created in that window (exactly what restart does) had its freshly-bound socket deleted out from under it, leaving a running but unreachable session: state file present, no socket, every dial failing with "session is not running". Close the listener while the path is still ours - before signalling cleaned - so the unlink lands on the old socket and the path is free by the time Kill returns. Established connections (the kill responder) are unaffected; the deferred Close becomes a no-op. Pinned by an end-to-end regression test that kills and immediately recreates a session under the same name, then asserts the replacement still answers after the old host has fully exited.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Feature
Restart a session's agent in place — recycle a wedged or stale agent without losing the session's identity or the provider conversation.
Service.Restart: stop the running backend session (soft close, existing HUP→TERM→KILL escalation, record kept) → resume under the same name: same id, label, store record, provider resume args (claude/omp/opencode -c, …). Already-stopped sessions simply resume (idempotent).Ctrl+Xconfirm dialog gains anranswer — "Stop and remove name? y / restart r / N" — with stop's F29 id-snapshot semantics (refresh reorders can't retarget it).uam restart <id>.Host bug exposed and fixed (second commit)
Restart's rapid kill→recreate-same-name exposed a latent #22 bug: the old host's deferred listener Close unlinked the socket path ~50ms after Kill had returned, deleting the replacement host's freshly-bound socket — a running but unreachable session ("session is not running" on every dial, state file present, socket missing). Fixed by closing the listener before signalling
cleaned, while the path is still the old host's. Pinned by an e2e regression test (kill → recreate same name → old host fully exits → socket must still answer) that reproduced the bug deterministically.Known limits (accepted)
Test plan
4 new tests (service live-restart + idempotent-stopped, TUI confirm
rafter reorder, CLI verb) + the socket regression test; full suite +-racegreen; vet/lint/gosec/govulncheck clean; help + README updated.