Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: check every bundle probe against the Bun floor (third /ship invocation, pass 2)

garrytan71d49156b517
diff --git a/src/core/agent-install/setup.ts b/src/core/agent-install/setup.ts
index d228621c52..7d278ddef1 100644
--- a/src/core/agent-install/setup.ts
+++ b/src/core/agent-install/setup.ts
@@ -183,6 +183,15 @@ Restore with \`backup restore /absolute/path/archive.gbrain-backup --into /absol
`;
}
+function refuseBelowFloor(identity: ReturnType<typeof artifactFromBundle>, options: AgentSetupOptions, root: string, outcome: string): void {
+ if (bunVersionMeets(identity.bun_version, MINIMUM_BUN_VERSION)) return;
+ const rerunArgs = ['--root', root, '--harness', options.harness, ...(options.adopt ? ['--adopt'] : []), ...(options.upgrade ? ['--upgrade'] : []),
+ ...(options.skills ? ['--skills', options.skills] : []), ...(options.json ? ['--json'] : [])];
+ const rerun = `curl --fail --silent --show-error --location ${SETUP_HELPER_URL} --output /tmp/gbrain-setup.sh && bash /tmp/gbrain-setup.sh ${rerunArgs.map(shellQuote).join(' ')}`;
+ const next = options.upgrade ? 'Make a verified backup first (docs/guides/in-agent-setup.md), then fetch' : 'Fetch';
+ throw new AgentInstallError('runtime_below_floor', `This GBrain release needs Bun ${MINIMUM_BUN_VERSION} or newer, but the setup bundle carries Bun ${identity.bun_version || 'of unknown version'}, so the helper that staged it is out of date. ${outcome} ${next} the current helper and rerun setup: ${rerun}`);
+}
+
export async function setupInAgent(options: AgentSetupOptions): Promise<AgentSetupResult> {
if (options.skills !== undefined && !['follow', 'memory-only'].includes(options.skills)) throw new AgentInstallError('usage', 'The skills policy must be follow or memory-only.');
const root = checkedRoot(options.root);
@@ -191,13 +200,7 @@ export async function setupInAgent(options: AgentSetupOptions): Promise<AgentSet
// A bundle that cannot be read is reported inside the install below, where the receipt journals it.
let identity: ReturnType<typeof artifactFromBundle> | undefined;
try { identity = artifactFromBundle(options.bundle, options.sourceRef); } catch { identity = undefined; }
- if (identity && !bunVersionMeets(identity.bun_version, MINIMUM_BUN_VERSION)) {
- const rerunArgs = ['--root', root, '--harness', options.harness, ...(options.adopt ? ['--adopt'] : []), ...(options.upgrade ? ['--upgrade'] : []),
- ...(options.skills ? ['--skills', options.skills] : []), ...(options.json ? ['--json'] : [])];
- const rerun = `curl --fail --silent --show-error --location ${SETUP_HELPER_URL} --output /tmp/gbrain-setup.sh && bash /tmp/gbrain-setup.sh ${rerunArgs.map(shellQuote).join(' ')}`;
- const next = options.upgrade ? 'Make a verified backup first (docs/guides/in-agent-setup.md), then fetch' : 'Fetch';
- throw new AgentInstallError('runtime_below_floor', `This GBrain release needs Bun ${MINIMUM_BUN_VERSION} or newer, but the setup bundle carries Bun ${identity.bun_version || 'of unknown version'}, so the helper that staged it is out of date. Nothing was changed. ${next} the current helper and rerun setup: ${rerun}`);
- }
+ if (identity) refuseBelowFloor(identity, options, root, 'Nothing was changed.');
if (!existsSync(dirname(root))) throw new AgentInstallError('parent_missing', 'Create and verify the persistent parent directory first.');
const existed = existsSync(root);
if (!existed) mkdirSync(root, { mode: 0o700 });
@@ -255,6 +258,7 @@ export async function setupInAgent(options: AgentSetupOptions): Promise<AgentSet
delete receipt.last_failure;
let changed = false;
identity ??= artifactFromBundle(options.bundle, options.sourceRef);
+ refuseBelowFloor(identity, options, root, 'No runtime was installed.');
if (receipt.artifact && !options.upgrade && identity.source_ref !== receipt.artifact.source_ref) throw new AgentInstallError('artifact_version_mismatch', 'Repair must use the recorded source commit; use --upgrade to explicitly change versions.');
const upgrade = !!options.upgrade && receipt.artifact?.source_ref !== identity.source_ref;
if (!receipt.artifact || upgrade || !artifactUsable(root, receipt.artifact)) {
diff --git a/test/agent-install-bun-floor.test.ts b/test/agent-install-bun-floor.test.ts
index 1053696ea9..69860fbeb2 100644
--- a/test/agent-install-bun-floor.test.ts
+++ b/test/agent-install-bun-floor.test.ts
@@ -124,6 +124,18 @@ test('an unreadable bundle is still journaled on the install receipt', async ()
expect(receipt.last_failure?.code).toBe('invalid_artifact');
});
+test('a bundle whose first runtime probe fails is still checked against the floor before install', async () => {
+ const { root, bundle } = fixture('1.4.3');
+ const probed = join(bundle, '.probed');
+ writeFileSync(join(bundle, 'bun'), `#!/bin/sh\nif [ ! -e '${probed}' ]; then : > '${probed}'; exit 9; fi\nif [ "$1" = --version ]; then echo 1.4.3; exit 0; fi\nexit 7\n`);
+ const { exit, result } = await run(setupArgs(root, bundle));
+ expect(exit).toBe(1);
+ expect(result.reason).toBe('runtime_below_floor');
+ expect(existsSync(join(root, 'runtime'))).toBe(false);
+ const receipt = JSON.parse(readFileSync(join(root, '.gbrain', 'agent-install', 'receipt.json'), 'utf8'));
+ expect(receipt.last_failure?.code).toBe('runtime_below_floor');
+});
+
test('missing arguments still answer usage (exit 2) before the floor check', async () => {
const { bundle } = fixture('1.4.3');
const { exit, result } = await run(['--harness', 'grok-bot', '--bundle', bundle, '--source-ref', 'a'.repeat(40), '--json']);