Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

persistence: Git-durability seams in effect-git.ts and hardenBrainRepo; git spawns take gitChildEnv (#5182)

garrytan8970ee59d4b3
diff --git a/src/core/brain-repo-durability.ts b/src/core/brain-repo-durability.ts
index da31340346..21ecfd69e8 100644
--- a/src/core/brain-repo-durability.ts
+++ b/src/core/brain-repo-durability.ts
@@ -1,4 +1,4 @@
-import { assertManagedFilesystemWrite } from './persistence/filesystem-guard.ts';
+import { assertManagedFilesystemWrite, hasFilesystemPublication, managedFilesystemRootFor } from './persistence/filesystem-guard.ts';
/**
* brain-repo-durability.ts — auto-harden a brain's git working tree (v0.42.44).
*
@@ -988,6 +988,17 @@ function pullDetail(o: PullOutcome): { status: StepStatus; detail: string } {
* already-hardened repo produces all ok/skipped and NO new commit.
*/
export async function hardenBrainRepo(opts: HardenOpts): Promise<DurabilityReport> {
+ // #5182: a managed canonical worktree gets no hook, cron or helper here — the
+ // owner's recorded git_durability setting decides, and its verb installs
+ // the credential. Name that verb instead of the bare coordinator refusal.
+ const managed = managedFilesystemRootFor(opts.repoPath);
+ if (managed && !hasFilesystemPublication(opts.repoPath)) {
+ const sourceId = managed.sourceId ?? opts.sourceId;
+ throw opError('writer_coordinator_required',
+ `${opts.repoPath} is the managed canonical worktree of source ${sourceId}; its Git durability is an owner setting, not a hook.`,
+ `Run gbrain sources writer git-durability ${sourceId} --enable${opts.pat ? ' --pat-file <path>' : ''} (add --dry-run to preview). The owner commits and pushes page writes itself; no pull cron or post-commit hook is installed on a managed root.`,
+ { fix: readFix('Shows the owner and whether it commits and pushes page writes, read-only.', { argv: ['gbrain', 'sources', 'writer', 'status', sourceId, '--json'] }) });
+ }
if (!opts.dryRun) assertManagedFilesystemWrite(opts.repoPath);
const { sourceId } = opts;
const dryRun = !!opts.dryRun;
diff --git a/src/core/persistence/effect-git.ts b/src/core/persistence/effect-git.ts
index 6ae803b3fa..6e0d6d272f 100644
--- a/src/core/persistence/effect-git.ts
+++ b/src/core/persistence/effect-git.ts
@@ -1,6 +1,8 @@
import { existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, statSync } from 'node:fs';
import { basename, dirname, join, relative, resolve as resolvePath, sep } from 'node:path';
-import { execFileBounded, isDurabilityHardenedAsync } from '../brain-repo-durability.ts';
+import { execFileBounded } from '../brain-repo-durability.ts';
+import { gitDurabilityPolicy } from './git-durability-policy.ts';
+import type { WorktreeBinding } from './ownership.ts';
import { OperationError, opError } from '../ops/contract.ts';
import { readFix } from '../ops/op-fix.ts';
import type { GitCommitNote } from './effect-model.ts';
@@ -225,12 +227,14 @@ export const DURABILITY_NOT_ENABLED = { git: 'skipped', reason: 'durability_not_
/**
* Caller owns the native worktree lock. Never run pull, rebase, or legacy hooks.
- * `hardened` is the caller's durability probe of `root`, taken before it locked
- * the worktree.
+ * `hardened` is the caller's durability verdict for `root`, taken before it
+ * locked the worktree. Without one, the binding's recorded git_durability
+ * decides (#5182): `enabled`/`disabled` never consult the legacy hook probe,
+ * and an unrecorded binding falls back to the probe, fail-closed.
*/
export async function publishGitEffect(root: string, relativePath: string, signal?: AbortSignal,
- hardened?: boolean, note?: GitCommitNote): Promise<Record<string, unknown>> {
- if (!(hardened ?? await isDurabilityHardenedAsync(root))) return { ...DURABILITY_NOT_ENABLED };
+ hardened?: boolean, note?: GitCommitNote, binding?: Pick<WorktreeBinding, 'git_durability'> | null): Promise<Record<string, unknown>> {
+ if (!(hardened ?? (await gitDurabilityPolicy(binding, root)).durable)) return { ...DURABILITY_NOT_ENABLED };
const outcome = (await commitGitTargets(root, [relativePath], signal, note ? new Map([[relativePath, note]]) : undefined)).get(relativePath)!;
if (outcome instanceof OperationError) throw outcome;
if (outcome.reason === 'target_absent') return outcome;
diff --git a/src/core/persistence/git-durability-administration.ts b/src/core/persistence/git-durability-administration.ts
index 5501661959..868d3a14ff 100644
--- a/src/core/persistence/git-durability-administration.ts
+++ b/src/core/persistence/git-durability-administration.ts
@@ -17,6 +17,7 @@ import { join } from 'node:path';
import { execFileBounded } from '../bounded-child-exec.ts';
import { classifyGitCheckout } from '../git-checkout.ts';
import { durableSsrfFlags, GIT_ENV, GIT_ENV_AUTH, GIT_SSRF_SUBCOMMAND_FLAGS } from '../git-remote.ts';
+import { gitChildEnv } from '../git-env.ts';
import { ensureGbrainHome, resolveGbrainHome } from '../gbrain-home.ts';
import { opError } from '../ops/contract.ts';
import { readFix } from '../ops/op-fix.ts';
@@ -59,7 +60,7 @@ export function parseGitDurabilityParams(params: Record<string, unknown>): GitDu
async function git(root: string, args: string[], auth = false): Promise<{ code: number; stdout: string; stderr: string }> {
const { error, stdout, stderr } = await execFileBounded('git', ['-C', root, ...(auth ? durableSsrfFlags() : []), ...args],
- { timeout: GIT_TIMEOUT_MS, maxBuffer: 1024 * 1024, env: { ...process.env, ...GIT_ENV, ...(auth ? GIT_ENV_AUTH : {}), LC_ALL: 'C' } });
+ { timeout: GIT_TIMEOUT_MS, maxBuffer: 1024 * 1024, env: gitChildEnv({ ...GIT_ENV, ...(auth ? GIT_ENV_AUTH : {}), LC_ALL: 'C' }) });
if (error && (error.killed || typeof error.code !== 'number')) throw opError('git_unavailable', 'Git did not finish within its bounded attempt.',
`git ${args[0]} in ${root} did not finish within ${GIT_TIMEOUT_MS / 1000} seconds or could not start; nothing was changed. Check that git runs in that checkout on the brain host, then rerun.`);
return { code: error ? error.code as number : 0, stdout, stderr };