Repository navigation
Description
Summary
resolveGbrainBin() probes gbrain --version under a 2 s budget on POSIX. When that expires it
returns null, and freshClassify() reports no-cli — "gbrain CLI not on PATH". But no-cli is
not in --is-ok's accept list, while timeout is (added deliberately in #1964 for "a
slow-but-healthy engine"). So a slow version probe bypasses the very protection #1964 added, and
./setup silently suppresses every brain-aware block.
This is the same family as #1792 / #1964 / #2194 / #2456 / #2499, but one step earlier: those all
concern classifying the gbrain sources list probe. This one never reaches that probe.
Why 2 s is not enough for a bun-shim install
lib/gbrain-local-status.ts:263-266:
// On Windows the shim is `gbrain.cmd` → `bun run cli.ts`; a cold spawn can
// exceed 2s, and a false negative here poisons the 60s status cache with
// "no-cli". Give the shim headroom; POSIX keeps the tight timeout.
const VERSION_PROBE_TIMEOUT_MS = NEEDS_SHELL_ON_WINDOWS ? 10_000 : 2_000;The comment already names the exact failure — for Windows. But a bun install -g from source puts a
#!/usr/bin/env bun shim on POSIX too, executing TypeScript rather than a compiled binary. The
assumption "POSIX ⇒ native ⇒ fast" does not hold there.
Measured on a 2-vCPU aarch64 host, gbrain 0.47.3.0 installed as a bun shim (~/.bun/bin/gbrain →
src/cli.ts):
gbrain --version, 5 runs at load 2.4 |
774, 783, 789, 801, 899 ms |
| POSIX budget | 2 000 ms |
| Margin | ~2.3× |
./setup renders 62 skills before it probes, saturating both vCPUs — the machine was at load 4.7
during the upgrade that triggered this. A 2.3× slowdown under the load setup itself creates is not
an exotic condition.
Reproduction
Put a shim first on PATH that slows only --version, leaving the real CLI healthy:
cat > /tmp/slow/gbrain <<'SH'
#!/usr/bin/env bash
case "$1" in --version) sleep 3 ;; esac
exec "$HOME/.bun/bin/gbrain" "$@"
SH
chmod +x /tmp/slow/gbrain
PATH=/tmp/slow:$PATH gbrain sources list # healthy
PATH=/tmp/slow:$PATH bin/gstack-gbrain-detect # and yet:
PATH=/tmp/slow:$PATH bin/gstack-gbrain-detect --is-ok; echo $?Observed:
gbrain_on_path : false ← it IS on PATH
gbrain_local_status : no-cli
gbrain_doctor_ok : false
--is-ok exit : 1 → brain-aware blocks suppressed
Real-world effect on the 1.69.0.0 → 1.71.0.0 upgrade: ./setup printed the single line
gbrain not detected — brain-aware blocks suppressed, the render went from 10 files carrying
Brain Context Load and 12 carrying Save Results to Brain to 0 and 0, and
~/.gstack/gbrain-detection.json was persisted with gbrain_on_path: false. Re-running
gstack-config gbrain-refresh on a quiet box restored 10/12 immediately. Nothing else surfaced the
loss.
Suggested fix
Distinguish "the probe timed out" from "the binary is absent", so the existing timeout whitelist
covers it. In resolveGbrainBin() the execFileSync catch can check e.code === 'ETIMEDOUT' (or
e.killed) and signal a distinct outcome, which freshClassify() maps to timeout rather than
falling through to no-cli:
// timed out ≠ missing. `--is-ok` already accepts "timeout" (#1964); a slow
// bun-shim `--version` must not be reported as "not installed".
if (e.code === "ETIMEDOUT" || e.killed) return TIMED_OUT;A smaller alternative, if the classification split is unwelcome: detect a script shim
(#!/usr/bin/env bun / a non-ELF first line) and grant it the same 10 s headroom Windows already
gets. That keeps the tight budget for genuinely native installs.
Either way, no-cli should mean "not on PATH" and nothing else — the label is what makes this
silent, because it is the one status the whitelist cannot forgive.
Suggested test
test/gbrain-local-status.test.ts already has "returns 'no-cli' when gbrain is not on PATH". A
sibling asserting that a slow but present CLI classifies as timeout (and that --is-ok exits
0) would pin the distinction.
Activity
v1.78.0.0 fix: the two-red-lanes wave — AUQ collapse rooted, OSV gree…