mirror of
https://github.com/garrytan/gstack.git
synced 2026-08-07 23:08:36 +02:00
fix(gbrain-local-status): classifier falsely reports broken-db inside repos with their own DATABASE_URL
The freshClassify probe ran `gbrain sources list --json` with the inherited process env. When the probe ran from inside a repo with its own .env (an app DATABASE_URL on a different port), Bun autoloaded the project's .env, gbrain connected to the wrong database, and the classifier reported broken-db on otherwise-healthy brains. Fix: route the probe env through `buildGbrainEnv` from lib/gbrain-exec, the same helper the sync orchestrator uses. DATABASE_URL is seeded from ~/.gbrain/config.json so the result is cwd-independent. The 60s cache can no longer propagate a poisoned negative to clean directories. Contributed by @jetsetterfl via #1583. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
b84ec551a4
commit
d6b6737ba3
@@ -35,6 +35,7 @@ import {
|
|||||||
} from "fs";
|
} from "fs";
|
||||||
import { homedir } from "os";
|
import { homedir } from "os";
|
||||||
import { dirname, join } from "path";
|
import { dirname, join } from "path";
|
||||||
|
import { buildGbrainEnv } from "./gbrain-exec";
|
||||||
|
|
||||||
export type LocalEngineStatus =
|
export type LocalEngineStatus =
|
||||||
| "ok"
|
| "ok"
|
||||||
@@ -226,12 +227,20 @@ function freshClassify(env?: NodeJS.ProcessEnv): LocalEngineStatus {
|
|||||||
if (!existsSync(gbrainConfigPath())) return "missing-config";
|
if (!existsSync(gbrainConfigPath())) return "missing-config";
|
||||||
|
|
||||||
// 3. Probe gbrain sources list.
|
// 3. Probe gbrain sources list.
|
||||||
|
//
|
||||||
|
// Seed DATABASE_URL from ~/.gbrain/config.json (via buildGbrainEnv, the
|
||||||
|
// same helper the sync orchestrator uses in lib/gbrain-exec.ts). Without
|
||||||
|
// this, Bun autoloads a project's .env when the probe runs inside a repo
|
||||||
|
// that defines its own DATABASE_URL (e.g. an app DB on a different port),
|
||||||
|
// gbrain connects to the wrong DB, and the classifier falsely reports
|
||||||
|
// broken-db. This also makes the result cwd-independent, so the 60s cache
|
||||||
|
// can no longer propagate a poisoned negative to clean directories.
|
||||||
try {
|
try {
|
||||||
execFileSync("gbrain", ["sources", "list", "--json"], {
|
execFileSync("gbrain", ["sources", "list", "--json"], {
|
||||||
encoding: "utf-8",
|
encoding: "utf-8",
|
||||||
timeout: PROBE_TIMEOUT_MS,
|
timeout: PROBE_TIMEOUT_MS,
|
||||||
stdio: ["ignore", "pipe", "pipe"],
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
env: env ?? process.env,
|
env: buildGbrainEnv({ baseEnv: env ?? process.env }),
|
||||||
});
|
});
|
||||||
return "ok";
|
return "ok";
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user