Environment transports own execution processes
环境传输负责执行进程
The environment protocol sends self-contained functions and origin callbacks over a byte channel. Starting, stopping and retaining a process depend on the transport. A common resident Unix listener adds socket naming, permissions, startup locking and worker replacement even when a provider only needs one process for one channel. No function state survives between connections, and sent runs cannot resume or replay.
English
Problem
The environment protocol sends self-contained functions and origin callbacks over a byte channel. Starting, stopping and retaining a process depend on the transport. A common resident Unix listener adds socket naming, permissions, startup locking and worker replacement even when a provider only needs one process for one channel. No function state survives between connections, and sent runs cannot resume or replay.
Decision
Transports own execution-process startup, shutdown and any persistence mechanism. The registry owns registrations, the function protocol and one cached connection per registration. SSH and local transports start a fresh daemon.js serve --stdio process for each new connection; reusing a live channel keeps that process. The daemon serves one connection using Node standard-library APIs. It has no resident listener, socket bridge or remote process supervisor.
This decision partially supersedes the original environment note: its resident-process and socket-trust decisions are historical; its function I/O, origin callbacks and single-runtime rationale remain active. The original note remains active and cross-linked.
Alternatives considered
- A common resident Unix listener. The original design preserved a process across disconnections, used a lock for exclusive startup, and replaced each connection's worker so a lingering connection or blocked function could not prevent a new connection. It also required socket permissions and a trusted directory. Without resumable runs or retained function state, these mechanisms do not justify common protocol ownership. A provider with a concrete persistence or supervision requirement may implement its own listener.
- One stdio daemon per connection. The original note rejected this because disconnection ends the process and each transport needs a launch path. Those properties match transport ownership: the shipped providers already start their execution channel, and the registry never resumes a sent run.
- A shared listener that refuses a second host. The original rejection remains relevant to providers choosing shared listeners: a lingering or blocked connection can deny reconnection. Independent execution processes avoid a shared admission decision.
- A universal remote supervisor. The original resident requirement excluded the
dsh-sshhelper because its connection- or lease-scoped cleanup ended managed processes. Removing residency removes that conflict, but does not require a shared helper or supervisor. Each provider owns any stronger termination guarantee. - Application keys for authenticated stdio channels. Channel access already permits execution as the daemon user. SSH authentication and provider-owned local pipes establish the shipped trust scope. Any network provider must authenticate its channel; the protocol's
authexchange remains extensible.
Consequences
- The common daemon needs no socket namespace, filesystem socket permissions, startup lock, idle listener or worker replacement. Independent connections do not replace one another's processes.
- Without a resident listener, the daemon stops blocked execution itself: it runs functions in worker threads and terminates the worker of a cancelled run that does not stop, as the original note describes. Closing SSH ends remote code only once the daemon observes its closed input. Stronger remote supervision belongs to a provider that supplies it.
- Callers trust the provider, daemon files and execution machine.
node:vmseparates globals; it is not a sandbox. Filesystem and process operations use the execution process's permissions. - Disconnection rejects in-flight runs with unknown outcomes, without replay or rollback. A later connection starts a new process; it does not recover execution state.
中文
问题
执行环境协议通过字节通道发送自包含函数和发起端回调。进程的启动、停止和保留方式取决于传输。通用的常驻 Unix 监听器引入 socket 命名、权限、启动锁和 worker 替换机制,即使提供方只需要一个进程服务一个通道也是如此。连接之间不保留函数状态,已发送的运行也不能恢复或重放。
决策
传输实现负责执行进程的启动、停止和任何持久运行机制。注册表负责注册项、函数协议,以及每个注册项的一个缓存连接。SSH 和本地传输为每个新连接启动全新的 daemon.js serve --stdio 进程;复用活跃通道时保留该进程。守护进程使用 Node 标准库 API 服务一个连接,没有常驻监听器、socket 桥接或远程进程监管器。
本决策部分取代最初的执行环境记录:其中的常驻进程和 socket 信任决策属于历史;函数 I/O、发起端回调和单运行时的理由仍然有效。原记录保持活跃,并与本记录互相链接。
考虑过的替代方案
- 通用的常驻 Unix 监听器。 最初的设计在断连后保留进程,通过锁保证独占启动,并替换每个连接的 worker,使残留连接或阻塞函数不会妨碍新连接。它还要求 socket 权限和可信目录。在没有可恢复运行或保留函数状态的情况下,这些机制不足以成为通用协议的职责。具有明确持久运行或监管需求的提供方可实现自己的监听器。
- 每个连接一个 stdio 守护进程。 最初的记录否决了此方案,因为断连会结束进程,而且每种传输都需要启动路径。这些特性符合传输管理进程的职责:随附提供方本就负责启动执行通道,注册表也从不恢复已发送的运行。
- 拒绝第二个 host 的共享监听器。 对于选择共享监听器的提供方,最初的否决理由仍然有效:残留或阻塞的连接可能阻止重连。独立执行进程无需共享连接接纳决策。
- 通用远程监管器。 最初的常驻要求排除了
dsh-sshhelper,因为它按连接或租约进行的清理会结束受管理进程。取消常驻要求消除了这一冲突,但不要求使用共享 helper 或监管器。任何更强的终止保证均由提供方负责。 - 在已认证的 stdio 通道上使用应用层密钥。 通道访问权限本已允许以守护进程用户身份执行。SSH 认证和提供方管理的本地管道确定了随附实现的信任范围。任何网络提供方都必须认证其通道;协议的
auth交换仍可扩展。
影响
- 通用守护进程不需要 socket 命名空间、文件系统 socket 权限、启动锁、空闲监听器或 worker 替换。独立连接不会替换彼此的进程。
- 没有常驻监听器时,守护进程自行停止阻塞的执行:它在 worker 线程中运行函数,并终止被取消后仍未停止的运行所在的 worker,如最初的记录所述。关闭 SSH 后,只有当守护进程观察到其输入已关闭时,远程代码才会结束。更强的远程监管由提供该能力的提供方负责。
- 调用方信任提供方、守护进程文件和执行机器。
node:vm隔离全局对象,但不是沙箱。文件系统和进程操作使用执行进程的权限。 - 断连使进行中的运行拒绝并报告结果未知,不重放也不回滚。后续连接启动新进程,不恢复执行状态。