Skip to content

fix(exec): read a tool's version without leaving its data folders in the member's home - #1895

Merged
SaulMoro merged 1 commit into
Tencent:mainfrom
zuhairkhalid229:fix/1888-probe-version-xdg
Nov 15, 2026
Merged

SaulMoro merged 1 commit into
Tencent:mainfrom
zuhairkhalid229:fix/1888-probe-version-xdg

Conversation

@zuhairkhalid229

Copy link
Copy Markdown
Contributor

Summary

Reading a tool's version no longer leaves OpenCode's data, cache and state folders in the member's home. probeVersion in @teamai/shared/exec runs <binary> --version like probeBinary, with the caller's env and cwd, but with XDG_DATA_HOME, XDG_CACHE_HOME and XDG_STATE_HOME in a temporary directory it removes afterwards. It answers empty instead of throwing, as probeBinary does. The four sites from the issue use it: confinedToolLevel, levelReached, opencodeMajorVersion, and the OpenCode session adapter through a new Processes.probeVersion (Processes.probe stays as it is, because the Codex reader in tool-core/formats/codex.ts probes through it with its own arguments and home).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npm run lint passes (on Linux; on my Windows machine family-facts reports the same errors on main, which look path-separator related)
  • The test files that cover what I changed pass (npx vitest run <test files>)
  • Added/updated tests for the change
  • Runtime change: one real-CLI run in a world (record below)

Tests, on an ubuntu-latest runner on my fork (Node 22), npx vitest run over opencode-version, exec, tool-launch-confined, tool-launch-confined-tools, opencode-hooks, installed-launcher-readiness, mcp-reconcile, session-cmd, doctor-scorers, agent-session-find, agent-session-copy and packages/tool-opencode, runtime-tools, shared, tool-core, tool-codex:

  • this branch: 33 files, 965 passed, 12 skipped
  • main with only the new tests and the updated fake brought in: 2 failed, the two new cases, each with AssertionError: expected [ '.cache', '.local' ] to deeply equal []

The new cases use installFakeOpencode({ makesDataFolders: true }), which makes the three folders on every start as OpenCode does, with a scratch HOME:

  • opencode-version.test.ts: opencodeMajorVersion reads the version and the home stays empty.
  • tool-launch-confined.test.ts: confinedOffers offers OpenCode at both levels and the home stays empty.
  • exec.test.ts: a failing probe answers '' and removes its directory.

The fake used to read a version override from $XDG_DATA_HOME/fake-opencode/version, which the probe no longer sees, so setFakeOpencodeVersion is gone and the OpenCode 1 cases in agent-session-find and agent-session-copy put a fake that prints that version on PATH instead. These test files are not in windows-tests.ts, so Windows CI does not run them.

Real-CLI record, with real OpenCode (npm install -g opencode-ai, 1.19.5) on the same runner, a world built from each branch:

$ npm run -s verify -- teamai <run> init https://teamai.test/team/repo.git --provider git --agent opencode
$ npm run -s verify -- teamai <run> doctor
$ npm run -s verify -- sh <run> sh -c '<is each of $HOME/.local/share/opencode, $HOME/.cache/opencode, $HOME/.local/state/opencode present>'
$ npm run -s verify -- ledger <run>
  • World from main, Build d1b252804f41, teamai 0.22.0, sha256 038c2852ae17: all three folders PRESENT in the world's HOME after init and doctor.
  • World from this branch, Build aa37ed68764d, teamai 0.22.0, sha256 1d356c763b87: all three absent. Init and doctor report the same checks as on main.

Verdict, opencode x git x workspace scope via teamai init + teamai doctor: the observable this PR is about matched (FAILED on main, passed on this branch), but the ledger is not CLEAN in either world. Both end with Ledger: 1 LEAK, the same line on main and on this branch: LEAK home/.teamai/team-hooks left behind, with everything in it. That looks like the uninstall leftovers in #1879 rather than anything this change touches. claude, codex and codebuddy were not on that runner's PATH, so nothing here is claimed for them.

Related Issues

Fixes #1888

Notes for Reviewers

  • Only the --version probes changed. Other --version probes (codex-trust.ts, pkg/env-detect.ts, the tool detect.ts files) still use probeBinary; the issue names OpenCode's.
  • probeVersion removes its directory with maxRetries and ignores a failed removal: on Windows a child the 5 s timeout killed can still hold a file there, and a leftover temp folder should not make the probe throw (opencodeMajorVersion caches the promise).

…the member's home

OpenCode makes its data, cache and state folders on every start, --version
included, so each `opencode --version` probe left ~/.local/share/opencode,
~/.cache/opencode and ~/.local/state/opencode in the member's home on a
machine that never ran OpenCode.

probeVersion in @teamai/shared/exec runs <binary> --version with the
caller's env and cwd, but with XDG_DATA_HOME, XDG_CACHE_HOME and
XDG_STATE_HOME in a temporary directory it removes afterwards, and answers
empty instead of throwing, as probeBinary does. The confined judge probes
(confinedToolLevel, levelReached), opencodeMajorVersion and the OpenCode
session adapter (through Processes.probeVersion) use it.

The fake opencode can no longer read a version override from its data home,
which the probe no longer sees, so the OpenCode 1 session tests install a
fake that prints that version instead.

Fixes Tencent#1888
@github-actions

Copy link
Copy Markdown

No findings in the specified PR diff.

The description documents sufficient testing: failing-on-main regression tests and a representative real-CLI world run at aa37ed68764d. The reported ledger leak also occurs on the base and is not evidence of a regression here.

Review was read-only; I did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Approving at aa37ed6.

What I checked

  • Red on main, green here. With main's exec.ts, confined.ts, session-adapter.ts, opencode-version.ts and confined-launch.ts, the three new cases fail. The two home checks fail with expected [ '.cache', '.local' ] to deeply equal [], and the probeVersion case fails because the helper doesn't exist yet. With this head, opencode-version, tool-launch-confined, exec, agent-session-find, agent-session-copy and packages/tool-opencode pass (203 tests), and typecheck passes.
  • Real CLI on POSIX, with OpenCode on the world's PATH. A fresh world from this head ran teamai init --agent opencode, teamai pull and teamai doctor. Afterwards ~/.local/share/opencode, ~/.cache/opencode and ~/.local/state/opencode are all absent, and doctor's OpenCode checks pass as on main. Main's build leaves all three behind with the same commands. The only uninstall leftover is home/.teamai/team-hooks, and main leaves it too, as you say.
  • All four sites from #1888 are covered, including the session adapter's cli() through Processes.probeVersion. Keeping Processes.probe for the Codex reader's own arguments and home is right.
  • A failed mkdtemp answers empty instead of throwing, which matches probeBinary's contract and is safe with opencodeMajorVersion caching the promise.

Overlap with #1892. #1892 adds the same helper for the first three sites but leaves the session adapter on probeBinary, so this PR is the complete fix for #1888. This one should land, and #1892 is superseded.

[P2 non-blocking]

  • Moving the XDG homes can break a probe through a version-manager shim. probeVersion points XDG_DATA_HOME, XDG_CACHE_HOME and XDG_STATE_HOME at a temp directory for every confined tool's probe, not only OpenCode's. A tool installed through a shim that keeps its installs under $XDG_DATA_HOME won't find them there. mise, for example, defaults its data directory to $XDG_DATA_HOME/mise. The probe then answers empty, and teamai falls back to the assumed OpenCode major and best-effort isolation. Two ways to avoid it:

    • leave the environment alone, note which of OpenCode's three folders are missing before the probe, and remove only those afterwards;
    • redirect only for the opencode family, the one that creates them.

    I couldn't run a shim install here, so this comes from mise's documented defaults, not from a run. It can be a follow-up.

CI review. No findings, and we agree, apart from the P2 above.

Merge risk. Low. Only the version probe's environment changes, and its output is read as before. The test fake no longer reads a version override from the data home, and the two OpenCode 1 cases now put a fake with that version on PATH.

@SaulMoro
SaulMoro merged commit ee4e8d7 into Tencent:main Nov 15, 2026
20 checks passed
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.

Reading OpenCode's version leaves its data, cache and state folders in the member's home

3 participants