fix(gbrain): thin-client state — remote-MCP brains no longer classify as broken-config (#2051)

A thin client (remote-HTTP MCP brain, no local engine by design) probed
`gbrain sources list`, which gbrain's dispatch guard REFUSES on thin clients
(exit 1, no recognized error string), so the classifier fell to its
defensive broken-config default and every suppression gate silently hid
brain-aware blocks from exactly the users on a shared team brain.

New 'thin-client' state, detected PRE-probe from gbrain's own remote_mcp
config marker via the existing gbrainConfigPath() helper (mirrors gbrain's
isThinClient(); honors GBRAIN_HOME; zero network, immune to error-string
drift), with a /thin[- ]client/ stderr backstop in the probe catch. Remote
reachability is deliberately NOT probed by the classifier — that is the
#1964 pathology; gbrain calls degrade gracefully at use time, and the detect
JSON says so honestly (gbrain_thin_client: {probed: false}).

The state is admitted at every suppression gate — gstack-gbrain-detect
--is-ok (drives setup + gbrain-refresh), gen-skill-docs' detection override,
gstack-config gbrain-refresh — while the sync stages (code/memory/dream)
SKIP with an accurate reason: code indexing runs on the brain server, memory
syncs via the remote brain's artifacts pull. The two consumer classes need
opposite answers, which is why this is a distinct state and not a
skip-the-probe special case. sync-gbrain Step 1.5 and setup-gbrain prose
route thin-client to proceed, never into broken-config remediation.

detectMcpMode secondary generalization: url-match against the config's
remote_mcp.mcp_url (deterministic — gbrain mounts at the generic /mcp path)
-> name pattern gbrain[-_]* -> stdio command token; gbrain_mcp_mode stays a
3-value enum.

Tripwires: end-to-end --is-ok exits 0 on a thin-client fixture AND still
exits 1 on broken-config (the gate didn't widen); pre-probe + stderr-fallback
classifier paths; 4 detectMcpMode identification cases incl. a non-matching
url that must NOT false-positive.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-07-09 19:29:37 -07:00
co-authored by Claude Fable 5
parent a7a25aa489
commit e742648eda
9 changed files with 266 additions and 27 deletions
+33 -2
View File
@@ -22,6 +22,12 @@
* Timeout → probe exceeded GSTACK_GBRAIN_PROBE_TIMEOUT_MS (default 15s) with no
* recognized error — engine is likely healthy but slow (e.g. a cold
* pooler connection, #1964). Consumers treat this as usable.
* Thin-client → config carries gbrain's remote_mcp marker (#2051): NO local
* engine by design; queries go to a remote-HTTP MCP brain. Usable
* for brain-aware prose gates; sync stages that need a LOCAL engine
* (code/memory/dream) skip. Remote reachability is verified at USE
* time (gbrain calls degrade gracefully), never by a classifier
* network probe — that's the #1964 pathology.
* Ok → DB reachable, sources list returned valid JSON.
*/
@@ -47,7 +53,8 @@ export type LocalEngineStatus =
| "missing-config"
| "broken-config"
| "broken-db"
| "timeout";
| "timeout"
| "thin-client";
export interface ClassifyOptions {
/** Bypass the 60s cache. Used after any state-mutating operation. */
@@ -258,6 +265,26 @@ function freshClassify(env?: NodeJS.ProcessEnv): LocalEngineStatus {
// 2. Config file present?
if (!existsSync(gbrainConfigPath(env))) return "missing-config";
// 2.5 Thin client? gbrain's own marker (mirrors gbrain isThinClient():
// truthy remote_mcp in config). A thin client has NO local engine — gbrain
// REFUSES `sources` commands on it (THIN_CLIENT_REFUSED_COMMANDS, exit 1
// with no recognized error string), so the probe below would fall to the
// defensive broken-config default and silently suppress brain-aware blocks
// (#2051). Detected PRE-probe from the config file: zero network cost,
// immune to gbrain error-string drift. Remote reachability is deliberately
// NOT probed here — a classifier network probe is the #1964 pathology.
try {
const cfg = JSON.parse(readFileSync(gbrainConfigPath(env), "utf-8")) as {
remote_mcp?: unknown;
};
if (cfg && typeof cfg === "object" && cfg.remote_mcp) {
return "thin-client";
}
} catch {
// Unparseable config: fall through to the probe, whose stderr
// classification surfaces broken-config with the raw error upstream.
}
// 3. Probe gbrain sources list.
//
// Seed DATABASE_URL from ~/.gbrain/config.json (via buildGbrainEnv, the
@@ -288,7 +315,11 @@ function freshClassify(env?: NodeJS.ProcessEnv): LocalEngineStatus {
if (e.code === "ENOENT") return "no-cli";
// Pattern match against gbrain's known error strings. Order matters:
// "Cannot connect to database" is the more specific DB-unreachable signal.
// thin-client refusal first (backstop for a config the pre-probe check
// couldn't read — gbrain's dispatch guard says e.g. "`gbrain sources` is
// not routable ... (thin-client of <url>)"), then the more specific
// DB-unreachable signal.
if (/thin[- ]client/i.test(stderr)) return "thin-client";
if (stderr.includes("Cannot connect to database")) return "broken-db";
if (stderr.includes("config.json")) return "broken-config";