@@ -261,6 +261,97 @@ When initiated with a non-streaming request, an :program:`exec error`
261261response SHALL NOT be sent if a failure occurs after a successful call to
262262:func: `execvp `.
263263
264+ attach
265+ ======
266+
267+ The :program: `attach ` RPC attaches to an existing background subprocess.
268+
269+ .. object :: attach request
270+
271+ The request SHALL consist of a JSON object with the following keys:
272+
273+ .. object :: pid
274+
275+ (*integer *, REQUIRED) The process ID of the background subprocess.
276+
277+ .. object :: label
278+
279+ (*string *, OPTIONAL) The label of the background subprocess. If this key
280+ is present, the value of ``pid `` SHALL be ignored and the subprocess
281+ SHALL be identified by its label.
282+
283+ .. object :: flags
284+
285+ (*integer *, REQUIRED) A bitfield comprised of zero or more flags.
286+
287+ No flags are currently supported. The flags value SHALL be ignored
288+ and output forwarding behavior SHALL be inherited from the original
289+ subprocess.
290+
291+ .. note ::
292+
293+ Output produced by the subprocess before the attach request MAY be lost
294+ unless the subprocess server has buffered it or logged it to its own
295+ log stream.
296+
297+ The :program: `attach ` response stream SHALL follow the same format as
298+ streaming :program: `exec ` responses. The server SHALL send:
299+
300+ - :program: `exec attached ` response to indicate successful attachment
301+ - :program: `exec output ` responses for any buffered output and subsequent
302+ output matching the target subprocess flags
303+ - :program: `exec stopped ` response if the subprocess is stopped
304+ - :program: `exec finished ` response when the subprocess terminates
305+ - :program: `exec error ` response with ENODATA (61) to indicate successful
306+ stream termination
307+
308+ .. object :: exec attached response
309+
310+ The client has successfully attached to the subprocess.
311+
312+ The response SHALL consist of a JSON object with the following keys:
313+
314+ .. object :: type
315+
316+ (*string *, REQUIRED) The response type with a value of ``attached ``.
317+
318+ .. object :: pid
319+
320+ (*integer *, REQUIRED) The process ID of the subprocess.
321+
322+ .. object :: flags
323+
324+ (*integer *, REQUIRED) The flags that the subprocess was originally
325+ started with. This allows the client to determine which output streams
326+ and responses to expect.
327+
328+
329+ If the subprocess was started with the waitable flag and has already
330+ terminated before the attach request is processed, the server SHALL send an
331+ :program: `exec attached ` response, followed by :program: `exec output ` responses
332+ with the EOF flag set for each output stream that was being forwarded,
333+ followed by the :program: `exec finished ` response, and finally ENODATA to
334+ terminate the stream.
335+
336+ .. note ::
337+
338+ A waitable background subprocess that is successfully attached to and
339+ receives the :program: `exec finished ` response SHALL be considered reaped
340+ and cannot be waited on or attached to again.
341+
342+ If the requesting process disconnects, the subprocess SHALL revert to
343+ background mode and continue running until it terminates or the server
344+ is shut down.
345+
346+ .. object :: attach error response
347+
348+ The :program: `attach ` RPC SHALL return an error response if:
349+
350+ - The subprocess does not exist or has exited without the waitable flag (ENOENT)
351+ - The subprocess is not currently in background mode or already has a
352+ client attached (EBUSY)
353+ - The client lacks authorization to attach to the subprocess (EPERM)
354+
264355write
265356=====
266357
0 commit comments