Repository navigation
fix(workspace): skip $HOME from findWorkspace walk-up + saved-root fallback - #1538
Conversation
…llback
A stray `~/.genie/workspace.json` (from a misfired `genie init` run from
$HOME, or carried over during ops) hijacked workspace detection: every
cwd whose walk-up traversed HOME resolved as a workspace rooted at HOME,
then `scanAgents` looked for `$HOME/agents/` (which does not exist) and
the TUI sidebar silently surfaced "Agents 0/0" — no error, no log, the
operator's left menu was just empty.
Observed in production 2026-04-29 after a full day of debugging chasing
phantom `kind`-discriminator regressions, environment drift, and stale
binaries. The actual culprit was `~/.genie/workspace.json` (created
months ago, forgotten) sitting next to `config.json`/`logs/`/`data/`
in genie's GLOBAL config dir. Walk-up cannot distinguish that from a
real workspace marker because the marker is just a JSON file.
Fix: in both walk-up and saved-root fallback, refuse to honor `$HOME`
as a workspace root. `~/.genie/` is genie's CONFIG home (daemon socket,
logs, saved workspace root, version files), never a workspace.
Refactor: `findWorkspace` accepts an optional `{ userHome }` opts arg
for testability — `homedir()` in some Bun builds caches at process
start and does not respond to `process.env.HOME` mutation, which makes
the regression test impossible to express via env alone.
Tests:
- skips $HOME as workspace root even when $HOME/.genie/workspace.json exists
- refuses saved root that points to $HOME
- does NOT skip legitimate non-$HOME workspace markers (over-zealous-fix guard)
17 pass / 0 fail. Typecheck clean. No public API change — `userHome` is
opts-only and defaults to `homedir()`.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4cac84b985
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // the silent "Agents 0/0" / "no agents in left menu" bug — observed on | ||
| // 2026-04-29 (issue #<TODO> — root-caused via /proc env inspection; | ||
| // user's TUI showed empty sidebar despite 10 canonical agents on disk). | ||
| if (current !== userHome) { |
There was a problem hiding this comment.
Canonicalize home path before skip check
The new guard compares current and userHome as raw strings, so it can be bypassed when the same home directory is represented by a different path form (for example, a symlinked home path or case-variant path on case-insensitive filesystems). In that case existsSync(join(current, WORKSPACE_MARKER)) still hits the same ~/.genie/workspace.json, and the function can continue returning home as a workspace root, which means the reported sidebar/agent-resolution bug is not fully fixed in those environments.
Useful? React with 👍 / 👎.
Summary
A stray `~/.genie/workspace.json` hijacks workspace detection: every cwd whose walk-up traverses $HOME resolves as a workspace rooted at $HOME, `scanAgents` then looks for `$HOME/agents/` (which doesn't exist), and the TUI sidebar silently shows Agents 0/0 — no error, no log, the operator's left menu is just empty.
`~/.genie/` is genie's GLOBAL config dir (daemon socket, logs, saved workspace root, version files), never a workspace. `findWorkspace` should refuse to honor it.
Repro (without this fix)
```bash
echo '{"name":"oops"}' > ~/.genie/workspace.json
cd /home/me # or any path whose walk-up traverses $HOME
genie # TUI sidebar shows "Agents 0/0", no canonical agents listed
```
Root-causing this took a day
Observed in production 2026-04-29. The phantom symptom (`Agents 0/0` after PR #1447 landed the `kind` discriminator) was attributed to a regression in the new TUI render path. Multiple investigation cycles, version bumps (.12 → .29), an attempted dispatch of a fix-engineer team — all chasing the wrong tree.
The actual culprit (`~/.genie/workspace.json` planted months ago, forgotten) was identified by inspecting the live TUI process's `/proc//environ` and finding `GENIE_TUI_WORKSPACE=/home/genie` (instead of `/home/genie/workspace`). Walk-up could not distinguish a real workspace marker from a stale config-dir file.
Fix
In both branches of `findWorkspace`:
`findWorkspace` accepts an optional `{ userHome }` opts arg for testability — `homedir()` in Bun caches at process start and does not respond to `process.env.HOME` mutation, which makes the regression test impossible via env alone. Public API unchanged; `userHome` defaults to `homedir()`.
Test plan
Files
No `.docs-vendor` or other unrelated changes.