Repository navigation
fix(exec): read a tool's version without leaving its data folders in the member's home - #1895
Conversation
…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
|
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 Review was read-only; I did not run, build, or install PR code. |
SaulMoro
left a comment
There was a problem hiding this comment.
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.tsandconfined-launch.ts, the three new cases fail. The two home checks fail withexpected [ '.cache', '.local' ] to deeply equal [], and theprobeVersioncase fails because the helper doesn't exist yet. With this head,opencode-version,tool-launch-confined,exec,agent-session-find,agent-session-copyandpackages/tool-opencodepass (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 pullandteamai doctor. Afterwards~/.local/share/opencode,~/.cache/opencodeand~/.local/state/opencodeare 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 ishome/.teamai/team-hooks, and main leaves it too, as you say. - All four sites from #1888 are covered, including the session adapter's
cli()throughProcesses.probeVersion. KeepingProcesses.probefor the Codex reader's own arguments and home is right. - A failed
mkdtempanswers empty instead of throwing, which matchesprobeBinary's contract and is safe withopencodeMajorVersioncaching 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.
probeVersionpointsXDG_DATA_HOME,XDG_CACHE_HOMEandXDG_STATE_HOMEat 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_HOMEwon'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
opencodefamily, 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.
Summary
Reading a tool's version no longer leaves OpenCode's data, cache and state folders in the member's home.
probeVersionin@teamai/shared/execruns<binary> --versionlikeprobeBinary, with the caller's env and cwd, but withXDG_DATA_HOME,XDG_CACHE_HOMEandXDG_STATE_HOMEin a temporary directory it removes afterwards. It answers empty instead of throwing, asprobeBinarydoes. The four sites from the issue use it:confinedToolLevel,levelReached,opencodeMajorVersion, and the OpenCode session adapter through a newProcesses.probeVersion(Processes.probestays as it is, because the Codex reader intool-core/formats/codex.tsprobes through it with its own arguments and home).Type of Change
Test Plan
npx tsc --noEmitpassesnpm run lintpasses (on Linux; on my Windows machinefamily-factsreports the same errors onmain, which look path-separator related)npx vitest run <test files>)Tests, on an
ubuntu-latestrunner on my fork (Node 22),npx vitest runoveropencode-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-copyandpackages/tool-opencode,runtime-tools,shared,tool-core,tool-codex:mainwith only the new tests and the updated fake brought in: 2 failed, the two new cases, each withAssertionError: 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 scratchHOME:opencode-version.test.ts:opencodeMajorVersionreads the version and the home stays empty.tool-launch-confined.test.ts:confinedOffersoffers 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, sosetFakeOpencodeVersionis gone and the OpenCode 1 cases inagent-session-findandagent-session-copyput a fake that prints that version onPATHinstead. These test files are not inwindows-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:main,Build d1b252804f41, teamai 0.22.0, sha256 038c2852ae17: all three folders PRESENT in the world's HOME after init and doctor.Build aa37ed68764d, teamai 0.22.0, sha256 1d356c763b87: all three absent. Init and doctor report the same checks as onmain.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 withLedger: 1 LEAK, the same line onmainand 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,codexandcodebuddywere not on that runner's PATH, so nothing here is claimed for them.Related Issues
Fixes #1888
Notes for Reviewers
--versionprobes changed. Other--versionprobes (codex-trust.ts,pkg/env-detect.ts, the tooldetect.tsfiles) still useprobeBinary; the issue names OpenCode's.probeVersionremoves its directory withmaxRetriesand 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 (opencodeMajorVersioncaches the promise).