fix(pty): keep registration out of purged temp directories - #20
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OPENCODE_PTY_RUNTIME_DIRwith explicit flags. Every command (daemon,play,status,list,watch,stop) requires--name NAMEand accepts an optional--runtime-dir DIR; the runtime directory isDIR/NAME. Names must be one path component of letters, digits,.,_, or-.DIRdefaults to OpenCode's state directory,${XDG_STATE_HOME:-~/.local/state}/opencode/pty, instead of$XDG_RUNTIME_DIRor the temp directory. macOSdirhelperdeletes regular files in$TMPDIRwhose creation and access times are over three days old, even while the daemon runs; this removedservice.jsonand broke restart handoff discovery. The heldservice.locksurvived because dirhelper skips open files./tmp/opencode-pty-<uid>/so its path always fitssun_path; macOS temp cleaners skip sockets.remove_if_currentfor the registration), then remove the empty runtime directory.DIRthat are over ten minutes old, contain only registration files, and show daemon evidence: a lock that can be acquired, or, without a lock file, a valid registration whose PID is gone. Empty directories and directories with foreign or unparseable files are kept.Validation
cargo fmt --check,cargo clippy --all-targets --all-features -- -D warnings, andcargo testpass on macOS.--runtime-dirroots and assert the runtime directory is removed on exit.play --name demo --runtime-dir DIRwas found bystatus/listwith the same flags, swept a backdated abandoned sibling, and leftDIRempty afterquit; a missing or invalid--nameis rejected.Rollout
Breaking CLI change: OpenCode must spawn
daemon --runtime-dir <root> --name <id>instead of settingOPENCODE_PTY_RUNTIME_DIR, together with the release bump.OPENCODE_PTY_RUNTIME_DIRis removed entirely. Existing handoffs carry their directory, so daemons still running from the legacy temp directory remain adoptable: OpenCode moves theirservice.lockandservice.jsoninto<root>/<id>by rename (the inode, and so the old daemon's flock, is preserved) and uses that directory from then on. If any step fails, OpenCode abandons the old daemon and starts a fresh one in a new directory; it never respawns into a legacy temp directory.