Skip to content

fix(chat): give opencode a private TMPDIR so scratch work never lands in $HOME - #671

Merged
kthare10 merged 1 commit into
developfrom
fix/opencode-tmpdir
Nov 11, 2026
Merged

kthare10 merged 1 commit into
developfrom
fix/opencode-tmpdir

Conversation

@kthare10

Copy link
Copy Markdown
Contributor

Closes #670

Problem

OpenCode's bash tool tells the model to do scratch work in os.tmpdir()/opencode and says the directory already exists. The image build runs opencode --version as root, which leaves /tmp/opencode owned by root:root with mode 0755. The model's mkdir there failed, the cd after it failed as well, and the test script ran in $HOME, leaving empty output files there. Evidence is in #670.

Changes

  • Dockerfile: remove /tmp/opencode in the same RUN that creates it, so a terminal-launched opencode doesn't hit it either.
  • docker/supervisor/scripts/opencode.sh: export TMPDIR=$STUDIO_RUNTIME_DIR/tmp (mode 0700, a separate directory per uid). This also fixes shared hosts (Open OnDemand binds the host /tmp), where /tmp/opencode would belong to whichever user created it first. Commands the model runs inherit it, so mktemp stays private too. opencode honors TMPDIR; verified in a pod with TMPDIR=$T opencode --version, which creates $T/opencode owned by the user.
  • studio-api/tests/test_opencode_launcher.py: runs the real launcher against a fake opencode and asserts that TMPDIR is private and that the session cwd is still the workspace.

Testing

  • pytest -q: 1062 passed.
  • No image rebuilt yet. After deploy, ls -ld /tmp/opencode in a new pod should fail, and the chat's scratch dir should be /tmp/studio-runtime-<uid>/tmp/opencode.

… in $HOME

OpenCode's bash tool tells the model to use os.tmpdir()/opencode for
temporary work and says the directory already exists. The image build
ran `opencode --version` as root, which left /tmp/opencode owned by
root:root with mode 0755. The model's mkdir there failed, the cd after
it failed as well, and the test script ran in the session directory
($HOME), leaving empty output files in the user's home.

- Dockerfile: remove /tmp/opencode in the same layer that creates it.
- opencode.sh: export TMPDIR=$STUDIO_RUNTIME_DIR/tmp (0700, per uid).
  This also covers shared hosts, where /tmp/opencode would otherwise
  belong to whichever user created it first.
@kthare10
kthare10 merged commit b6ff30a into develop Nov 11, 2026
1 check passed
@kthare10
kthare10 deleted the fix/opencode-tmpdir branch November 11, 2026 02:30
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