Dashboard › opencode › Distillation
978b276e-4fc8-4567-8e21-acbab9525942["lore_tm_v1_ekouzsg2fhaIO3okHOnGuJX_F4Dp3jtdoroiLZ-dgCw","lore_tm_v1_JXKF-ULxyJGlmdbKgJUFx_auaEVZ5LXC0JLdz0eAWDg","lore_tm_v1_HWNu5zl6KiQ5qaoFxP1dhWhNFTRn2rzunqNB6-jqC8c"]
Date: Sep 8, 2026
/home/byk/.local/share/opencode-v2-pilot/supervisor/internal/supervisor/auth.go showed authenticate() obtains both SO_PEERCRED and SO_PEERPIDFD via peerIdentity(), validates the peer UID/GID/PID, queries manager.ClientState(ctx), validates the systemd client identity, and stores that initial identity in authenticatedPeer.authenticatedPeer.validateCredentials() requires credential.Pid > 0 and exact matches against expectedUID and expectedGID; otherwise it returns "peer credentials do not match the expected client identity".authenticatedPeer.validateIdentity() requires the socket peer PID to equal clientIdentity.MainPID, and requires ActiveState == "active", SubState == "running", ControlGroup == expectedClientCgroup, and an InvocationID exactly 16 bytes long.authenticatedPeer.Recheck() first tests pidfd liveness with unix.PidfdSendSignal(peer.pidfd, 0, nil, 0), then re-queries manager.ClientState(ctx), repeats identity validation, and rejects admission if the current InvocationID differs from the initially authenticated invocation with "client service InvocationID changed during admission".peerIdentity() uses connection.SyscallConn() and raw.Control() to retrieve unix.SO_PEERCRED and unix.SO_PEERPIDFD; it rejects a negative pidfd, invokes unix.CloseOnExec(pidfd), and returns errors under the wrapper "SO_PEERCRED/SO_PEERPIDFD".authenticatedPeer.Close() closes its pidfd when pidfd >= 0 and sets the stored descriptor to -1; authentication failure paths call peer.Close() after obtaining the peer identity.TestReceiveStartClosesEveryExtraDescriptor, TestCopyInputRejectsOutputFrame, TestServeSessionDetectsDisconnectWhileInputForwardingBlocks, and TestTypeScriptTransportUsesHelperAndSplitsWrites; the TypeScript integration test uses a transient unit name matching opencode-pty-0123456789abcdef0123456789abcdef.service./home/byk/.local/share/opencode-v2-pilot/config/opencode/plugins/pty-transport.ts showed protocol constants: MAGIC = Buffer.from("OPTY"), VERSION = 1, HEADER_SIZE = 12, MAX_FRAME_SIZE = 70 * 1024, MAX_IO_PAYLOAD_SIZE = 32 * 1024, frame types INPUT=2, OUTPUT=3, EXIT=4, ERROR=5, STARTED=6, STOP=7, STOPPED=8, and unit-name regex /^opencode-pty-[0-9a-f]{32}\.service$/.pty-transport.ts defaults to supervisor socket /run/opencode-pty/supervisor.sock and helper /usr/local/libexec/opencode-pty-client; it uses HELPER_TIMEOUT_MS = 5_000, STOP_TIMEOUT_MS = 25_000, and MAX_HELPER_ERROR_BYTES = 2_000.assertSupervisorAvailable() can skip helper verification only when verifyRootHelper === false; otherwise it requires the helper to be a root-owned regular executable file with no group/world write bits, then connects to the supervisor socket and verifies that Node exposes a valid connected socket descriptor.openSupervisorTransport() spawns the helper with arguments [String(runtimeSeconds), "a" + base64url(command), ...args.map(argument => "a" + base64url(argument))] and stdio ["pipe", "pipe", "pipe", connectedSocketFD(socket), binding.fd], passing the connected supervisor socket and binding descriptor as child fds 3 and 4.pendingOutput until onOutput(listener) is registered, then drains the buffered Buffer objects in order via pendingOutput.splice(0).forEach(listener).OPTY, version 1, reserved header bytes 6 and 7 equal to zero, and payload length no greater than 70 * 1024; it accumulates partial socket data in buffer and processes complete frames in sequence.1..32 * 1024 bytes. STARTED frames must be nonempty UTF-8, occur only before unitName is set, and match /^opencode-pty-[0-9a-f]{32}\.service$/. ERROR frames must carry 1..32 * 1024 bytes of valid UTF-8.9 bytes: byte 0 is execMainCode, bytes 1..4 are big-endian execMainStatus, bytes 5..8 are a big-endian result-string length, and the remaining UTF-8 bytes must match that declared length; a valid EXIT resolves exited and calls socket.end().stopping === true; it synthesizes { execMainCode: 2, execMainStatus: 15, result: "stopped" }, resolves exited, and ends the socket."PTY supervisor connection closed before a structured exit.".openSupervisorTransport().write(data) splits input into chunks of at most MAX_IO_PAYLOAD_SIZE (32 * 1024) and writes each as a TYPE_INPUT frame under a 5_000 ms timeout; any timed-out write destroys the socket.openSupervisorTransport().close() sends one empty TYPE_STOP frame when not already stopping or settled, waits up to 25_000 ms for exited, destroys the socket on timeout, and otherwise waits for socket closure.connectedSocketFD() accesses Nodeβs private socket._handle.fd via Reflect.get, requires a nonnegative integer descriptor whose fstatSync(fd).isSocket() is true, and destroys the socket if Node does not expose a valid connected Unix-socket descriptor.waitForHelper() requires a helper stderr pipe, kills the helper with SIGKILL after 5_000 ms, retains stderr only while cumulative received size is at most 2_000 bytes, rejects signal termination, and reports retained stderr or PTY client helper exited with code ${code}. for a nonzero exit.