Skip to content

feat: restart a session's agent in place#25

Merged
aksOps merged 2 commits into
mainfrom
feat/session-restart
Jun 11, 2026
Merged

feat: restart a session's agent in place#25
aksOps merged 2 commits into
mainfrom
feat/session-restart

Conversation

@aksOps

@aksOps aksOps commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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).
  • TUI: the Ctrl+X confirm dialog gains an r answer — "Stop and remove name? y / restart r / N" — with stop's F29 id-snapshot semantics (refresh reorders can't retarget it).
  • CLI: 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)

  • Emulator scrollback resets (new host); an attached client sees "session ended" and re-attaches.
  • hermes has no resume mechanism, so its restart re-sends the original prompt — same behavior as its existing resume.

Test plan

4 new tests (service live-restart + idempotent-stopped, TUI confirm r after reorder, CLI verb) + the socket regression test; full suite + -race green; vet/lint/gosec/govulncheck clean; help + README updated.

aksOps added 2 commits June 11, 2026 07:58
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.
@sonarqubecloud

Copy link
Copy Markdown

@aksOps aksOps merged commit a0b42c5 into main Jun 11, 2026
13 checks passed
@aksOps aksOps deleted the feat/session-restart branch June 11, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant