Skip to content

fix(util): use a per-user tmp directory - #52973

Closed
Shalin-Shah-2002 wants to merge 1 commit into
anomalyco:devfrom
Shalin-Shah-2002:per-user-tmp
Closed

Shalin-Shah-2002 wants to merge 1 commit into
anomalyco:devfrom
Shalin-Shah-2002:per-user-tmp

Conversation

@Shalin-Shah-2002

Copy link
Copy Markdown

Issue for this PR

Fixes #50259

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The global tmp directory is os.tmpdir()/opencode, one fixed name shared by every user of a machine, and the Global layer runs mkdir on it at startup. If anything else already owns that name, startup fails for everyone with EEXIST: file already exists, mkdir '/tmp/opencode', which is the error in the issue (the reporter's /tmp/opencode is a 0-byte file). If another user owns it as a directory, startup passes but later writes into it can fail.

On POSIX the tmp directory is now opencode-<uid>, so it can't collide with another user's or a stray entry. Windows already has a per-user temp directory and keeps opencode. The tmp path is read through Global, so the permission whitelist and the instructions text pick up the new name without other changes.

I don't know what created the stray file in the report, so this fixes the shared name and the crash, not that original cause. Anything that was left in the old /tmp/opencode is not migrated; it is only scratch space.

How did you verify your code works?

Added a test in packages/util/test/global.test.ts that puts a regular file named opencode in TMPDIR and builds the Global layer. Before the change it fails with the issue's EEXIST; after, it passes. The existing tests that pinned …/opencode (global-roots.test.ts, global.test.ts, cli/test/service.test.ts) now expect opencode-<uid>.

packages/util: 91 pass. packages/cli test/service.test.ts: 21 pass. Typecheck is clean in both, and the pre-push check passed. With a stray file at $TMPDIR/opencode, opencode debug paths now exits 0 and reports tmp as …/opencode-501.

I could only test on macOS with one user, so I simulated the occupied name with a file instead of a second Unix user.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

https://claude.ai/code/session_01HfXsWoKF5h7tmdmyUEw1rD

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

muti user can't run at linux [EEXIST: file already exists, mkdir '/tmp/opencode']

1 participant