Skip to content

Support an explicit Unix PTY socket directory - #27

Closed
CBEPX wants to merge 2 commits into
anomalyco:masterfrom
CBEPX:feat/private-unix-pty-socket-directory-20261024
Closed

CBEPX wants to merge 2 commits into
anomalyco:masterfrom
CBEPX:feat/private-unix-pty-socket-directory-20261024

Conversation

@CBEPX

@CBEPX CBEPX commented Oct 24, 2026 •

Copy link
Copy Markdown

Add the optional Unix environment variable OPENCODE_PTY_SOCKET_DIR so an isolated instance can keep its socket in its own directory. The value must be absolute. An unset variable retains /tmp/opencode-pty-<uid>/. The existing ownership, symlink and 0700 checks remain in use, and abandoned-socket cleanup uses the same selected root.

This changes src/daemon/unix.rs and documents the variable in README. It adds no dependency or protocol change. Windows implementation files remain untouched.

Validation on macOS arm64:

  • Configuration tests: 4 PASS after RED. cargo fmt --check and Clippy with warnings denied passed.
  • Upstream macOS CI test selection: 74 PASS, 0 FAIL, 1 ignored subprocess fixture entrypoint.
  • Minimum Rust 1.90.0: the same macOS test selection passed (74 PASS, 0 FAIL, 1 ignored). Formatting, Clippy with warnings denied and a debug build passed. The guarded build used a private mktemp -d adapter with an explicit temporary path.
  • Native OpenCode 2.1.3 with the supported OPENCODE_PTY_BIN override: private socket, terminal creation/output, persistence across CLI calls and explicit restart closure passed.
  • Native persistent WebSocket checks passed with the debug and optimized candidates: framed input/output, disconnect, fresh-ticket reconnect and cursor-0 replay. Requests without authorization, without the ticket header and with a reused ticket were rejected.
  • The optimized Rust 1.90.0 candidate passed the same macOS test selection (74 PASS, 0 FAIL, 1 ignored).
  • The native GUI retained two legacy /api/pty terminals through reload, with the same IDs, PIDs and process birth identities. Input/output and explicit close passed. This separate backend does not prove experimental candidate GUI binding.
  • An Apple PTY capability filter allowed the instance's own terminal and denied a separate control PTY. Regular-file writes outside the declared scope stayed denied. Primary OpenCode settings and pre-existing shared IPC/service state stayed unchanged.

The original lifecycle check used a local debug candidate built with Rust 1.99.1 and the upstream-pinned Zig 0.16.0. The optimized candidate used Rust 1.90.0. No global installation was performed. Linux and Windows were not tested.

Related to #26.

CBEPX and others added 2 commits October 24, 2026 04:48
Sockets now live in a dedicated opencode-pty-<uid> child of
OPENCODE_PTY_SOCKET_DIR, so the permissions of the chosen directory are
left untouched. Paths containing `..` components are rejected.

The stale-runtime sweep removes the socket recorded in the abandoned
registration (when owned by the current uid) instead of recomputing it
from the current socket root.
@jlongster
jlongster marked this pull request as ready for review October 27, 2026 14:49
@jlongster

Copy link
Copy Markdown
Collaborator

anomalyco/opencode#59697

@jlongster jlongster closed this Oct 27, 2026
@jlongster

Copy link
Copy Markdown
Collaborator

Thanks @CBEPX! This landed in the monorepo as anomalyco/opencode#59697 with you kept as the author (OPENCODE_PTY_SOCKET_DIR), and it was released in @opencode/pty 0.3.3.

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.

2 participants