Two shell helpers still read ~/.gbrain/config.json and ignore GBRAIN_HOME (follow-up to #2521)
What happened
When GBRAIN_HOME is set, gbrain keeps its config at $GBRAIN_HOME/.gbrain/config.json. gbrain's configDir() appends .gbrain to the override (src/core/config.ts:1973-1985 at gbrain 752ecbd0), and docs/architecture/topologies.md:262-265 documents setting GBRAIN_HOME per worktree. #2521 moved gstack's config reads to that contract. lib/gbrain-exec.ts:86-88 now says "Every gstack-side gbrain-config read MUST resolve through this helper", and bin/gstack-skill-start:445-450 follows the same rule. Two shell helpers on main (4414f4cc) still hard-code $HOME/.gbrain/config.json:
bin/gstack-skill-start:394sets_GBRAIN_CONFIG="$HOME/.gbrain/config.json". Lines 395-414 print the/sync-gbraincontext-load hint ("GBrain configured…" or "…this worktree isn't pinned yet") only when that file exists. Take an install whose config is underGBRAIN_HOME, with nothing at~/.gbrain. The preamble prints no hint there, thoughgbrainis on PATH and configured. Line 450 of the same script already reads"${GBRAIN_HOME:-$HOME}/.gbrain/config.json".bin/gstack-gbrain-source-wireup:58setsGBRAIN_CONFIG="$HOME/.gbrain/config.json". Lines 104-119 use it for the URL lock: the script reads the file'sdatabase_urland exports it asGBRAIN_DATABASE_URLfor every childgbraincall. Line 351 uses it for the ZeroEntropy advisory (#2365). The header at lines 30-37 says the lock exists so that a config rewrite "can't redirect us at a different brain mid-stream". gbrain lets a setGBRAIN_DATABASE_URLoverride the file'sdatabase_url(config.ts:683, merge at:748-753).- When
~/.gbrain/config.jsonis absent and both URL variables are empty, no URL is captured and the advisory's check is silent. gbrain then uses theGBRAIN_HOMEconfig. - Now put a second brain's config, one with a
database_url, at~/.gbrain. The lock exports that URL, and the wireup's database calls (sources list,sources add,sync) go to that brain. Without adatabase_urlthere, the same calls go to theGBRAIN_HOMEbrain. So the target depends on a fileGBRAIN_HOMEwas meant to override. - The split-topology guide (
topologies.md:274-276) places the artifact brain at the default config withGBRAIN_HOMEunset. The helper mixes the default config's URL with an inheritedGBRAIN_HOMEconfig. Should callers clearGBRAIN_HOME, or should the helper honor it throughout?lib/gbrain-sources.ts(its header says it mirrors this helper) passes the caller-supplied environment unchanged, or inherits the process environment when none is supplied, and selects cwd throughgbrainChildCwd. It does not itself read~/.gbrain/config.json. - This branch is the documented path:
setup-gbrain/SKILL.md:498runs the helper with both URL variables emptied. The other callers (gstack-brain-restore:247, the dailygstack-brain-sync --advance-onlyat:1247, the v1.17.0.0 migration) set no URL variable themselves.
- When
Expected: both helpers use the parent-directory convention that line 450 of gstack-skill-start already uses, ${GBRAIN_HOME:-$HOME}/.gbrain/config.json. For a valid absolute GBRAIN_HOME without surrounding whitespace, this matches gbrain's configDir(). gbrain also trims whitespace and validates the value; the shell form does not.
Scope: I checked these two shell helpers only. I did not audit TypeScript or skill prose; lib/checks.ts:166 and setup-gbrain/sections/brain-init.md:217 show the same $HOME/.gbrain pattern.
Steps to reproduce
The hint (1). Run this from a gstack checkout at 4414f4cc whose toplevel has no .gbrain-source. Set GBRAIN_HOME to a directory that holds .gbrain/config.json, have gbrain on PATH, and leave ~/.gbrain absent:
S=$(mktemp -d)
sed -n 394,414p bin/gstack-skill-start > "$S/asis.sh"
sed '1s|.*|_GBRAIN_CONFIG="${GBRAIN_HOME:-$HOME}/.gbrain/config.json"|' "$S/asis.sh" > "$S/fixed.sh"
bash "$S/asis.sh" # prints nothing
bash "$S/fixed.sh" # GBrain configured but this worktree isn't pinned yet. Run `/sync-gbrain --full` ...
env -u GBRAIN_HOME bash "$S/fixed.sh" # prints nothing: unset GBRAIN_HOME still means ~/.gbrain
On the same install, the full preamble (gstack-skill-start --skill gstack --model claude) prints no GBrain configured line.
The URL lock (2), with two synthetic configs. The snippet makes no database call; it shows that the helper exports brain_a's URL while GBRAIN_HOME names the config with brain_b. A child gbrain that inherits that URL uses it over the GBRAIN_HOME config's database_url (config.ts:683, :748-753).
T=$(mktemp -d); mkdir -p "$T/home/.gbrain" "$T/b/.gbrain"
echo '{"engine":"postgres","database_url":"postgresql://localhost/brain_a"}' > "$T/home/.gbrain/config.json"
echo '{"engine":"postgres","database_url":"postgresql://localhost/brain_b"}' > "$T/b/.gbrain/config.json"
{ echo 'warn(){ echo "WARN: $*" >&2; }'
sed -n 58p bin/gstack-gbrain-source-wireup
sed -n 97,125p bin/gstack-gbrain-source-wireup
echo 'echo "$GBRAIN_DATABASE_URL"'; } > "$T/lock.sh"
env -i PATH="$PATH" HOME="$T/home" GBRAIN_HOME="$T/b" bash "$T/lock.sh"
# postgresql://localhost/brain_a
Readiness report
The doctor output has no gbrain row. Complete output, with the home directory shortened to ~ and the project path replaced:
gstack doctor 1.99.2.0
ok install root ~/.claude/skills/gstack: claude global current (1.99.2.0), agy global current (1.99.2.0), codex global current (1.99.2.0)
ok rescue refs none in ~/.claude/skills/gstack
ok state root ~/.gstack durable=yes (selected by default)
ok bun 1.4.4 at /usr/local/bin/bun (floor 1.3.3, tested 1.4.2)
ok hooks 15 hook(s) parse
ok codex codex-cli 0.160.1; self-locate ok; model gpt-6.1-sol (source: GSTACK_CODEX_MODEL)
ok codex probe cached MODEL_OK, 2h ago (not re-run; --live probes now)
ok artifacts sync status ok (mode full; queue 0)
ok browse bundle browse/dist built
ok binaries find-browse, design, pdf, gstack-global-discover launch (4 of 4)
ok cso native helper 1.99.2.0 (bc858ffc659b)
ok claude code 2.1.309 (Claude Code) at /usr/local/bin/claude
ok session journal largest of 1: 17.1 MiB
ok guard log 97 decisions (5 denied)
ok CLAUDE.md no gstack section lists skills (~/.claude/CLAUDE.md, <project>/CLAUDE.md)
15 ok, 0 warn, 0 not configured, 0 fail
Environment
- Host: Claude Code 2.1.309
- OS: Linux 7.0 (container)
- gstack 1.99.2.0 (
bc858ffc). Both files have the same blob SHAs as onmain4414f4cc. - gbrain 0.60.675.0. The
configDir()contract above is cited from gbrainmaster752ecbd0. GBRAIN_HOMEis set to a directory outside$HOME; there is no~/.gbrain.- Related:
- #2521 (closed). Released in v1.67.0.0 through #2604, which changed
bin/gstack-gbrain-detect,bin/gstack-gbrain-installand thelib/readers. - #2306 (closed PR) changed
bin/gstack-gbrain-detect,lib/gbrain-exec.tsandlib/gbrain-local-status.ts. - Neither touched these two helpers.
- #2521 (closed). Released in v1.67.0.0 through #2604, which changed
Suggested fix, a one-line change in each helper:
-_GBRAIN_CONFIG="$HOME/.gbrain/config.json"
+_GBRAIN_CONFIG="${GBRAIN_HOME:-$HOME}/.gbrain/config.json"
The same change applies to GBRAIN_CONFIG= in gstack-gbrain-source-wireup, and its header comment at lines 30-37 names the path too. test/gstack-gbrain-source-wireup.test.ts runs with a hermetic env that has no GBRAIN_HOME (lines 136-143), so its current cases keep passing. A case that sets GBRAIN_HOME and puts a decoy ~/.gbrain/config.json in place would pin the fix.
Validation parity with gbrain's trim, absolute-path and .. checks (config.ts:1976-1984) is outside this change.
Thanks for the report and the patch. This is fixed on main by #4343 (merged as 43c815be), which rebuilt the change from #4326 with credit to its author. gstack's helpers now resolve gbrain's config through GBRAIN_HOME the same way gbrain does, and gstack-gbrain-source-wireup --check-target reports whether a past wireup could have targeted the other brain. It reaches the stable channel in the next release.