Skip to content

fix(gbrain-detect): classify gbrain >= 0.43 held-lock refusal as engine-locked, not broken-config - #2698

Open
pvanl wants to merge 1 commit into
garrytan:mainfrom
pvanl:fix/engine-locked-gbrain-043-message
Open

fix(gbrain-detect): classify gbrain >= 0.43 held-lock refusal as engine-locked, not broken-config#2698
pvanl wants to merge 1 commit into
garrytan:mainfrom
pvanl:fix/engine-locked-gbrain-043-message

Conversation

@pvanl

@pvanl pvanl commented Aug 26, 2026

Copy link
Copy Markdown

What

lib/gbrain-local-status.ts recognizes a held PGLite lock only by the pre-0.43 signature: stderr containing connect timed out or exit code 124 (#2194). Since gbrain 0.43.0.0 the CLI refuses the same case with exit 1 and its own message:

GBrain's local database is already open through gbrain serve (MCP, PID N). This brain uses PGLite, so a separate CLI process cannot open it at the same time. Stop gbrain serve, then retry this CLI command.

That string matches none of the classifier branches, so it falls through to the defensive broken-config default.

Why it matters

broken-config is not cosmetic: Step 1.5 of /setup-gbrain and /sync-gbrain STOP on it and offer remediation that moves a perfectly healthy ~/.gbrain/config.json aside and re-inits the engine. A user who follows that advice wipes a working setup because an MCP serve happened to hold the lock — which is the normal state whenever a Claude Code session with the gbrain MCP is open.

Reproduced live on gbrain 0.43.0.0, 0.44.0.0 and 0.46.30.0: with a serve running, gstack-gbrain-detect reports gbrain_local_status=broken-config; kill the serve and the same untouched config reports ok. Verified the message contains neither config.json nor Cannot connect to database nor connect timed out, so no existing branch can catch it.

Fix

One branch next to the existing #2194 case, matching the stable substring already open through, with identical semantics: engine-locked for pglite, broken-db otherwise.

Tests

Added a fake-gbrain behavior for the 0.43+ refusal (exit 1 + message) and two cases: pglite → engine-locked, postgres → broken-db. Without the lib change both fail on the broken-config fall-through.

bun test test/gbrain-local-status.test.ts
46 pass, 0 fail

Kind regards from Peter's agent, who never sleeps... ツ

🤖 Generated with Claude Code

…ne-locked

gbrain 0.43+ refuses a held PGLite lock with exit 1 and the message
"GBrain's local database is already open through `gbrain serve` (MCP,
PID N)" instead of the pre-0.43 exit 124 + "connect timed out" that
the garrytan#2194 branch matches. The message matches no known pattern, so the
classifier falls through to the defensive broken-config default — and
Step 1.5 of /setup-gbrain and /sync-gbrain then tell the user to move a
perfectly healthy config.json aside and re-init the engine.

Reproduced live on gbrain 0.43.0.0, 0.44.0.0 and 0.46.30.0: with a
serve holding the lock, gstack-gbrain-detect reports
gbrain_local_status=broken-config; after stopping the serve it reports
ok with the same untouched config.

Match on the stable substring "already open through", mirroring the
existing garrytan#2194 branch semantics: engine-locked for pglite, broken-db
otherwise. Adds a fake-gbrain behavior for the 0.43+ refusal plus two
cases (pglite -> engine-locked, postgres -> broken-db).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Aug 26, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant