Fix opencode TUI startup when /tmp is mounted noexec (BUN_TMPDIR override) - #41
Merged
Conversation
…t-aware isTmpNoexec compared TMPDIR to /proc/self/mounts mountpoints verbatim, so a symlinked TMPDIR (e.g. /tmp -> /var/tmp on a noexec mount) escaped detection and Bun kept dying. Resolve with realpathSync first -- the mount table lists real paths only. bunTmpdirOverride's test assumed the host TMPDIR is exec and asserted null unconditionally, which would fail on exactly the noexec hosts this feature targets. It now derives the expectation from the live mount table via mountHasNoexec, so it is deterministic everywhere.
bunTmpdirOverride returns ~/.cache/opencode/tmp, not the test's mkdtemp dir, so on exactly the noexec hosts this feature targets the mount-aware test from 3065fe8 failed. Expect the actual override path, and realpath the mkdtemp dir first so a symlinked host TMPDIR (/tmp -> /var/tmp) is compared the same way isTmpNoexec compares it.
bunTmpdirEnv clobbered a user-set BUN_TMPDIR whenever the host TMPDIR was noexec. Bun prefers BUN_TMPDIR over TMPDIR, so an explicit value already sidesteps the noexec problem -- and the override could even turn a working configuration into a dead launch when HOME is not writable (the fallback mkdir fails and the launch falls back to the noexec TMPDIR). Leave an existing BUN_TMPDIR untouched.
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.
概要
opencode は Bun ランタイムで動き、起動時に埋め込み
libopentui.soを TMPDIR(既定/tmp) へ展開してdlopenする。/tmpがnoexecマウントだとmmap(PROT_EXEC)が失敗し TUI 初期化で即死する (anomalyco/opencode issue #26136 / #27580 と同一問題、上流 PR #26134 は未マージ)。ccserver 側で同等の回避を実装: ホストの TMPDIR が noexec マウント上のとき、非サンドボックス起動の opencode セッションにのみ
BUN_TMPDIR=$HOME/.cache/opencode/tmpを設定する。変更内容
server/ws/bunTmpdir.js(新規)parseMountOptions/mountHasNoexec—/proc/self/mounts解析の純関数(最長プレフィックス一致マウント、octal エスケープ復号)isTmpNoexec— linux かつ実在する絶対 TMPDIR(既定 /tmp) が noexec か。symlink は realpath 解決bunTmpdirOverride/bunTmpdirEnv— 切り替え先ディレクトリを作成して返す。mkdir 失敗時は従来動作にフォールバック。ユーザーが明示的にBUN_TMPDIRを設定済みなら上書きしないserver/ws/sessionManager.js—createSession()の pty env に、opencode && !useSandboxのときのみ BUN_TMPDIR を注入。サンドボックス内の/tmpは fresh tmpfs で常に exec 可であり、ホストのキャッシュディレクトリは bwrap にバインドされないため、サンドボックス起動時は何もしないserver/ws/bunTmpdir.test.js(新規) — 純関数の単体テスト 11 件(node --test)テスト
npm test— 313 pass / 1 fail。fail は既知の環境依存テスト (sandbox-resolve.test.js:/usr/bin/claudeがこのホストに実在するため)。