Skip to content

feat(daemon): add infer daemon stop and move the session commands to infer sessions - #1968

Merged
edenreich merged 1 commit into
mainfrom
feat/daemon-stop
Nov 24, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/daemon-stop

Conversation

@edenreich

@edenreich edenreich commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The daemon is the process that hosts sessions, not the place to act on them. Yet infer daemon carried workspaces, run, stop and teleport, so infer daemon stop stopped one session, and nothing stopped the daemon itself. Cleaning up a daemon meant reading ~/.infer/run/daemon.pid and killing it by hand, which is how a daemon from a stale build kept running members in the wrong mode during testing of #1963.

Now infer daemon starts and stops the process, the session commands live under infer sessions, and a stop ends everything the daemon runs gracefully.

infer daemon                                     # start it
infer daemon stop                                # stop it, and everything it runs, gracefully
infer sessions workspaces                        # moved from infer daemon, unchanged
infer sessions run|stop|teleport <session-id>    # moved from infer daemon, unchanged

infer daemon stop

  • It stops the daemon this user runs, the one holding the lock on ~/.infer/run/daemon.pid. It sends SIGTERM, waits for the daemon's own shutdown, and kills it if it still runs after a minute.
  • A pid file no daemon holds is left alone. A daemon that crashed leaves its file behind, and that pid may name another process by now, so the pid counts only while the daemon holds the file's lock.
  • Stopping no daemon is not an error. It prints no infer daemon is running and exits 0.
  • It needs no binding, so it also stops a daemon from another build that would refuse a client's hello.
  • infer daemon takes no arguments, so a leftover infer daemon run <id> fails instead of starting a daemon.

infer sessions

workspaces, run, stop and teleport move from cmd/daemon to cmd/sessions unchanged, apart from naming their argument <session-id>. The command tree now mirrors the bounded contexts: the daemon hosts the sessions context, it does not own its verbs.

Everything the daemon runs shuts down gracefully

  • Session workers already did: the daemon sends each an interrupt, closes its stdin, and the worker ends its turn and cleans up.
  • Scheduled, heartbeat and A2A runs and subagents did not. agentheadless.Run started them with exec.CommandContext, whose cancel is a SIGKILL, so a run never got to stop its MCP servers, browser and background shells. process.TerminateOnCancel now sends SIGTERM and gives the run 25 seconds before a kill. infer headless already shuts down on SIGTERM.
  • The scheduler left running jobs behind. Each job ran on context.Background(), so a stop waited 30 seconds and then let the job run on for up to 30 minutes after the daemon exited. The scheduler now cancels its jobs on stop and waits for them.
  • Windows has no SIGTERM, so there infer daemon stop kills the daemon. Its session workers still clean up as their stdin closes, but one-shot runs outlive it. This is marked as a shortcut: on daemon.Stop, to be replaced by a stop frame over the binding once windows needs one.

infer daemon workspaces, run, stop <id> and teleport are gone. Use infer sessions workspaces, run, stop and teleport. There are no deprecated aliases, since keeping them under infer daemon would keep the daemon tied to the session verbs. The docs, the examples' Taskfiles and READMEs, and the chat's error hint use the new commands.

Verification

  • End to end in tmux against the tokenless mock (INFER_GATEWAY_MOCK, an isolated HOME and binding port), with three children of the daemon running: a chat session worker, a room member holding a Write call for approval, and a heartbeat run whose mock turn stalls forever.
    • infer daemon stop printed stopped the infer daemon (pid 98322) and returned in 0.13s, with no infer process left.
    • The daemon log shows every child running its own shutdown (stopping background shell service, stopping job supervisor, shutting down agent containers), the heartbeat run included, the member's pending approval moving to Cancelled, then heartbeat service stopped and daemon stopped.
    • A second infer daemon stop printed no infer daemon is running.
  • TestStopStopsOnlyTheDaemonHoldingThePidFile: no pid file, a pid file no daemon holds (its process is not signalled), and the daemon holding it (stopped, its pid returned).
  • TestStopKillsAProcessThatIgnoresTheRequestOnceGracePasses: a process that traps SIGTERM is killed once the grace passes, not before.
  • TestACancelledRunShutsDownOnItsOwnBeforeAnyKill: a cancelled run gets to run its SIGTERM handler. It fails without the change (lines = ["ready"], killed before the handler ran).
  • TestCommandTopology lists sessions. go test -race for cmd/..., internal/daemon, internal/platform/process, internal/agent/headless and internal/scheduler/..., plus the pre-commit gate.
  • Not run: the Kubernetes teleport examples whose Taskfiles now call infer sessions, which need a cluster. The edit there is the command name only.

Cross-repo impact

… infer sessions

The daemon is the process that hosts sessions, not the place to act on them,
yet infer daemon carried workspaces, run, stop and teleport. So infer daemon
stop stopped one session, and nothing stopped the daemon itself.

infer daemon now starts and stops the process. infer daemon stop sends SIGTERM
to the pid the pid file's lock vouches for, waits for the daemon to shut down,
and kills it if it still runs after a minute. A pid file no daemon holds is
left alone, since its pid may name another process by now. With no daemon
running it says so and exits 0. infer daemon takes no arguments, so a leftover
infer daemon run fails instead of starting a daemon.

The session commands move unchanged to infer sessions workspaces, run, stop and
teleport, which take a <session-id>. infer daemon workspaces, run, stop <id>
and teleport are gone, and the docs and examples use the new commands.

A stop ends everything the daemon runs gracefully. Session workers already
ended their turn and cleaned up. A scheduled, heartbeat or A2A run and a
subagent were killed on cancel, skipping their own shutdown of MCP servers,
browser and background shells, and the scheduler left a running job behind
after 30 seconds. Such a run now gets SIGTERM and 25 seconds before a kill, and
the scheduler cancels its jobs on stop. Windows has no SIGTERM, so there the
daemon is killed and its one-shot runs outlive it.

Verified in tmux against the tokenless mock: with a chat session worker, a room
member holding a call for approval and a stalled heartbeat run, infer daemon
stop returned in 0.13s, every child logged its own shutdown, and no infer
process was left.
@edenreich
edenreich requested a review from a team as a code owner November 24, 2026 14:59
@github-project-automation github-project-automation Bot moved this to Todo in 2026 Nov 24, 2026
@edenreich edenreich changed the title feat(daemon)!: add infer daemon stop and move the session commands to infer sessions feat(daemon): add infer daemon stop and move the session commands to infer sessions Nov 24, 2026
@edenreich
edenreich added this pull request to stack #1971 November 24, 2026 16:37
@edenreich
edenreich merged commit c078c6f into main Nov 24, 2026
14 checks passed
@edenreich
edenreich deleted the feat/daemon-stop branch November 24, 2026 16:43
edenreich added a commit that referenced this pull request Nov 24, 2026
## Summary

Closes #1969. Stacked on #1968, so its base is `feat/daemon-stop`. Merge
#1968 first, and GitHub moves this PR onto `main`.

A workspace is a place sessions run, a concept of its own, yet #1968 put
its listing under `infer sessions` beside the commands that act on one
session. Workspaces now get their own command group:

```bash
infer workspaces list                          # every workspace in daemon.yaml and whether it is reachable
infer sessions run|stop|teleport <session-id>  # what infer sessions keeps
infer daemon stop                              # what infer daemon keeps, besides starting it
```

- **`infer workspaces list`** prints what `infer sessions workspaces`
printed: each workspace's name, compute, kind, protocol, whether it is
reachable, and its details. It asks the running daemon over its binding,
as before.
- **`infer sessions`** keeps `run`, `stop` and `teleport`.
- The command and its test move from `cmd/sessions` to `cmd/workspaces`
unchanged, apart from the `list` subcommand taking no arguments.
- The docs, the examples' Taskfiles and READMEs, and the chat's error
hint (`check it with: infer workspaces list`) use the new command.
`docs/commands-reference.md` gets an `infer workspaces` section after
`infer sessions`.

## Verification

- **In tmux against the tokenless mock**, with an isolated `HOME` and
binding port:
- `infer workspaces list` printed `Edens-MBP - local agui true
storage=jsonl version=dev` under its header
  - `infer sessions --help` lists `run`, `stop` and `teleport` only
  - `infer daemon stop` stopped the daemon
- `TestPrintWorkspacesListsTheProtocol` now runs in `cmd/workspaces`,
and `TestCommandTopology` lists `workspaces`.
- `go test -race ./cmd/...`, `golangci-lint`, the import check,
markdownlint, and the pre-commit gate.
- **Not run:** the Kubernetes teleport examples whose Taskfiles now call
`infer workspaces list`, which need a cluster. The edit there is the
command name only.

## Cross-repo impact

- inference-gateway/docs#1307 updates the CLI page, `cli.md`, for this
PR and #1968: `infer workspaces list` replaces `infer daemon workspaces`
there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant