Docs / Reference

otto-host drain

Brings every session on a session host to a safe stop, keeps anything new from starting, and resumes what it paused once you undrain. Used by Drain a session host for maintenance.

Synopsis

otto-host drain [--grace <min>] [--hard <min>] [--by <label>] [--wait] [--wait-minutes <n>] [--stdin-cancel]
otto-host drain status
otto-host undrain [--resume]

Each command asks the host's broker, which does the work and keeps the state. On the server, run them in the otto-host container as the service user:

docker exec otto-host otto-as-service node /otto-host-exec/otto-host.js drain status

Otto's Settings → Session hosts runs the same commands, on the desktop and in the web app.

Commands

drain

Starts a drain. The hold goes on at once, then the broker stops the sessions in three stages. A drain that is already on is kept as it is: its start time, grace period and hard timeout do not change.

Without --wait, it prints the status and returns. With --wait, it follows the drain, prints a progress line at each change, and returns when the phase is drained or stuck, when the drain is lifted, or when the wait runs out. Stopping the wait never cancels the drain.

drain status

Prints the status. Changes nothing.

undrain

Lifts the hold: launches, resumes and messages work again. The broker stops the drain where it is; a session it has not paused yet keeps running.

With --resume, the broker also resumes every session a drain paused, oldest pause first, one at a time:

Each resumed session gets the note. Without --resume, the paused sessions stay on Paused; resume them from Otto when you want.

Options

OptionCommandsEffect
--grace <min>drainThe grace period, in minutes. Default 5. From 0 to 1440.
--hard <min>drainThe hard timeout: how long after the deadline a step that must not be cut is waited for. Default 30. From 0 to 1440.
--by <label>drainWho asked, shown in every refusal and in the status, such as server-move export. At most 120 characters.
--waitdrainFollows the drain until it is drained or stuck, printing progress lines. Checks every 5 seconds.
--wait-minutes <n>drainWith --wait: how long to follow it. Default the grace period plus the hard timeout plus 2 minutes.
--stdin-canceldrainWith --wait: stops waiting when standard input closes. The drain goes on.
--resumeundrainResumes what the drain paused, one at a time.

Output

Like every otto-host command, it prints JSON lines: progress lines while --wait follows the drain ("phase": "drain", a message), then one result line whose data is the status. A request that fails prints a result with "ok": false and the reason. Exit status 2 for wrong usage (a bad flag or minutes out of range); otherwise 0, a refused request included (such as a drain asked from inside a session: "ok": false, code refused).

The hold

From the moment a drain starts until it is undrained, the host's broker refuses:

It does not wake a paused Keeper for a message from another session. That message waits in the host's queue and is delivered after the undrain, like a message a memory floor holds: at most 50 wait, each for at most 6 hours.

Every refusal carries the same words:

This host is draining for maintenance (since 2026-10-24 09:12 UTC, by Otto on my-mac): it starts and resumes no session until it is undrained — `otto-host undrain` on the host, or Undrain in Otto's Settings → Session hosts.

A message typed into a session that is still running is delivered as usual.

Stages

  1. Grace period. Each session is paused as soon as its turn is over: it is idle, shows no question, and runs no background work. The pause is the session pool's: Claude gets /exit, the conversation is kept, and a paused record is filed, so the session shows on Paused.
  2. Deadline (start plus the grace period). A session still busy, or with a question on its screen, is interrupted with Esc, as an urgent HOLD message would be, then paused. A session in a step that must not be cut is not interrupted: it is waited for, and paused once its turn is over.
  3. Hard timeout (deadline plus the hard timeout). A session still in such a step is reported as stuck. It is never cut: finish or stop it by hand.

A swarm's workers are left to run to their end; no new worker starts. An interrupted session is recorded in the drain's status, and a line in its project's Hive channel says it was interrupted.

Steps that must not be cut

At the deadline, the broker asks the preview relay what each busy session runs. A session is in a step that must not be cut when:

When the preview relay cannot say what runs, every busy session counts as in such a step.

Status

Every command answers with the status:

FieldContents
drainingWhether the hold is on.
phaseOne of the phases.
startedAt, byWhen the drain started, and who asked. Null once undrained.
graceMinutes, hardMinutesThe grace period and the hard timeout.
deadline, hardDeadlineWhen the grace period ends, and when the hard timeout ends. Null once undrained.
sessionsThis drain's sessions: id, name, state (one of the session states), and when there are some, steps, interruptedAt, pausedAt, cliSessionId, error (the last pause or interrupt that failed; tried again). Empty once undrained.
pausedWhat a drain paused and nobody resumed yet: cliSessionId, name, pausedAt, interrupted, projectId.
summaryOne line for a person.

Phases

PhaseMeaning
offNo hold, nothing to resume.
graceDraining, within the grace period: busy sessions are finishing their turn.
cuttingPast the deadline: sessions are still being interrupted and paused, or waited for.
drainedEvery session is paused. A swarm worker may still run. Nothing starts until undrained.
stuckPast the hard timeout, a session is still in a step that must not be cut, or still cannot be paused. Nothing was cut.
resumingUndrained with --resume: what the drain paused is resuming, one at a time.

Session states

StateMeaning
waitingBusy, or asking a question, within the grace period. Also a session whose pause or interrupt failed; it is tried again.
heldPast the deadline, in a step that must not be cut: waited for.
stuckStill in that step past the hard timeout: reported, never cut.
pausedPaused. Its conversation is kept.
workerA swarm's worker, left to finish.

The note on resume

A session a drain paused gets this note typed in when it is resumed, after its resume is over and before any message:

Otto paused this session for maintenance on <host> at <time> UTC, and has resumed it now. Check `git status` and anything you had running, then continue where you left off.

When the drain interrupted its turn, the note adds, after the time: , interrupting the turn you were in (a command it was running was stopped).

It gets the note however it is resumed: by undrain --resume, by hand from Otto, by a Keeper's message after the undrain, or on a new server after a move. It gets it once. A paused session nobody resumes is forgotten by the drain after 30 days; it stays on Paused.

Who may drain

Anything outside the sessions: Otto on a Mac or in the web app (Settings → Session hosts), the server's own scripts such as server-move.sh export --drain, or a person at the server. A session cannot drain or undrain the host it runs on: the broker checks that the caller's process is not inside one of the host's sessions, and refuses with

A session can't drain the host it runs on — ask the user to, from Otto's Settings → Session hosts

Drain and undrain requests together are limited to 10 a minute.

Files

PathWhat
/otto/drain.jsonThe drain: the hold, its start, grace period and hard timeout, this drain's sessions, and what a drain paused. $OTTO_HOME/drain.json, on the otto-state volume, written only by the broker, readable by the sessions. It survives a restart of the broker, the daemon or the container, and a server move: on the new server the hold is still on. An absent or unreadable file means no drain.