Skip to content

RFC: Native non-PTY process protocol - #173

Open
pcarrier wants to merge 2 commits into
codex/wasmi-plugin-rfcfrom
codex/native-process-rfc
Open

RFC: Native non-PTY process protocol#173
pcarrier wants to merge 2 commits into
codex/wasmi-plugin-rfcfrom
codex/native-process-rfc

Conversation

@pcarrier

@pcarrier pcarrier commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Extract the non-PTY process design from #167 into a standalone, all-client protocol RFC.

  • feature bit 13 and direction-local 0xC0 through 0xC6
  • direct argv execution with bounded arguments and environment
  • flow-controlled binary stdin, stdout, and stderr with lifetime offsets
  • ordinary endpoint-scoped children plus opt-in detachable children
  • client-generated 128-bit adoption tokens and atomic snapshot-to-live reattachment
  • bounded output gaps and repeatable retained exit snapshots across reconnects
  • correlated spawn/control outcomes, stdin state, explicit exit reasons, and kill causes
  • Unix process-group and Windows job cleanup semantics
  • count, stream-window, pending-request, spawn-concurrency, and retained-result limits
  • feature gate and security posture independent of Wasmi

Network clients use their existing transport. In-process extensions use the same packets through the ordinary host ABI, but neither implementation depends on the other.

Review follow-up

The revised RFC makes detach/adopt ownership, outbox cutoffs, inherited stdin, output-credit reset, terminal expiry, and concurrent adoption linearization explicit. It also serializes Unix spawn registration against Blit's existing waitpid(-1) backstop, documents expected supervisor BUDGET handling, and gives supervisors an explicit Unix per-process grace-period recipe.

Detached state is intentionally server-memory-only: it does not survive a Blit restart, and output produced while unbound is drained and represented as an offset gap rather than replayed.

Stack

This is intentionally based on #167 so the extension RFC can link to it while keeping the process family out of the parent PR. It should be reviewed and merged separately after the base lands.

Verification

  • ./bin/lint passes
  • cargo fmt --check, repository-wide Prettier, and git diff --check pass
  • independent consistency and flow-control reviews found no remaining merge blocker

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Coverage

Crate Lines Functions Regions
alacritty-driver 72.7% (806/1109) 75.0% (63/84) 76.2% (1310/1719)
browser 0.0% (0/822) 0.0% (0/68) 0.0% (0/1401)
cli 25.0% (2429/9697) 36.7% (299/815) 27.7% (4117/14871)
compositor 11.6% (1145/9870) 20.9% (98/469) 11.6% (1527/13207)
fonts 81.4% (721/886) 88.6% (70/79) 83.0% (1427/1719)
fssync 92.4% (4875/5274) 94.1% (445/473) 92.5% (8919/9647)
gateway 25.5% (375/1469) 29.9% (38/127) 19.2% (470/2448)
git 87.4% (4190/4793) 88.5% (332/375) 87.1% (6631/7614)
lsp 76.0% (2503/3295) 78.2% (248/317) 73.8% (3886/5266)
proxy 19.2% (172/898) 20.5% (26/127) 21.0% (293/1392)
remote 90.6% (9190/10147) 93.7% (672/717) 88.5% (15457/17460)
sd-notify 73.9% (68/92) 100.0% (6/6) 83.2% (109/131)
server 39.2% (7265/18552) 53.7% (707/1316) 41.7% (12306/29539)
ssh 32.2% (165/512) 48.2% (27/56) 31.4% (261/830)
upsidedown 31.4% (391/1247) 27.8% (55/198) 34.8% (797/2287)
webrtc-forwarder 2.7% (72/2624) 2.1% (4/187) 1.2% (50/4335)
webserver 62.1% (1133/1825) 65.9% (164/249) 64.5% (1912/2964)
Total 48.6% (35500/73112) 57.5% (3254/5663) 50.9% (59472/116830)

@pcarrier
pcarrier force-pushed the codex/native-process-rfc branch from 9a56e1f to 2efd517 Compare August 5, 2026 18:31
@pcarrier
pcarrier marked this pull request as ready for review August 5, 2026 18:31
@indent

indent Bot commented Aug 5, 2026

Copy link
Copy Markdown
PR Summary

Documentation-only RFC that extracts the non-PTY process protocol from the extension RFC (#167) into a standalone, all-client design doc. Feature bit 13 moves from RESERVED to PROCESS, and the family occupies direction-local opcodes 0xC0-0xC6. No code changes.

  • Adds docs/design/processes.md: feature bit 13, PROCESS_* opcodes in both directions, direct argv execution (no shell), flow-controlled binary stdin/stdout/stderr with lifetime offsets, endpoint-scoped process IDs, and correlated spawn/control/exit outcomes with explicit exit reasons and kill_cause.
  • Specifies opt-in detachable children: a server-wide detached registry, client-generated 128-bit adopt_token bearer secrets, PROCESS_ADOPT/PROCESS_ADOPTED with an atomic snapshot-to-live reattachment, a DETACH control action, bounded output gaps (drained, not replayed, while unbound), and repeatable retained exit snapshots with a 5-minute TTL. Detached state is server-memory-only and does not survive a restart.
  • Documents Unix process-group / Windows job cleanup, waitpid(-1) backstop serialization, admission limits (count/window/request-bytes/spawn-concurrency/retained-result), expected supervisor BUDGET backpressure, and a BLIT_PROCESS=0 gate with authority parity to CREATE2(HAS_COMMAND) (explicitly not a sandbox).
  • Updates docs/design/extensions.md to point its process-execution alternatives at the new RFC, and docs/protocol.md to rename bit 13, extend the disabled-family note to bits 11-13, and add the processes.md#security-and-deployment link.

Reviewed for internal consistency: opcode block 0xC0-0xC6 stays clear of Git's 0xA0-0xBF; C2S/S2C opcode tables, packet field widths, all enum tables (control actions, exit reasons, kill causes, stdin/stream states), adopt-token zero/non-zero rules, common-status-registry membership, ID/token lifetime, stdin accounting, and the capacity table all check out. No issues found.

Issues

No issues found.

CI Checks

All CI checks passed on 5493f9b.

View session

@indent

indent Bot commented Aug 5, 2026

Copy link
Copy Markdown

Reviewing this against #94 (units — declarative process supervision: unit files, Restart=, readiness and health checks, dependencies). This family is a better Backing=pipe than the one I specified — exact offsets, cumulative-byte windows, MERGE_STDERR, and "raw bytes, not UTF-8 and not line-framed" is exactly what regex readiness matching needs — and the group/job kill semantics are the ones I'd argued for. I'd like to drop my version and build on this.

One thing prevents that today.

Please add a detach/adopt path

No detached children. Every child belongs to one logical endpoint and is terminated when that endpoint closes.

A restarted extension attempt gets no handles to the previous attempt's children.

For a client running a build or a test, that's the correct default and I wouldn't change it. For a supervisor it inverts the property that makes a supervisor worth having: the supervisor is supposed to be more reliable than the things it supervises. Here, updating the supervising extension, cancelling its attempt, or tripping a guest trap takes down every process it manages. A units extension could not ship a new version without killing production.

It's also inconsistent with the neighbouring family, in a way that would surface as two backings with opposite crash semantics. #167 says PTYs "remain server-session objects, exactly as they do when an ordinary network client disconnects. Attempt cleanup does not invent extension-only PTY ownership." So a PTY-backed unit survives its supervisor restarting and a pipe-backed one does not — same declarative config, same restart, different outcome, for a reason nobody writing a unit file would predict.

What I need is the weakest version of this that works: an opt-in spawn flag that makes a child outlive its endpoint, plus a way for a later endpoint to re-attach to it by a stable identity. (extension_id, process_id) would do, since #167 already gives extensions a stable ID across attempts. I don't need detached children to be discoverable server-wide, or adoptable by an unrelated client, or to buffer output while unattached — dropping output during the gap is fine, and a supervisor that reconnects to a live process and a known exit status has everything it needs.

Worth saying that this is useful beyond units. Any client that wants a long-running job to survive a reconnect wants it, and today the only way to get it is CREATE2(HAS_COMMAND) — i.e. taking a PTY you don't want purely for its lifetime semantics. That's a bad reason to allocate a terminal.

Please make the per-endpoint cap reachable for a supervisor

BLIT_PROCESS_MAX_PER_CLIENT defaults to 16, and a supervisor is a single endpoint. Combined with generations staying reserved through drain, a handful of crash-looping units can exhaust it, and the failure lands on unrelated healthy units as BUDGET at the worst moment. Server-wide 64 has the same shape.

I'm not asking for a higher default — 16 is right for an interactive client. I'd like either the per-endpoint cap to be raisable for a specific endpoint, or an acknowledgement in the RFC that a supervising client should expect to hit it, so the units design sizes against it deliberately rather than discovering it in a crash loop.

Two smaller notes

KILLED doesn't say who killed it. A client-requested KILL, an endpoint teardown, and a post-grace escalation after TERMINATE all arrive as reason = KILLED, code = 0. Restart=on-failure works fine off RETURNED plus code, but "was this my own intentional stop, or did something else kill my child?" has to be reconstructed client-side by correlating against the PROCESS_CONTROLLED you got back. A sub-reason byte, or reserving a couple of the free 5..255 values, would make the common supervisor case unambiguous. Not a blocker.

BLIT_PROCESS_KILL_GRACE is server-fixed at 2 s and "clients cannot tune resources per spawn," so a unit's TimeoutStopSec= can't be expressed through TERMINATE. The workaround is fine and I'll take it — SIGNAL(SIGTERM), run my own timer, then KILL — but it does mean TERMINATE is unusable for anything with a per-unit stop timeout, which is most of what I'd want it for. Worth a sentence noting that supervisors are expected to do their own escalation.

Everything else here I'd take as-is.

@pcarrier

pcarrier commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in fe67fb5 and rebased onto current #167. The RFC now specifies opt-in DETACHABLE children with client-persisted 128-bit adoption tokens; atomic PROCESS_ADOPT / PROCESS_ADOPTED snapshot-to-live binding; bounded output gaps, stdin inheritance, detach cutoffs, terminal-result retention, and endpoint-loss races; explicit KILLED causes; supervisor BUDGET guidance; and the Unix custom-grace workaround / Windows limitation. It also serializes child registration against the existing waitpid(-1) backstop and makes process-lifetime tasks server-owned so an extension replacement can adopt a surviving child.

@pcarrier
pcarrier force-pushed the codex/native-process-rfc branch from fe67fb5 to 5493f9b Compare August 6, 2026 01:21
pcarrier added a commit that referenced this pull request Aug 6, 2026
…dlines, retention (#204)

Closes #181.

Implements all three gaps in #181. They share one cause — nothing in the server owned a PTY's lifetime — and one implementation: a supervisor loop that runs when the delivery tick does not.

Five commits, each building standalone and separately verified:

| Commit | #181 item | What it fixes |
| --- | --- | --- |
| `answer a refused create instead of dropping it` | 3 (half) | all four create arms refuse with a bare `continue`, so a nonce-bearing client waits forever |
| `kill a terminal's process group, not just its leader` | 2 | `kill(pid)` / `kill(pid, SIGHUP)` reached the session leader alone — kill a shell, keep its children |
| `detect a terminal's exit from the child, not from EOF` | 1, 2 | exit detection was EOF-on-master, which means "the slave closed", not "the child exited" |
| `enforce opt-in terminal deadlines, and say when one fired` | 1 | every timeout was client-side, so none survived the client that set it |
| `bound retained terminals, and count the cap against live ones` | 3 (rest) | nothing but an explicit `CLOSE` ever removed an exited entry |

## Relationship to #188

#188 made `BLIT_MAX_PTYS` reachable and argued — correctly — that unlimited is the right default. It also documented the gap this PR closes, in `allocate_pty_id`: *"the protocol has no 'create refused' message"*, settling for an `eprintln` so the cap at least leaves a trace in the server log.

So the cap could be set but not safely used: turning it on traded an unbounded terminal count for a client that hangs. This adds the missing message and **leaves the default at 0**. `--max-ptys` is added alongside the env var for symmetry with the other server knobs; the `eprintln` stays, because the older create opcodes still drop the request silently by design.

The last commit does change the cap's *counting* to live terminals only, so a client running short commands under `--max-ptys N` is not refused after N of them with nothing running. Exited terminals get their own bound instead.

## Verification

Each commit message records its own check. The load-bearing ones, all re-run after the rebase onto main:

- **Refusal**: server with `--max-ptys 1` refuses the second create in milliseconds with `budget exhausted (terminal cap reached (1); raise --max-ptys or close a terminal)` and exit 1. Previously: a 10s hang, then a generic socket timeout.
- **Exit detection**: A/B'd against a pre-change server with the same command, `bash -c '(trap "" HUP; sleep N) & exit 7'` — a grandchild that ignores the hangup and keeps the slave open. Before: the terminal sits at `running` indefinitely. After: `exited(7)`.
- **Deadlines**: a terminal created with `--deadline 5` and abandoned dies at ~5s with no client attached. `blit terminal wait` prints `signal(15) — killed by deadline` where a hand-rolled `kill 9` prints a bare `signal(9)`. Refreshed every 2s against a 4s deadline it survived 12s, then died 8s after the refreshes stopped.
- **Retention**: with `--max-ptys 2 BLIT_MAX_EXITED=3`, six consecutive short commands all succeed and the list settles at the newest three.
- **Group kill**: two tests pin both halves — one asserts a child survives a leader-only kill, the other that a group kill reaches it. Mutation-checked by flipping the second to leader-only and confirming it fails.

Workspace clippy clean, `cargo fmt` clean, 556 Rust tests and 812 JS tests passing, JS typecheck clean.

## Review notes

**Two things not verified here.** The Windows job-object half has no toolchain in this checkout (Nix, no rustup) and rests on CI's windows build. And the third commit removes `reap_zombies`' global `waitpid(-1)` drain — a strict improvement, since it was reaping other subsystems' children and discarding their statuses out from under the audio pipeline's own `try_wait`, but it is a change outside the PTY family.

**Group kill's limit, stated rather than papered over.** It reaches the leader's process group and, via `TIOCGPGRP`, the terminal's foreground group. A job backgrounded by an interactive shell is in neither and survives. Bounding that needs a cgroup, not a signal.

**Feature bits 11–13 are left unallocated** for the extension, channel, and process families under review in #167 and #173. This takes 14 (`CREATE_STATUS`), 15 (`KILL_MODE`), and 16 (`PTY_DEADLINE`), matching the allocation #167's `protocol.md` already proposes for 14. The common status registry this introduces is #167's design; landing it here means #167 can drop that section rather than restate it.

**Five pre-existing test failures in `crates/git`** are unrelated — identical 55-passed/5-failed on a tree with none of these changes (a local git config makes `git tag v1` demand a message).

## Follow-ups, deliberately not in here

- `docs/design/units.md` (#94) needs reconciling before it merges: it allocates `S2C_LEASE = 0x10`, which this PR now uses for `CREATE_FAILED`; it gives `CREATE_FAILED` a different opcode *and* payload; and its "the `C2S_KILL` flags arm is `data.len() >= 7`" is off by one, since 7 is the existing message length.
- The timed `C2S_CLOSE` escalation from units.md needs `CLOSE` to hold the entry in a "closing" state, which tangles with the retention path, and is not part of what #181 asks for.
- Bounding the *aggregate* `S2C_LIST` size needs a logical-message ceiling that does not exist yet. The per-field `TOO_LARGE` check is in.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant