Repository navigation
Description
Summary
brain-aware planning (v1.52) advertises support for "any thin-client MCP" brain, but the
classifier lib/gbrain-local-status.ts freshClassify() probes via gbrain sources list --json — a local-DB-only command. Under thin-client mode this is intentionally not
routable, so the probe throws, the catch falls through to the defensive broken-config
default, and gen-skill-docs --respect-detection suppresses every brain block. A healthy
thin-client brain therefore never gets brain-aware planning.
Environment
- gstack
v1.52.1.0(currentmain,070722a) - gbrain
0.41.28.0, thin-client mode (remote MCP over HTTP; no local DB) - Cause is OS-independent (first hit on Windows, but not platform-specific)
Reproduction
- Configure gbrain as a thin-client (remote
mcp_url, no local engine). Doctor is healthy:
gbrain doctor --json --fast→{"mode":"thin-client","status":"ok",...} - The probe command is refused by design:
$ gbrain sources list --json `gbrain sources` is not routable. sources commands manage local DB + config rows. Per-subcommand thin-client routing lands in v0.31.x. For now: use `sources_list` / `sources_status` MCP tools, or run on the host. (exit 1) gstack-config gbrain-refresh→~/.gstack/gbrain-detection.jsonshows
"gbrain_doctor_ok": true, "gbrain_mcp_mode": "remote-http", "gbrain_local_status": "broken-config"
(healthy thin-client, yetbroken-config).bun run gen:skill-docs:user→ planning SKILL.md files contain no brain blocks
(gen-skill-docs.ts:50un-suppresses only whengbrain_local_status === 'ok').
Root cause
In lib/gbrain-local-status.ts freshClassify(), once the on-PATH check (L224) and
config-exists check (L227) pass — both true for a thin-client — it probes with
execFileSync("gbrain", ["sources","list","--json"]) (L239). gbrain sources is local-DB-only
and explicitly not routable in thin-client mode, so the call throws; the stderr matches neither
"Cannot connect to database" nor "config.json", hitting the defensive broken-config
default (L260). The 5-state enum has no healthy-thin-client path and freshClassify never
checks the mode.
Suggested fix
Detect thin-client mode before the sources list probe and treat a healthy thin-client as
ok. The signal already exists: gbrain doctor --json --fast returns mode: "thin-client" +
status: ok|warnings, and detect already calls it in detectDoctor() (bin/gstack-gbrain-detect
:121) — the mode field is one parse away. detectMcpMode() independently returns remote-http
too. e.g. in freshClassify: if doctor reports thin-client mode and ok/warnings status, return
"ok" without running the host/local-DB-only sources list probe.
Workaround (until fixed)
Override detection externally, no gstack edits: confirm health via gbrain doctor, then write
"gbrain_local_status": "ok" into ~/.gstack/gbrain-detection.json (keeping the other real
detect fields) and run bun run gen:skill-docs:user. Must be re-run after every ./setup or
gstack-config gbrain-refresh, since both rewrite detection.json from the broken probe.
Secondary (minor)
scripts/resolvers/gbrain.ts generateGBrainContextLoad tells the agent to run
gbrain get_page "<slug>", but the thin-client CLI has no get_page subcommand
(Unknown command: get_page); the CLI verb is gbrain get. (get_page is the MCP op name.)
Activity
Rahgnoruk commentedon May 31, 2026
Adding a second variant that hits the same defensive
broken-configdefault — different trigger from the thin-client case, same fail-mode worth covering in the fix.Environment
connection,pgvector,pgbouncer_prepare,rls,schema_version,embeddings,graph_coverage)gbrain sources list --jsonworks manually — returns valid JSON with 594 indexed pagesReproduction (cold-start cache poisoning)
/sync-gbrain. First probe ofgbrain sources list --json(lib/gbrain-local-status.ts:239) hits cold pooler → fails with timeout / connection-reset stderr that matches neither"Cannot connect to database"nor"config.json"broken-config, cache writes (L197-211) with 60s TTL/sync-gbrainStep 1.5 seesbroken-config→ STOPok. Same call, same env, same config — only difference is cache TTL elapsedIn my run the actual cause never surfaced upstream because the catch block on L246-261 swallows the stderr; the user only sees
"broken-config"with no indication it's transient.Why the existing thin-client fix doesn't cover this
The OP's suggested fix (detect thin-client mode via
doctor --json --fastmode: thin-clientand returnok) won't help here — doctor reports the SAMEmode: postgres, status: okwhether the pooler is hot or cold. The variance is purely in thesources listprobe's execution-time outcome, not in any persistent config.Suggested extension to the fix
In addition to the thin-client mode short-circuit, treat transient failures distinctly from terminal config errors:
Alternative (simpler): don't cache failures at all — only cache
okresults. A re-probe on every error path is ~80ms cost, and avoids ever poisoning the cache from a one-off transient.Workaround
Same as the OP's:
rm ~/.gstack/.gbrain-local-status-cache.jsonafter a transient failure. But because the trigger is non-deterministic (cold pooler), users can't tell ahead of time whether they need to clear it — manifests as/sync-gbrainfailing the first time after an idle period, succeeding on retry.shandutta commentedon Jun 1, 2026
Additional topology where this reproduces: Mac Mini agents using the canonical DevBox GBrain over stdio MCP, with no local Mac GBrain DB by design.
Setup:
ssh -T -o BatchMode=yes devbox gbrain serve~/.codex/config.tomlgbrainCLI may be installed for version/update compatibility, but~/.gbrain/config.jsonis intentionally absent to avoid split-brain stateObserved detection shape:
{ "gbrain_mcp_mode": "local-stdio", "gbrain_local_status": "missing-config" }or, when the local CLI probe times out, the same healthy MCP server can appear as:
{ "gbrain_mcp_mode": "local-stdio", "gbrain_local_status": "no-cli" }In both cases, the brain is actually reachable through MCP, but
scripts/gen-skill-docs.ts --respect-detectiononly un-suppressesGBRAIN_CONTEXT_LOAD/GBRAIN_SAVE_RESULTSwhengbrain_local_status === "ok". That keeps brain-aware blocks suppressed for a valid remote-brain topology.Local patch we are carrying on the Mac Mini:
gbrain_mcp_mode === "local-stdio" || "remote-http"as detected for skill-doc generation.setup, use the same MCP-aware predicate before runninggen:skill-docs:user.--hostrather than hard-coding Claude, so Codex gets the same brain-aware generated skills.Important distinction: this should only enable brain-aware context/load/save prompt blocks. Local DB operations such as
/sync-gbrainshould still be gated on real local engine health, not merely MCP presence.jbetala7 commentedon Jun 1, 2026
Opened #1832 with a fix. On the not-routable failure path,
freshClassify()now confirms health viagbrain doctor --json --fastand returnsokwhen doctor reportsmode: thin-clientwithok/warnings— so a healthy thin-client keeps its brain blocks instead of defaulting tobroken-config. Doctor is only consulted when the local-DBsources listprobe is refused, so the local-DB hot path is unaffected, and an unconfirmed/unhealthy brain still falls through to the defensive default. Added two gate-tier tests covering the healthy and unhealthy thin-client cases.xaviroblessarries commentedon Jun 2, 2026
Adding a second, distinct fail-mode to this thread — same root theme ("the detector assumes the literal name
gbrain+ a local-DB topology"), and it sits naturally next to shandutta's mode-aware proposal above. Verified on gstack v1.55.0.0.Bug A (this issue) is the
freshClassifysources listprobe inlib/gbrain-local-status.ts:241, which falls to the defensivereturn "broken-config"at :263 on a thin-client (thegbrain sources is not routablestderr matches neither "Cannot connect to database" nor "config.json"). PR #1832 fixes that path via agbrain doctor --json --fastshort-circuit. That looks right and I support it.Bug B is separate and PR #1832 does not touch it:
detectMcpMode()inbin/gstack-gbrain-detecthardcodes the literal MCP server namegbrainacross all three tiers:claude mcp get gbrain --json(line 153)/^gbrain:/(line 175)cj?.mcpServers?.gbrain(line 186)A brain registered under any other MCP name (mine is registered under a non-
gbrainname) misses all three tiers, andgbrain_mcp_modereturns"none"even when the brain is healthy and connected.test/gstack-gbrain-detect-mcp-mode.test.tsconfirms the assumption — its mock only fakesmcp get gbrain,gbrain:, andmcpServers.gbrain.Impact: today this is latent, because the suppression gate keys on
gbrain_local_status === "ok"(scripts/gen-skill-docs.ts:50,loadGbrainOverride), not ongbrain_mcp_mode. So it is Bug A that strips the brain-aware blocks on localgen:skill-docsregeneration right now. But Bug B blocks the obvious mode-based remedy (shandutta'smcp_mode ∈ {local-stdio, remote-http} ⇒ detectedpredicate) and any future MCP-presence-based gating, because the predicate would still be reading from a name-matched lookup that misses non-gbrainservers. (The checked-in SKILL.md files already carry the brain-aware blocks, so this is local-regen-only, not a runtime planning loss — cosmetically wrong, not load-bearing today.)Suggested fix (folding into #1832 or a follow-up):
detectMcpMode(), stop matching the literal server name. Detect the brain MCP by capability/connection, not by name: resolve the configured server name from gbrain config, accept a candidate set, or (simplest) treat a healthyremote-http/thin-clientdoctorresult as authoritative for "brain present" independent of the MCP entry's name.mcp_mode ∈ {local-stdio, remote-http} ⇒ brain present) for brain-block un-suppression only, while still gating local-DB ops (/sync-gbrain) on real local engine health.scripts/resolvers/gbrain.tstells the agent to rungbrain get_page "<slug>", but the thin-client CLI verb isgbrain get(get_pageis the MCP op name). Worth folding into the same fix.fix(gbrain): treat healthy thin-client as ok in local-status classifier
time-attack commentedon Jul 15, 2026
@lucha0404 Thin-client brains can still be misclassified as broken-config until the selected implementation lands.
fix(gbrain): enforce per-repo deny/read-only policy in sync; typed th…
garrytan commentedon Aug 15, 2026
Verified already fixed on main by the v1.61.0.0 fix wave (
94993f74, #2472) — closing with receipts.lib/gbrain-local-status.tsnow classifies thin clients explicitly: theremote_mcpmarker is checked before thesources listprobe, with a thin-client stderr backstop, so healthy thin-client brains no longer land inbroken-configand brain-aware blocks aren't suppressed.(Audited during fork-port wave 2 planning; see #2577.)