Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes (upgrade restart never prints an unrecognised parent's command line)

garrytan8ecdfcd6627e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5088568528..9f00db5e6f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,7 +16,7 @@ identifiers and attribution are available in the pre-removal Git revision
### Itemized changes
-- `src/core/upgrade-restart.ts`: `gbrainEntry` resolves a relative entry point against the process's working directory (`/proc/<pid>/cwd` on Linux), skips interpreter flags that take a value (`--preload x`, `--cwd x`, `-r x`) and treats `src/cli.ts` as gbrain when the package two levels up is named gbrain; an unreadable package falls back to the old path match. `bun run <file>` runs the file in its own process and is classified; `bunx`, `bun x` and `bun run <bin>` are wrappers whose child is the gbrain process, so they are no longer counted twice. A worker whose parent is not recognised as gbrain is refused with that parent's pid and command line. On macOS, where the working directory is not read, a relative entry still matches a gbrain path and is otherwise named in the refusal, with connection strings redacted.
+- `src/core/upgrade-restart.ts`: `gbrainEntry` resolves a relative entry point against the process's working directory (`/proc/<pid>/cwd` on Linux), skips interpreter flags that take a value (`--preload x`, `--cwd x`, `-r x`) and treats `src/cli.ts` as gbrain when the package two levels up is named gbrain; an unreadable package falls back to the old path match. `bun run <file>` runs the file in its own process and is classified; `bunx`, `bun x` and `bun run <bin>` are wrappers whose child is the gbrain process, so they are no longer counted twice. A worker whose parent is not recognised as gbrain is refused with that parent's pid and executable name; its command line, which can carry credentials, is never printed or put in `--json` output. On macOS, where the working directory is not read, a relative entry still matches a gbrain path and is otherwise named in the refusal, with connection strings redacted.
- `scripts/eval-spend-guard.sh` (#8717): the lease's start time is read before the signal traps are armed, so no command substitution is parsed between arming them and `wait`. A TERM that landed there ran its trap while bash 5.2 still expected the lease line's `)`, the trap failed with "unexpected EOF while looking for matching `)'", the signal was lost and the guard waited out its command and exited 0. Under CPU load the original guard did that in 3 of 3000 forced TERMs and the fixed guard in 0 of 3000, interleaved. `test/eval-spend-guard.test.ts` pins that no command substitution sits in that window; the exit-143 assertion is unchanged.
- `.github/workflows/test.yml`, `e2e.yml`, `stress.yml` (#8700): the 15 `pglite-snapshot` cache keys hash `src/core/**/*.ts` (plus the snapshot builder and its test helper) instead of `src/core/*.ts` and a hand list of subdirectory files, so a schema input in a new `src/core` folder needs no workflow edit. A change anywhere under `src/core` now rebuilds the snapshot cache.
- `scripts/stress/run.ts` (#8702): a pooler-gated test is exempt from the stress gate only when the workflow job that names it, or the script lines beside it, set `GBRAIN_CI_REQUIRE_PGBOUNCER`; a flag elsewhere in the same file no longer counts. `test/e2e/graduation-cli-topologies.test.ts` is no longer exempt, and a script owner is reported as an "owning pooled runner".
diff --git a/src/core/upgrade-restart.ts b/src/core/upgrade-restart.ts
index 1d18e899c9..3a956b66b4 100644
--- a/src/core/upgrade-restart.ts
+++ b/src/core/upgrade-restart.ts
@@ -33,7 +33,6 @@
*/
import { basename, dirname, isAbsolute, resolve } from 'node:path';
import { parseGlobalFlags } from './cli-options.ts';
-import { redactConnectionInfo } from './audit/redact-connection-info.ts';
export type ProcessRole = 'serve' | 'autopilot' | 'supervisor' | 'worker' | 'mcp' | 'sync';
@@ -55,7 +54,7 @@ export interface HostProcess {
/** The package directory of the gbrain install it was started from (realpath); null when unknown (a compiled binary). */
install_root?: string | null;
/** A worker with no gbrain process above it: the process that started it, which was not recognised as gbrain. */
- unclassified_parent?: { pid: number; command: string };
+ unclassified_parent?: { pid: number; executable: string };
}
export interface ProcessTableRow { pid: number; ppid: number; command: string; started_ms: number | null; gbrain_home: string | null | undefined; cwd?: string | null }
@@ -181,7 +180,7 @@ export async function collectHostProcesses(sources: ProcessSources): Promise<Hos
for (const p of byPid.values()) {
p.ppid = p.ancestors?.find(pid => byPid.has(pid)) ?? null;
const launcher = p.role === 'worker' && p.ppid === null && p.ancestors?.[0] !== undefined ? rows.get(p.ancestors[0]) : undefined;
- if (launcher) p.unclassified_parent = { pid: launcher.pid, command: launcher.command };
+ if (launcher) p.unclassified_parent = { pid: launcher.pid, executable: basename(launcher.command.trim().split(/\s+/)[0]!) };
}
return [...byPid.values()].sort((a, b) => a.pid - b.pid);
}
@@ -305,7 +304,7 @@ export function planRestart(processes: readonly HostProcess[], ctx: RestartConte
case 'worker':
if (parent?.role === 'supervisor' && parent.args) supervisors.set(parent.pid, [...(supervisors.get(parent.pid) ?? []), p.pid]);
else if (parent?.role === 'autopilot' && runsUnder(parent, ctx.autopilotService)) addService('autopilot', parent.pid);
- else kill(p, `${label(p)} is not run by a jobs supervisor this restart can relaunch${parent?.role === 'autopilot' ? ' (its autopilot runs under no installed service)' : ''}${p.unclassified_parent ? ` (its parent, pid ${p.unclassified_parent.pid} (\`${redactConnectionInfo(p.unclassified_parent.command)}\`), is not a process this restart recognises as gbrain)` : ''}: stop it (\`kill ${p.pid}\`, SIGTERM drains its jobs) and start \`gbrain jobs work\` again the way it was launched, or run workers under \`gbrain jobs supervisor start --detach\`.`);
+ else kill(p, `${label(p)} is not run by a jobs supervisor this restart can relaunch${parent?.role === 'autopilot' ? ' (its autopilot runs under no installed service)' : ''}${p.unclassified_parent ? ` (its parent, pid ${p.unclassified_parent.pid} (\`${p.unclassified_parent.executable}\`), is not a process this restart recognises as gbrain)` : ''}: stop it (\`kill ${p.pid}\`, SIGTERM drains its jobs) and start \`gbrain jobs work\` again the way it was launched, or run workers under \`gbrain jobs supervisor start --detach\`.`);
break;
case 'mcp':
if (ctx.stopMcp && p.args) stops.push({ kind: 'stop', role: 'mcp', pid: p.pid, started_ms: p.started_ms });
diff --git a/test/upgrade-restart.test.ts b/test/upgrade-restart.test.ts
index 9cd110798c..a4e821b499 100644
--- a/test/upgrade-restart.test.ts
+++ b/test/upgrade-restart.test.ts
@@ -110,8 +110,9 @@ describe('gbrainEntry (#8723)', () => {
expect(plan.steps).toEqual([{ kind: 'supervisor', pid: 20, workers: [21], ...supervisorRestartArgv(['jobs', 'supervisor', '--queue', 'default']) }]);
});
- test('a worker whose parent cannot be classified is refused with that parent\'s pid and command line', async () => {
+ test('a worker whose parent cannot be classified is refused with that parent\'s pid and executable, never its command line', async () => {
const databaseUrl = ['postgres://alice-example', 'hunter2'].join(':') + '@db.example:5432/brain';
+ const apiKey = ['sk-ant-api03', 'EXAMPLEONLY0123456789'].join('-');
const processes = await collectHostProcesses({
heartbeats: async () => [], workers: () => [], supervisor: () => null, home: HOME, exclude: [], packageName,
processTable: () => [
@@ -119,13 +120,19 @@ describe('gbrainEntry (#8723)', () => {
{ pid: 30, ppid: 1, command: `sh -c DATABASE_URL=${databaseUrl} bun run src/cli.ts jobs supervisor`, started_ms: 600, gbrain_home: HOME, cwd: null },
{ pid: 31, ppid: 30, command: `bun ${CHECKOUT}/src/cli.ts jobs work`, started_ms: 700, gbrain_home: HOME, cwd: null },
{ pid: 21, ppid: 20, command: `bun ${CHECKOUT}/src/cli.ts jobs work`, started_ms: 700, gbrain_home: HOME, cwd: null },
+ { pid: 40, ppid: 1, command: `timeout 3600 env ANTHROPIC_API_KEY=${apiKey} gbrain jobs work`, started_ms: 600, gbrain_home: HOME, cwd: null },
+ { pid: 41, ppid: 40, command: 'gbrain jobs work', started_ms: 700, gbrain_home: HOME, cwd: null },
],
});
- expect(processes.map(p => [p.pid, p.role])).toEqual([[21, 'worker'], [31, 'worker']]);
- const [manual, redacted] = planRestart(processes, ctx()).manual;
- expect(manual!.instruction).toContain('its parent, pid 20 (`bun run src/cli.ts jobs supervisor`), is not a process this restart recognises as gbrain');
- expect(redacted!.instruction).toContain('its parent, pid 30 (');
- expect(redacted!.instruction).not.toContain('hunter2');
+ expect(processes.map(p => [p.pid, p.role])).toEqual([[21, 'worker'], [31, 'worker'], [41, 'worker']]);
+ const plan = planRestart(processes, ctx());
+ const [manual, shell, wrapper] = plan.manual;
+ expect(manual!.instruction).toContain('its parent, pid 20 (`bun`), is not a process this restart recognises as gbrain');
+ expect(shell!.instruction).toContain('its parent, pid 30 (`sh`), is not a process');
+ expect(wrapper!.instruction).toContain('its parent, pid 40 (`timeout`), is not a process');
+ const printed = JSON.stringify({ processes, plan });
+ expect(printed).not.toContain('hunter2');
+ expect(printed).not.toContain(apiKey);
});
});