Skip to content

fix(gbrain): strip leaked db env for PGLite probes - #1931

Closed
maxpetrusenkoagent wants to merge 2 commits into
garrytan:mainfrom
maxpetrusenkoagent:hermes/oss-pr-2026-06-09-gstack-1917-fork
Closed

maxpetrusenkoagent wants to merge 2 commits into
garrytan:mainfrom
maxpetrusenkoagent:hermes/oss-pr-2026-06-09-gstack-1917-fork

Conversation

@maxpetrusenkoagent

Copy link
Copy Markdown
Contributor

Summaryn- strip leaked DATABASE_URL values when a PGLite gbrain config has no database_urln- keep explicit config database_url and GSTACK_RESPECT_ENV_DATABASE_URL behavior unchangedn- add regressions for buildGbrainEnv and local status probingnnFixes #1917.nn## Verificationn- bun test test/build-gbrain-env.test.ts test/gbrain-local-status.test.tsnn## Notesn- Branch is based on the fork main because the agent token lacks GitHub workflow scope for pushing upstream workflow history changes.n

PGLite configs may have no database_url to seed, so buildGbrainEnv used to pass through caller DATABASE_URL values loaded from a project .env. That made gbrain probes try an unrelated app DB and falsely classify healthy local brains as broken-db.

When config indicates local PGLite and has no database_url, drop DATABASE_URL and GBRAIN_DATABASE_URL unless GSTACK_RESPECT_ENV_DATABASE_URL=1 is set. Add regression coverage at the env helper and local-status probe layers.

Closes garrytan#1917
@trunk-io

trunk-io Bot commented Jun 9, 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

@maxpetrusenkoagent

Copy link
Copy Markdown
Contributor Author

Autoreview: CLEANnnVerified:n- bun test test/build-gbrain-env.test.ts test/gbrain-local-status.test.tsn

@garrytan garrytan left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against main. Correct fix for #1917, well-tested.

Verified:

  • The PGLite-config branch strips both DATABASE_URL and GBRAIN_DATABASE_URL so Bun's project .env autoload can't make the probe hit an unrelated app database and misclassify a healthy file-backed brain as broken-db. The engine === "pglite" || database_path detection covers both config shapes.
  • The GSTACK_RESPECT_ENV_DATABASE_URL=1 opt-out still works (early return precedes the strip), and the legacy no-signal config keeps today's pass-through behavior — the regression test rewrite makes that explicit.
  • The fail-on-database-url fake-gbrain behavior is a nice direct proof of the leak path.

Coordination note (no action needed from you): the fix-wave PR from garrytan/triage-high-priority-prs touches the same neighborhoods — it removes the GBRAIN_PREPARE auto-set block just below your hunk in lib/gbrain-exec.ts (#1965) and extends the same makeEnv/makeFakeGbrainScript unions in test/gbrain-local-status.test.ts (a "slow" behavior for #1964). Whichever lands second has small mechanical conflicts; resolution keeps both sides. One heads-up for the docblock: the wave deletes the "sets GBRAIN_PREPARE=true" paragraph your hunk sits next to — keep the wave's version of that paragraph, your PGLite paragraph above it.

Thanks — this closes #1917.

@maxpetrusenkoagent
maxpetrusenkoagent marked this pull request as draft June 19, 2026 17:56
@time-attack

time-attack commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

@maxpetrusenkoagent Rewrite this against current main and validate the current GBrain configuration paths. The environment cleanup is still needed, but this branch conflicts and is far behind.

@capy-ai

capy-ai Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Thank you, @maxpetrusenkoagent. Your fix is folded into v1.91.19.0 (#3025), which is now merged, and you're credited as a co-author on the release commit and in the CHANGELOG. Closing this PR because the change is on main now.

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.

3 participants