fix(preamble): probe gbrain engine liveness before recommending it#2321
Open
syong wants to merge 1 commit into
Open
fix(preamble): probe gbrain engine liveness before recommending it#2321syong wants to merge 1 commit into
syong wants to merge 1 commit into
Conversation
The gbrain block in every skill preamble checked three things: the config file exists, `gbrain --version` responds, and the worktree has a `.gbrain-source` pin. All three can pass while the engine is unreachable — none of them opens a connection. When the engine is down (disk full, container stopped, pooler unreachable, autopilot wedged), the preamble still printed "Prefer `gbrain search` over Grep", so the agent kept reaching for a tool whose every query fails instead of falling back to Grep. The failure is silent: there is no error surfaced anywhere, and the guidance actively asserts health it never verified. Add a bounded probe (`timeout 5 gbrain sources list`) and branch on it. When it fails, say so and tell the agent to use Grep, pointing at `gbrain doctor --fast` to diagnose. The timeout keeps a hung engine from stalling the preamble of every skill; the probe only runs when a pin is already present, so the non-gbrain path stays free. Verified against a real stopped engine: healthy -> normal guidance, stopped -> DOWN guidance, restarted -> normal guidance.
|
Merging to
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 |
Author
|
/trunk merge |
|
An error occurred while submitting your PR to the queue: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The gbrain block in the skill preamble decides whether to tell the agent "prefer
gbrain searchover Grep". Today it checks three things:~/.gbrain/config.jsonexistsgbrain --versionresponds.gbrain-sourcepinAll three can pass while the engine is completely unreachable — none of them opens a connection. They prove gbrain is installed, not that it works.
So when the engine goes down (disk full, container stopped, pooler unreachable, autopilot wedged), every skill preamble keeps printing:
The agent then reaches for a tool whose every query fails, instead of falling back to Grep. Nothing errors, nothing is surfaced — the guidance actively asserts health it never verified, so the outage is silent and can persist indefinitely.
I hit exactly this: the local Postgres engine was crash-looping on a full Docker disk for well over a day. The preamble recommended gbrain the entire time.
Fix
Add a bounded liveness probe and branch on the result:
When it fails, the preamble now says so and redirects to Grep:
Design notes:
timeout 5means a hung engine can't stall the preamble of every skill. Falls back to an unbounded call only wheretimeoutisn't available (rare on macOS/Linux; the alternative is skipping the check entirely).gbrain doctor --fastrather than assuming any particular backend (PGLite / Postgres / Supabase).sources listper skill invocation.Changes
scripts/resolvers/preamble/generate-brain-sync-block.ts— the actual changeSKILL.mdfiles — regenerated viabun run gen:skill-docsInsertions only; no existing lines modified.
Verification
Tested against a genuinely stopped engine, from a pinned worktree:
gbrain search" guidanceGBrain DOWN+ use Grep + diagnose hint`Also confirmed the unpinned-worktree branch still prints its existing "isn't pinned yet" message and never runs the probe.