Skip to content

fix(workspace): skip $HOME from findWorkspace walk-up + saved-root fallback - #1538

Merged
namastex888 merged 1 commit into
devfrom
fix/findworkspace-skip-home-as-workspace-root
Apr 29, 2026
Merged

namastex888 merged 1 commit into
devfrom
fix/findworkspace-skip-home-as-workspace-root

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

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`:

  1. Walk-up — when `current === userHome`, skip the marker check and continue to the parent. `~/.genie/workspace.json` is no longer a valid hit.
  2. Saved-root fallback — refuse to honor a saved `workspaceRoot` that points at $HOME. Any pre-fix run that persisted $HOME (via the now-removed walk-up bug) self-heals: the saved root is rejected, returning `null`, and `saveWorkspaceRoot` will write a real root the next time walk-up succeeds.

`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

  • `bun test src/lib/workspace.test.ts` → 17 pass / 0 fail (3 new tests)
  • `bun run typecheck` → clean
  • CI green
  • Smoke: drop a rogue `~/.genie/workspace.json`, run `genie` from `/home/genie`, confirm sidebar populates from saved real workspace root instead of resolving to $HOME

Files

  • `src/lib/workspace.ts` — fix (+27 -9)
  • `src/lib/workspace.test.ts` — regression coverage (+61)

No `.docs-vendor` or other unrelated changes.

…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()`.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 31f1422d-5139-44e0-a257-eed45d9770b5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/findworkspace-skip-home-as-workspace-root

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@namastex888
namastex888 merged commit f46cbd4 into dev Apr 29, 2026
10 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/lib/workspace.ts
// 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@automagik-genie
automagik-genie deleted the fix/findworkspace-skip-home-as-workspace-root branch September 25, 2026 04:52
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