@@ -60,38 +60,48 @@ host-neutral suspension handshake:
6060
61611 . Stop admitting external ingress controlled by the host.
62622 . Call ` gateway.suspend.prepare ` with a stable, unique ` requestId ` .
63- 3 . If the response is ` busy ` , keep the process running and retry later.
64- 4 . If it is ` ready ` , save the returned ` suspensionId ` , then freeze or snapshot
65- the process before ` expiresAtMs ` .
63+ 3 . If the response is ` busy ` , keep the process running and retry later. To hold
64+ admission closed while already-admitted work finishes, request the optional
65+ preserve-only drain mode and poll ` gateway.suspend.status ` instead.
66+ 4 . If the response is ` ready ` , save the returned ` suspensionId ` , then freeze or
67+ snapshot the process before ` expiresAtMs ` .
66685 . After thaw, or if suspension is abandoned, call ` gateway.suspend.resume `
6769 with that ` suspensionId ` over the existing or a newly authenticated
6870 WebSocket. The CLI equivalents are ` openclaw gateway suspend ` and
6971 ` openclaw gateway resume <suspensionId> ` .
7072
71- A prepared Gateway accepts authenticated WebSocket connects, but fences every
72- method except ` gateway.suspend.* ` and one exact predecessor-bound restart. That
73- exception requires a non-safe ` gateway.restart.request ` whose ` target ` matches
74- the live Gateway lock; safe and untargeted restart requests remain fenced.
75- Controllers may reconnect after thaw and call resume. The
73+ A draining or prepared Gateway accepts authenticated operator WebSocket
74+ connections, allowing a controller to reconnect and check, renew, or release
75+ its own lease. New node and worker connections remain fenced. A prepared
76+ Gateway fences every method except ` gateway.suspend.* ` and one exact
77+ predecessor-bound restart. That exception requires a non-safe
78+ ` gateway.restart.request ` whose ` target ` matches the live Gateway lock; safe and
79+ untargeted restart requests remain fenced. No restart exception is available
80+ while the Gateway is still draining. Controllers may reconnect after thaw and
81+ call resume. The
7682[ Admin HTTP RPC plugin] ( /plugins/admin-http-rpc ) remains available for hosts
7783that cannot speak WebSocket at all. If every control path is lost, the
7884two-minute lease expiry reopens admission automatically.
7985
8086The RPC contract is:
8187
8288- ` gateway.suspend.prepare ` — ` operator.admin ` ; params
83- ` { "requestId": "stable-host-operation-id", "terminalPolicy": "preserve" } `
89+ ` { "requestId": "stable-host-operation-id", "terminalPolicy": "preserve", "drain": true } `
8490- ` gateway.suspend.status ` — ` operator.read ` ; params
8591 ` { "suspensionId": "id-from-prepare" } `
8692- ` gateway.suspend.resume ` — ` operator.admin ` ; params
8793 ` { "suspensionId": "id-from-prepare" } `
8894
89- ` terminalPolicy ` is optional and accepts only ` "preserve" ` or ` "terminate" ` .
90- Omitting it defaults to ` "preserve" ` , so open terminal sessions block normal
91- host suspension. A caller preparing an update that will terminate the Gateway
92- may explicitly use ` "terminate" ` ; this ignores open process-local terminal
93- sessions only. Terminal persistence activity and all other tracked work still
94- block preparation.
95+ ` terminalPolicy ` and ` drain ` are optional. ` terminalPolicy ` accepts only
96+ ` "preserve" ` or ` "terminate" ` and defaults to ` "preserve" ` ; ` drain ` defaults
97+ to ` false ` . With ` drain: false ` or no ` drain ` field, request handling and
98+ response shapes are unchanged: open terminal sessions block normal host
99+ suspension. A caller preparing an update that will terminate the Gateway may
100+ explicitly use ` "terminate" ` ; this ignores open process-local terminal sessions
101+ only. Terminal persistence activity and all other tracked work still block
102+ preparation. Drain mode always preserves terminals: combining ` drain: true `
103+ with ` terminalPolicy: "terminate" ` returns ` INVALID_REQUEST ` without acquiring
104+ a lease.
95105
96106IDs are trimmed, must contain a non-whitespace character, and are limited to
97107128 characters. A busy prepare result has ` status: "busy" ` , ` reason ` ,
@@ -107,36 +117,91 @@ IDs are trimmed, must contain a non-whitespace character, and are limited to
107117}
108118```
109119
110- Status returns ` {"status":"running"} ` or a ready result with ` expiresAtMs ` .
120+ If ` drain: true ` finds active work, preparation acquires a renewable lease,
121+ pauses new automatic cron scheduling, closes admission to unrelated new work,
122+ and returns:
123+
124+ ``` json
125+ {
126+ "status" : " draining" ,
127+ "suspensionId" : " 2c3f..." ,
128+ "expiresAtMs" : 1770000000000 ,
129+ "retryAfterMs" : 20000 ,
130+ "activeCount" : 2 ,
131+ "blockers" : [
132+ { "kind" : " root-request" , "count" : 1 , "message" : " 1 active request" },
133+ { "kind" : " terminal-session" , "count" : 1 , "message" : " 1 open terminal session" }
134+ ]
135+ }
136+ ```
137+
138+ Already-admitted work and its owned completions continue naturally; unrelated
139+ new runs, sessions, scheduled jobs, and independent work stay rejected. Open
140+ terminal sessions and terminal-persistence work remain blockers until they
141+ settle naturally. Drain mode never terminates or detaches a terminal. A terminal
142+ that remains open indefinitely can therefore keep the lease draining until the
143+ controller resumes it or the lease expires.
144+
145+ Poll ` gateway.suspend.status ` with the returned ` suspensionId ` , honoring
146+ ` retryAfterMs ` . While blockers remain, status returns ` status: "draining" `
147+ together with ` expiresAtMs ` , ` retryAfterMs ` , ` activeCount ` , and ` blockers ` .
148+ Each status call refreshes the active-work snapshot. Once every blocker has
149+ finished, the same lease transitions to ` {"status":"ready","expiresAtMs":...} ` .
150+ Status returns ` {"status":"running"} ` when no suspension is held; querying a
151+ different active lease returns a conflict without exposing its identifiers.
111152Resume returns ` {"ok":true,"status":"running","resumed":true} ` ; repeating it
112153after a successful resume returns ` resumed: false ` .
113154
155+ The dedicated ` openclaw gateway suspend ` command retains its existing
156+ refuse-only behavior. Controllers can request drain mode through any Gateway
157+ client or the generic CLI RPC command:
158+
159+ ``` bash
160+ openclaw gateway call gateway.suspend.prepare \
161+ --params ' {"requestId":"host-operation-1","terminalPolicy":"preserve","drain":true}' \
162+ --json
163+ openclaw gateway call gateway.suspend.status \
164+ --params ' {"suspensionId":"<suspension-id>"}' \
165+ --json
166+ openclaw gateway resume ' <suspension-id>'
167+ ```
168+
114169A competing request ID or transient scheduler-resume failure returns retryable
115170` UNAVAILABLE ` with ` retryAfterMs ` . During scheduler recovery, prepare, status,
116171and resume all return that error, the Gateway remains not-ready and
117172fail-closed, and the host must not freeze or snapshot it. OpenClaw retries the
118173scheduler automatically and reopens admission only after recovery succeeds. A
119- mismatched resume ID returns ` INVALID_REQUEST ` . Prepare shares the Gateway's
120- control-plane write budget of three attempts per minute; honor the returned
121- retry delay. WebSocket clients are bucketed by device and IP. Admin HTTP
174+ mismatched resume ID returns ` INVALID_REQUEST ` . Prepare is subject to the
175+ Gateway's control-plane write limit of 30 attempts per minute; honor the
176+ returned retry delay. WebSocket clients are bucketed by device and IP. Admin HTTP
122177controllers are bucketed by resolved client IP, so controllers behind one
123178proxy can share a budget.
124179
125- Preparation is refuse-only: OpenClaw closes new root/session/command admission,
126- pauses automatic cron ticks, and inspects work synchronously. If anything is
127- active, it resumes the scheduler and reopens admission before returning
128- ` busy ` ; it does not interrupt or drain that work. A ready lease lasts two
129- minutes. Repeating ` prepare ` with the same ` requestId ` renews it; expiry resumes
130- the scheduler before reopening admission.
180+ Without ` drain: true ` , preparation remains refuse-only: OpenClaw closes new
181+ root/session/command admission, pauses automatic cron ticks, and inspects work
182+ synchronously. If anything is active, it resumes the scheduler and reopens
183+ admission before returning ` busy ` ; it does not interrupt or drain that work.
184+ With ` drain: true ` , the same suspension owner instead keeps admission closed
185+ and cron scheduling paused until existing work settles. Already-owned cron
186+ completion and reconciliation continue.
187+
188+ Both draining and ready leases last two minutes. Repeat ` prepare ` before
189+ ` expiresAtMs ` with the same ` requestId ` , terminal policy, and drain mode to renew
190+ the same ` suspensionId ` ; changing any of those values conflicts with the
191+ existing lease. Use ` status ` for routine polling and reserve ` prepare ` for
192+ renewal to avoid consuming the write budget. Explicit resume and lease expiry
193+ restore scheduling before reopening admission. Leases remain in memory and
194+ disappear if the Gateway process exits.
131195Restart emission that becomes due during a ready lease waits until the lease
132196resumes; an in-flight restart makes preparation return ` busy ` .
133197
134- While ready, ` /healthz ` remains live and ` /readyz ` returns ` 503 ` . Local or
135- authenticated readiness responses include ` gateway-draining ` ; unauthenticated
136- remote probes receive only ` { "ready": false } ` . The HTTP health probe,
137- suspension methods on existing WebSocket connections, and an already-enabled
138- Admin HTTP RPC route remain available. Other RPCs return retryable
139- ` UNAVAILABLE ` . Built-in HTTP user-work routes and ordinary plugin HTTP routes,
198+ While draining or ready, ` /healthz ` remains live and ` /readyz ` returns ` 503 ` .
199+ Local or authenticated readiness responses include ` gateway-draining ` ;
200+ unauthenticated remote probes receive only ` { "ready": false } ` . The HTTP health
201+ probe, suspension methods on authenticated operator WebSocket connections, and
202+ an already-enabled Admin HTTP RPC route remain available. Other unrelated RPCs
203+ return retryable ` UNAVAILABLE ` . Built-in HTTP user-work routes and ordinary
204+ plugin HTTP routes,
140205including OpenAI-compatible APIs, tool/session operations, node watches, and
141206configured hooks, return ` 503 ` with ` error.code: "gateway_unavailable" ` . New
142207plugin-owned WebSocket upgrades also return ` 503 ` ; this covers upgrade
0 commit comments