fix: whitelist engine-locked at all three gbrain-usable gates (#2456)

#2194 taught the classifier to report a PGLite lock held by a live
\`gbrain serve\` as engine-locked instead of broken-config, but none of the
three "is gbrain usable?" gates accepted the new status — so the symptom
moved from a wrong error to a quieter wrong suppression: gbrain-refresh
stripped GBRAIN_CONTEXT_LOAD / GBRAIN_SAVE_RESULTS blocks out of every
generated SKILL.md after every upgrade, on the RECOMMENDED /setup-gbrain
default (PGLite + local-stdio MCP spawns gbrain serve at session start).

engine-locked is the same class as timeout (#1964): the engine is
installed and healthy, a legitimate holder has the lock. All three gates
now agree:

- bin/gstack-gbrain-detect --is-ok exits 0 on engine-locked
- bin/gstack-config gbrain-refresh case arm renders instead of suppressing
- scripts/gen-skill-docs.ts --respect-detection treats it as detected

Test mirrors the existing timeout case in
test/gbrain-detection-override.test.ts (engine-locked renders brain
blocks; the sibling no-cli case still proves suppression works).

Applies the reporter's patch + test from the issue.

Fixes #2456

Co-authored-by: Mateus Moraes <mmoraes@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-08-16 10:01:44 -07:00
co-authored by Mateus Moraes Claude Fable 5
parent 5b65f91a8c
commit f9f3c9801a
4 changed files with 56 additions and 20 deletions
+27
View File
@@ -157,6 +157,33 @@ describe('gbrain detection override → gen-skill-docs', () => {
}
});
test('with status "engine-locked" (PGLite single-writer, #2456), brain blocks render like "ok"', () => {
const { tmpHome, cleanup } = makeFixture(
JSON.stringify({
gbrain_local_status: 'engine-locked',
gbrain_on_path: true,
gbrain_version: 'test-0.42.26',
}),
);
try {
const snap = regenAndSnapshot({
respectDetection: true,
tmpHome,
files: PROBE_FILES,
});
const content = probeUnion(snap);
// PGLite is single-writer: a live `gbrain serve` (the recommended
// /setup-gbrain default spawns one at session start) legitimately owns
// the embedded DB. gbrain is installed and healthy — a transient lock
// must not silently strip brain blocks (same reasoning as "timeout").
expect(content).toContain('## Save Results to Brain');
expect(content).toContain('gbrain put "office-hours/');
} finally {
cleanup();
}
});
test('with detected:false (status != "ok"), brain blocks stay suppressed', () => {
const { tmpHome, cleanup } = makeFixture(
JSON.stringify({ gbrain_local_status: 'no-cli', gbrain_on_path: false, gbrain_version: null }),