Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

v0.60.21.0 fix(persistence): SIGTERM a stopped git child before SIGKILL so it can release index.lock (#5793)

Garry Tan6fe43935ebe6
diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json
index 7352693055..2f270a191f 100644
--- a/.claude-plugin/plugin.json
+++ b/.claude-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "gbrain",
- "version": "0.60.20.0",
+ "version": "0.60.21.0",
"description": "Personal knowledge brain for your coding agent — hybrid search, synthesis, graph traversal, and durable cross-session memory over Postgres/PGLite with pgvector, plus a curated brain-first skill set.",
"author": {
"name": "Garry Tan",
diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json
index 719e1e3c75..52a5f7779d 100644
--- a/.codex-plugin/plugin.json
+++ b/.codex-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "gbrain",
- "version": "0.60.20.0",
+ "version": "0.60.21.0",
"description": "Personal knowledge brain for your coding agent — hybrid search, synthesis, graph traversal, and durable cross-session memory over Postgres/PGLite with pgvector, plus a curated brain-first skill set.",
"author": {
"name": "Garry Tan",
diff --git a/BOOTSTRAP_FOR_AGENTS.md b/BOOTSTRAP_FOR_AGENTS.md
index 0e276806d2..db34dc8cbf 100644
--- a/BOOTSTRAP_FOR_AGENTS.md
+++ b/BOOTSTRAP_FOR_AGENTS.md
@@ -1,4 +1,4 @@
-<!-- gbrain-runbook-stamp: 0.60.20.0 -->
+<!-- gbrain-runbook-stamp: 0.60.21.0 -->
<!-- This stamp must equal the VERSION file at every release; CI enforces it
(scripts/check-bootstrap-tag.sh). `gbrain bootstrap status` compares it to
the installed binary and warns on skew. -->
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 930b1cf6e3..4432ae9acd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,24 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [0.60.21.0] - 2026-09-30
+
+**A `git` command GBrain stops early no longer leaves your brain repo locked.**
+
+v0.60.16.0 gave every background `git` call a deadline so a lost exit signal can't hang the write queue. When it stopped a command, though, it killed `git` outright. If that happened in the middle of `git add` or `git commit`, git never got to remove its lock file, and every later git call in that repo failed until someone deleted the lock. That showed up as pages stuck in the queue with "git unavailable" after the owner process was shut down or restarted mid-write.
+
+Now GBrain asks `git` to stop first and gives it two seconds to clean up its lock. Only then does it force the kill. The deadline still holds: a `git` that ignores the request is stopped at most two seconds later.
+
+Nothing to configure and nothing to run after upgrading. If you hit this on v0.60.16.0, remove the leftover `.git/index.lock` in your brain repo once.
+
+### To take advantage of v0.60.21.0
+
+`gbrain upgrade` is all you need. There is no migration.
+
+### Itemized changes
+
+- `execFileBounded` (`src/core/brain-repo-durability.ts`) now sends SIGTERM at its deadline or on abort, and escalates to SIGKILL after a 2 second grace period. It still settles from its own timer if the exit event never arrives.
+- `test/bounded-child-exec.test.ts` adds a case where a child holding a lock file removes it on SIGTERM, plus one where a child ignoring SIGTERM is still stopped within the bound.
## [0.60.20.0] - 2026-09-30
**Fix wave 4: managed syncs stop wedging on big write histories, one bad email or issue no longer stops a connector forever, stuck upgrade migrations finish, and you can finally leave managed mode.**
diff --git a/VERSION b/VERSION
index 908e461f16..1b2b4f8237 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.60.20.0
+0.60.21.0
diff --git a/openclaw.plugin.json b/openclaw.plugin.json
index 17ac42ffef..70b1743cd0 100644
--- a/openclaw.plugin.json
+++ b/openclaw.plugin.json
@@ -1,7 +1,7 @@
{
"id": "gbrain-context-engine",
"name": "gbrain",
- "version": "0.60.20.0",
+ "version": "0.60.21.0",
"description": "Personal knowledge brain with Postgres + pgvector hybrid search",
"family": "bundle-plugin",
"kind": "context-engine",
diff --git a/package.json b/package.json
index c050d30502..6f73b6cf80 100644
--- a/package.json
+++ b/package.json
@@ -204,7 +204,7 @@
"bun": ">=1.3.11"
},
"license": "MIT",
- "version": "0.60.20.0",
+ "version": "0.60.21.0",
"overrides": {
"@ai-sdk/provider-utils": "4.0.33",
"@hono/node-server": "^2.0.5",
diff --git a/plugin-variants/gbrain-coding/.claude-plugin/plugin.json b/plugin-variants/gbrain-coding/.claude-plugin/plugin.json
index d99160f9e6..8b6933ffa6 100644
--- a/plugin-variants/gbrain-coding/.claude-plugin/plugin.json
+++ b/plugin-variants/gbrain-coding/.claude-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "gbrain-coding",
- "version": "0.60.20.0",
+ "version": "0.60.21.0",
"description": "Brain-first coding agent working inside a repo: retrieval, routing, ingest discipline, correction hygiene. Default persona for the claude-code harness bridge; also published as the gbrain-coding marketplace variant. (persona variant of the gbrain plugin — 21 skills)",
"author": {
"name": "Garry Tan",
diff --git a/plugin-variants/gbrain-coding/.codex-plugin/plugin.json b/plugin-variants/gbrain-coding/.codex-plugin/plugin.json
index 1d5ea2ac1d..8facdfc423 100644
--- a/plugin-variants/gbrain-coding/.codex-plugin/plugin.json
+++ b/plugin-variants/gbrain-coding/.codex-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "gbrain-coding",
- "version": "0.60.20.0",
+ "version": "0.60.21.0",
"description": "Brain-first coding agent working inside a repo: retrieval, routing, ingest discipline, correction hygiene. Default persona for the claude-code harness bridge; also published as the gbrain-coding marketplace variant. (persona variant of the gbrain plugin — 21 skills)",
"author": {
"name": "Garry Tan",
diff --git a/plugin-variants/gbrain-coding/README.md b/plugin-variants/gbrain-coding/README.md
index 7cb2a509a7..dccc0fb6ca 100644
--- a/plugin-variants/gbrain-coding/README.md
+++ b/plugin-variants/gbrain-coding/README.md
@@ -1,4 +1,4 @@
-<!-- gbrain-plugin-tree-stamp: 0.60.20.0 -->
+<!-- gbrain-plugin-tree-stamp: 0.60.21.0 -->
# gbrain-coding (generated persona variant — do not hand-edit)
Brain-first coding agent working inside a repo: retrieval, routing, ingest discipline, correction hygiene. Default persona for the claude-code harness bridge; also published as the gbrain-coding marketplace variant.
diff --git a/plugin-variants/gbrain-daily/.claude-plugin/plugin.json b/plugin-variants/gbrain-daily/.claude-plugin/plugin.json
index 1e22a447f8..0e6aed5283 100644
--- a/plugin-variants/gbrain-daily/.claude-plugin/plugin.json
+++ b/plugin-variants/gbrain-daily/.claude-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "gbrain-daily",
- "version": "0.60.20.0",
+ "version": "0.60.21.0",
"description": "Personal knowledge-brain daily use: meetings, tasks, briefings, reading, research. Published as the gbrain-daily marketplace variant. (persona variant of the gbrain plugin — 20 skills)",
"author": {
"name": "Garry Tan",
diff --git a/plugin-variants/gbrain-daily/.codex-plugin/plugin.json b/plugin-variants/gbrain-daily/.codex-plugin/plugin.json
index a8f14db38a..ac019488f3 100644
--- a/plugin-variants/gbrain-daily/.codex-plugin/plugin.json
+++ b/plugin-variants/gbrain-daily/.codex-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "gbrain-daily",
- "version": "0.60.20.0",
+ "version": "0.60.21.0",
"description": "Personal knowledge-brain daily use: meetings, tasks, briefings, reading, research. Published as the gbrain-daily marketplace variant. (persona variant of the gbrain plugin — 20 skills)",
"author": {
"name": "Garry Tan",
diff --git a/plugin-variants/gbrain-daily/README.md b/plugin-variants/gbrain-daily/README.md
index d80c04ffd4..d1dce7de56 100644
--- a/plugin-variants/gbrain-daily/README.md
+++ b/plugin-variants/gbrain-daily/README.md
@@ -1,4 +1,4 @@
-<!-- gbrain-plugin-tree-stamp: 0.60.20.0 -->
+<!-- gbrain-plugin-tree-stamp: 0.60.21.0 -->
# gbrain-daily (generated persona variant — do not hand-edit)
Personal knowledge-brain daily use: meetings, tasks, briefings, reading, research. Published as the gbrain-daily marketplace variant.
diff --git a/plugin/README.md b/plugin/README.md
index 7ee825cf6b..d0a9446ae2 100644
--- a/plugin/README.md
+++ b/plugin/README.md
@@ -1,4 +1,4 @@
-<!-- gbrain-plugin-tree-stamp: 0.60.20.0 -->
+<!-- gbrain-plugin-tree-stamp: 0.60.21.0 -->
# gbrain plugin skill tree (generated — do not hand-edit)
This tree is the curated skill set for the gbrain Codex and Claude Code
diff --git a/src/core/brain-repo-durability.ts b/src/core/brain-repo-durability.ts
index 97a4d5f855..cc9df5e1fd 100644
--- a/src/core/brain-repo-durability.ts
+++ b/src/core/brain-repo-durability.ts
@@ -33,7 +33,7 @@ import {
existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync, rmSync, statSync, renameSync,
} from 'fs';
import { join, dirname, relative, isAbsolute } from 'path';
-import { execFile, execFileSync, execSync, type ExecFileException } from 'child_process';
+import { execFile, execFileSync, execSync, type ChildProcess, type ExecFileException } from 'child_process';
import {
GIT_ENV, GIT_ENV_AUTH, divergenceSafePull, detectDefaultBranch, pushProbe,
type PullOutcome, type PushProbeResult,
@@ -474,6 +474,24 @@ export function isDurabilityHardened(repoPath: string): boolean {
}
}
+const BOUNDED_EXEC_TERM_GRACE_MS = 2_000;
+
+/**
+ * Whether a stopped child has exited even if the runtime lost its exit event:
+ * on Linux an exited-but-unreaped child is a zombie ('Z' in /proc/<pid>/stat).
+ * Elsewhere only the delivered exit counts, so the grace timer bounds the wait.
+ */
+function childHasExited(child: ChildProcess): boolean {
+ if (child.exitCode !== null || child.signalCode !== null) return true;
+ if (process.platform !== 'linux' || child.pid === undefined) return false;
+ try {
+ const stat = readFileSync(`/proc/${child.pid}/stat`, 'utf8');
+ return stat.slice(stat.lastIndexOf(')') + 2).startsWith('Z');
+ } catch {
+ return true;
+ }
+}
+
export interface BoundedExecOptions {
timeout: number;
env?: NodeJS.ProcessEnv;
@@ -488,6 +506,11 @@ export interface BoundedExecOptions {
* (bun:test `expect().resolves/.rejects`, oven-sh/bun#30301): execFile's
* callback and its own `timeout` then never fire and the child stays a zombie,
* so the deadline and abort are enforced with our own timer.
+ *
+ * Stopping sends SIGTERM first so git can remove its lockfiles (a SIGKILLed
+ * `git add`/`commit` leaves `.git/index.lock` behind and every later git call
+ * in that worktree fails), then SIGKILLs after a short grace period and
+ * settles from the timer even if the exit event never arrives.
*/
export function execFileBounded(file: string, args: string[], options: BoundedExecOptions): Promise<{ error: ExecFileException | null; stdout: string; stderr: string }> {
const { timeout, signal, ...rest } = options;
@@ -500,10 +523,29 @@ export function execFileBounded(file: string, args: string[], options: BoundedEx
signal?.removeEventListener('abort', onAbort);
resolve({ error, stdout, stderr });
};
- const child = execFile(file, args, { ...rest, encoding: 'utf8' }, (error, stdout, stderr) => finish(error, stdout, stderr));
+ let stopped: ExecFileException | null = null;
+ let escalation: ReturnType<typeof setTimeout> | undefined;
+ let poll: ReturnType<typeof setInterval> | undefined;
+ const settleStopped = () => {
+ clearTimeout(escalation);
+ clearInterval(poll);
+ finish(stopped, '', '');
+ };
+ const child = execFile(file, args, { ...rest, encoding: 'utf8' }, (error, stdout, stderr) => {
+ clearTimeout(escalation);
+ clearInterval(poll);
+ if (stopped) finish(stopped, '', '');
+ else finish(error, stdout, stderr);
+ });
const stop = (message: string, code: string) => {
- child.kill('SIGKILL');
- finish(Object.assign(new Error(message), { code, killed: true, signal: 'SIGKILL' as const }), '');
+ if (stopped) return;
+ stopped = Object.assign(new Error(message), { code, killed: true, signal: 'SIGTERM' as const });
+ child.kill('SIGTERM');
+ poll = setInterval(() => { if (childHasExited(child)) settleStopped(); }, 25);
+ escalation = setTimeout(() => {
+ child.kill('SIGKILL');
+ settleStopped();
+ }, BOUNDED_EXEC_TERM_GRACE_MS);
};
const timer = setTimeout(() => stop(`${file} did not finish within ${timeout}ms`, 'ETIMEDOUT'), timeout);
const onAbort = () => stop(`${file} was aborted`, 'ABORT_ERR');
diff --git a/templates/bootstrap/template-repo/README.md b/templates/bootstrap/template-repo/README.md
index b65c259280..ebe1f968ef 100644
--- a/templates/bootstrap/template-repo/README.md
+++ b/templates/bootstrap/template-repo/README.md
@@ -1,6 +1,6 @@
# gbrain agent workspace — template
-<!-- gbrain-template-stamp: 0.60.20.0 -->
+<!-- gbrain-template-stamp: 0.60.21.0 -->
This repository is the **"Use this template"** distribution artifact for a
[gbrain](https://github.com/garrytan/gbrain) personal-agent workspace — the same
diff --git a/test/bounded-child-exec.test.ts b/test/bounded-child-exec.test.ts
index 7dfecb0770..1777fa085d 100644
--- a/test/bounded-child-exec.test.ts
+++ b/test/bounded-child-exec.test.ts
@@ -65,3 +65,19 @@ test('bounded execution stops a running child on abort and at its deadline', asy
preAborted.abort();
expect((await execFileBounded('sleep', ['30'], { timeout: 60_000, signal: preAborted.signal })).error).toMatchObject({ code: 'ABORT_ERR' });
});
+
+test('a stopped child gets SIGTERM first so it can remove its lockfile, then SIGKILL after the grace period', async () => {
+ const lock = join(dir, 'index.lock');
+ const script = `touch '${lock}'; trap "rm -f '${lock}'; exit 143" TERM; while :; do sleep 0.05; done`;
+ const abort = new AbortController();
+ const running = execFileBounded('sh', ['-c', script], { timeout: 60_000, signal: abort.signal });
+ await Bun.sleep(200);
+ expect(await Bun.file(lock).exists()).toBe(true);
+ abort.abort();
+ expect((await running).error).toMatchObject({ code: 'ABORT_ERR', killed: true });
+ expect(await Bun.file(lock).exists()).toBe(false);
+ const started = performance.now();
+ const stubborn = await execFileBounded('sh', ['-c', 'trap "" TERM; while :; do sleep 0.05; done'], { timeout: 100 });
+ expect(stubborn.error).toMatchObject({ code: 'ETIMEDOUT', killed: true });
+ expect(performance.now() - started).toBeLessThan(5000);
+});