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:
- at most one every 20 seconds;
- only while the host is above its memory and disk floors and under its session cap; otherwise it waits;
- a session already resumed some other way is skipped.
Each resumed session gets the note. Without --resume, the paused sessions stay on Paused; resume them from Otto when you want.
Options
| Option | Commands | Effect |
|---|---|---|
--grace <min> | drain | The grace period, in minutes. Default 5. From 0 to 1440. |
--hard <min> | drain | The 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> | drain | Who asked, shown in every refusal and in the status, such as server-move export. At most 120 characters. |
--wait | drain | Follows the drain until it is drained or stuck, printing progress lines. Checks every 5 seconds. |
--wait-minutes <n> | drain | With --wait: how long to follow it. Default the grace period plus the hard timeout plus 2 minutes. |
--stdin-cancel | drain | With --wait: stops waiting when standard input closes. The drain goes on. |
--resume | undrain | Resumes 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:
- every launch, a handoff's too, from a Mac, the web app,
/otto:launch-sessionorotto-host launch; - every resume, by hand or for a message;
- a swarm's new workers;
- the task queue's starts and resumes;
- a message to a paused session (
/otto:message-session): it is not delivered.
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
- 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. - Deadline (start plus the grace period). A session still busy, or with a question on its screen, is interrupted with Esc, as an urgent
HOLDmessage 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. - 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:
- a process under its Claude runs
git rebase,commit,push,pull,merge,cherry-pick,revert,am,stash,worktree,checkout,switchorreset; - its checkout has a rebase, merge, cherry-pick or revert stopped halfway;
- its worktree is in
/otto:finalize-worktree's queue, waiting to land or landing; - a process under its Claude is an Otto script that writes the vault:
create-task,update-task,launch-session,lead-memoryorepic; - it is a swarm lead whose workers run.
When the preview relay cannot say what runs, every busy session counts as in such a step.
Status
Every command answers with the status:
| Field | Contents |
|---|---|
draining | Whether the hold is on. |
phase | One of the phases. |
startedAt, by | When the drain started, and who asked. Null once undrained. |
graceMinutes, hardMinutes | The grace period and the hard timeout. |
deadline, hardDeadline | When the grace period ends, and when the hard timeout ends. Null once undrained. |
sessions | This 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. |
paused | What a drain paused and nobody resumed yet: cliSessionId, name, pausedAt, interrupted, projectId. |
summary | One line for a person. |
Phases
| Phase | Meaning |
|---|---|
off | No hold, nothing to resume. |
grace | Draining, within the grace period: busy sessions are finishing their turn. |
cutting | Past the deadline: sessions are still being interrupted and paused, or waited for. |
drained | Every session is paused. A swarm worker may still run. Nothing starts until undrained. |
stuck | Past the hard timeout, a session is still in a step that must not be cut, or still cannot be paused. Nothing was cut. |
resuming | Undrained with --resume: what the drain paused is resuming, one at a time. |
Session states
| State | Meaning |
|---|---|
waiting | Busy, or asking a question, within the grace period. Also a session whose pause or interrupt failed; it is tried again. |
held | Past the deadline, in a step that must not be cut: waited for. |
stuck | Still in that step past the hard timeout: reported, never cut. |
paused | Paused. Its conversation is kept. |
worker | A 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
| Path | What |
|---|---|
/otto/drain.json | The 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. |