Skip to content

freshClassify health probe uses gbrain sources list, misclassifying healthy thin-client brains as broken-config → brain-aware blocks suppressed #1792

Closed

Description

@lucha0404

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 (current main, 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

  1. Configure gbrain as a thin-client (remote mcp_url, no local engine). Doctor is healthy:
    gbrain doctor --json --fast → {"mode":"thin-client","status":"ok",...}
  2. 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)
    
  3. gstack-config gbrain-refresh → ~/.gstack/gbrain-detection.json shows
    "gbrain_doctor_ok": true, "gbrain_mcp_mode": "remote-http", "gbrain_local_status": "broken-config"
    (healthy thin-client, yet broken-config).
  4. bun run gen:skill-docs:user → planning SKILL.md files contain no brain blocks
    (gen-skill-docs.ts:50 un-suppresses only when gbrain_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

  1. Rahgnoruk commented on May 31, 2026

    @Rahgnoruk

    Adding a second variant that hits the same defensive broken-config default — different trigger from the thin-client case, same fail-mode worth covering in the fix.

    Environment

    • gstack v1.44.0.0 (Windows MSYS bash)
    • gbrain 0.18.2, postgres engine (Supabase pooler, session mode port 5432)
    • Doctor reports OK on every check (connection, pgvector, pgbouncer_prepare, rls, schema_version, embeddings, graph_coverage)
    • gbrain sources list --json works manually — returns valid JSON with 594 indexed pages

    Reproduction (cold-start cache poisoning)

    1. Supabase pooler goes idle (no traffic for ~10+ min)
    2. Run /sync-gbrain. First probe of gbrain 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"
    3. Defensive default at L260 classifies as broken-config, cache writes (L197-211) with 60s TTL
    4. /sync-gbrain Step 1.5 sees broken-config → STOP
    5. Run probe again 1 min later (cache expired, pooler now hot) → returns ok. Same call, same env, same config — only difference is cache TTL elapsed

    In 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 --fast mode: thin-client and return ok) won't help here — doctor reports the SAME mode: postgres, status: ok whether the pooler is hot or cold. The variance is purely in the sources list probe'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:

    } catch (err) {
      const e = err as NodeJS.ErrnoException & { stderr?: Buffer | string };
      const stderr = (e.stderr ? e.stderr.toString() : "") || "";
    
      if (e.code === "ENOENT") return "no-cli";
      if (e.code === "ETIMEDOUT" || e.code === "ECONNRESET" || e.signal === "SIGTERM") {
        // Transient: don't cache, let next call re-probe with a hot connection
        return "ok"; // OR a new "transient-fail" state that bypasses writeCache()
      }
      if (stderr.includes("Cannot connect to database")) return "broken-db";
      if (stderr.includes("config.json")) return "broken-config";
      return "broken-config";
    }

    Alternative (simpler): don't cache failures at all — only cache ok results. 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.json after 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-gbrain failing the first time after an idle period, succeeding on retry.

  2. shandutta commented on Jun 1, 2026

    @shandutta

    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:

    • Claude MCP: ssh -T -o BatchMode=yes devbox gbrain serve
    • Codex MCP: same command in ~/.codex/config.toml
    • local gbrain CLI may be installed for version/update compatibility, but ~/.gbrain/config.json is intentionally absent to avoid split-brain state

    Observed 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-detection only un-suppresses GBRAIN_CONTEXT_LOAD / GBRAIN_SAVE_RESULTS when gbrain_local_status === "ok". That keeps brain-aware blocks suppressed for a valid remote-brain topology.

    Local patch we are carrying on the Mac Mini:

    1. Treat gbrain_mcp_mode === "local-stdio" || "remote-http" as detected for skill-doc generation.
    2. In setup, use the same MCP-aware predicate before running gen:skill-docs:user.
    3. Regenerate for the current --host rather 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-gbrain should still be gated on real local engine health, not merely MCP presence.

  3. jbetala7 commented on Jun 1, 2026

    @jbetala7
    Contributor

    Opened #1832 with a fix. On the not-routable failure path, freshClassify() now confirms health via gbrain doctor --json --fast and returns ok when doctor reports mode: thin-client with ok/warnings — so a healthy thin-client keeps its brain blocks instead of defaulting to broken-config. Doctor is only consulted when the local-DB sources list probe 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.

  4. xaviroblessarries commented on Jun 2, 2026

    @xaviroblessarries

    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 freshClassify sources list probe in lib/gbrain-local-status.ts:241, which falls to the defensive return "broken-config" at :263 on a thin-client (the gbrain sources is not routable stderr matches neither "Cannot connect to database" nor "config.json"). PR #1832 fixes that path via a gbrain doctor --json --fast short-circuit. That looks right and I support it.

    Bug B is separate and PR #1832 does not touch it: detectMcpMode() in bin/gstack-gbrain-detect hardcodes the literal MCP server name gbrain across all three tiers:

    • Tier 1: claude mcp get gbrain --json (line 153)
    • Tier 2: greps /^gbrain:/ (line 175)
    • Tier 3: reads cj?.mcpServers?.gbrain (line 186)

    A brain registered under any other MCP name (mine is registered under a non-gbrain name) misses all three tiers, and gbrain_mcp_mode returns "none" even when the brain is healthy and connected. test/gstack-gbrain-detect-mcp-mode.test.ts confirms the assumption — its mock only fakes mcp get gbrain, gbrain:, and mcpServers.gbrain.

    Impact: today this is latent, because the suppression gate keys on gbrain_local_status === "ok" (scripts/gen-skill-docs.ts:50, loadGbrainOverride), not on gbrain_mcp_mode. So it is Bug A that strips the brain-aware blocks on local gen:skill-docs regeneration right now. But Bug B blocks the obvious mode-based remedy (shandutta's mcp_mode ∈ {local-stdio, remote-http} ⇒ detected predicate) and any future MCP-presence-based gating, because the predicate would still be reading from a name-matched lookup that misses non-gbrain servers. (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):

    1. In 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 healthy remote-http/thin-client doctor result as authoritative for "brain present" independent of the MCP entry's name.
    2. Apply shandutta's predicate (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.
    3. Same-area cleanup the OP flagged: scripts/resolvers/gbrain.ts tells the agent to run gbrain get_page "<slug>", but the thin-client CLI verb is gbrain get (get_page is the MCP op name). Worth folding into the same fix.
  5. added a commit that references this issue on Jun 22, 2026
    4057ddb
  6. time-attack commented on Jul 15, 2026

    @time-attack
    Contributor

    @lucha0404 Thin-client brains can still be misclassified as broken-config until the selected implementation lands.

  7. garrytan commented on Aug 15, 2026

    @garrytan
    Owner

    Verified already fixed on main by the v1.61.0.0 fix wave (94993f74, #2472) — closing with receipts. lib/gbrain-local-status.ts now classifies thin clients explicitly: the remote_mcp marker is checked before the sources list probe, with a thin-client stderr backstop, so healthy thin-client brains no longer land in broken-config and brain-aware blocks aren't suppressed.

    (Audited during fork-port wave 2 planning; see #2577.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions