Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(upgrade): reinstall hints remove the global package before adding a tag (#5034, B-NEW-5)
time-attack9737979ba8c5
diff --git a/docs/guides/authorization-upgrade.md b/docs/guides/authorization-upgrade.mdindex 007c462c43..e416d2c654 100644--- a/docs/guides/authorization-upgrade.md+++ b/docs/guides/authorization-upgrade.md@@ -100,9 +100,17 @@ no tools; only an absent trusted-local binding uses the default registry.installation, replace `vX.Y.Z.W` below with the exact release being installed:```sh+ bun remove --global gbrainbun install --global --ignore-scripts github:garrytan/gbrain#vX.Y.Z.W```+ Remove first. Installing a different tag over an existing global install+ fails with `DependencyLoop` on Bun 1.3, and on Bun 1.4 it exits 0 without+ swapping the code while it corrupts the global `package.json` and+ `bun.lock` (#5034). If the install step fails after the removal, run it+ again before restarting anything; `gbrain --version` must print the new+ release.+For a linked source checkout, update that checkout to the chosen releasethrough its normal Git workflow, then run `bun install --ignore-scripts`.Do not use `gbrain upgrade --swap-only` for this source/package cutover: itsdiff --git a/docs/guides/upgrades-auto-update.md b/docs/guides/upgrades-auto-update.mdindex 3f25495c91..d7c1a725ef 100644--- a/docs/guides/upgrades-auto-update.md+++ b/docs/guides/upgrades-auto-update.md@@ -105,7 +105,7 @@ the startup Bun check, unlike `--version`). If the new release does notstart, the upgrade exits non-zero and prints recovery: `bun upgrade`, then`gbrain post-upgrade`; or return to the previous release with`git -C <clone> checkout <previous sha> && bun install` (bun-link) or-`bun install -g github:garrytan/gbrain#v<previous>` (package). Nothing is+`bun remove -g gbrain && bun add -g github:garrytan/gbrain#v<previous>` (package; an in-place tag swap fails or silently corrupts the global lock on current Bun, #5034). Nothing isrolled back automatically, and the autopilot channel records that version asfailed.diff --git a/skills/migrations/v0.50.0.0.md b/skills/migrations/v0.50.0.0.mdindex cf5328c291..fba727a0cc 100644--- a/skills/migrations/v0.50.0.0.md+++ b/skills/migrations/v0.50.0.0.md@@ -23,9 +23,14 @@ a thin client cannot authorize historical jobs.the following version-pinned command:```bash+ bun remove --global gbrainbun install --global --ignore-scripts github:garrytan/gbrain#v0.50.0.0```+ Remove first: installing a different tag over an existing global install+ fails with `DependencyLoop` on Bun 1.3 and silently leaves the old code+ while corrupting the global lock on Bun 1.4 (#5034).+For a linked source checkout, update that checkout to the chosen releasethrough its normal Git workflow, then run `bun install --ignore-scripts`.A source/package `gbrain upgrade --swap-only` still runs Bun's installationdiff --git a/src/commands/upgrade.ts b/src/commands/upgrade.tsindex 3d6562c784..ff14c55a03 100644--- a/src/commands/upgrade.ts+++ b/src/commands/upgrade.ts@@ -193,13 +193,13 @@ export async function runUpgrade(args: string[], opts: { targetVersion?: stringif (target && assessUpgradeOutcome(target, newVersion) === 'mismatch') {console.error(`Upgrade did not take effect: still running ${newVersion}, expected ${target}.`);console.error('Exact-tag Git installs stay pinned through `bun update`. Reinstall with:');- console.error(` bun add -g github:garrytan/gbrain#v${target}`);+ console.error(` ${bunReinstallCommand(`#v${target}`)}`);recordUpgradeError({phase: 'verify-target',fromVersion: oldVersion,toVersion: target,error: `still running ${newVersion} after upgrade`,- hint: `bun add -g github:garrytan/gbrain#v${target}`,+ hint: bunReinstallCommand(`#v${target}`),});setCliExitVerdict(1);return;@@ -213,7 +213,7 @@ export async function runUpgrade(args: string[], opts: { targetVersion?: stringif (pin) {const { pendingUpgradeVersion } = await import('../core/self-upgrade.ts');const latest = pendingUpgradeVersion(oldVersion);- const reinstall = latest ? `bun add -g github:garrytan/gbrain#v${latest}` : 'bun add -g github:garrytan/gbrain';+ const reinstall = bunReinstallCommand(latest ? `#v${latest}` : '');console.error(`Upgrade did not take effect: still running ${newVersion}, because the global install is pinned to ${pin} and \`bun update\` keeps a pinned tag.`);console.error('Reinstall to move off the pin:');console.error(` ${reinstall}`);@@ -340,7 +340,7 @@ function postSwapSmoke(newVersion: string, r: SmokeRecovery): boolean {const detail = (run.stderr ?? '').trim().split('\n')[0];const back = r.method === 'bun-link' && r.repoRoot && r.previousSha? `git -C ${r.repoRoot} checkout ${r.previousSha} && bun install`- : r.method === 'bun' ? `bun install -g github:${GBRAIN_GITHUB_REPO}#v${r.oldVersion}` : null;+ : r.method === 'bun' ? bunReinstallCommand(`#v${r.oldVersion}`) : null;console.error(`gbrain ${newVersion || '(new version)'} was installed but does not start: \`gbrain --help\` failed (${why}).${detail ? `\n ${detail}` : ''}`);console.error('Recovery:');console.error(' If it names an old Bun: bun upgrade, then gbrain post-upgrade');@@ -403,6 +403,17 @@ export function resolveBunGlobalRoot(): string {return installRoot ?? defaultRoot;}+/**+ * #5034 / B-NEW-5: reinstall the global Bun package at `ref` by removing it+ * first. An in-place `bun add -g` / `bun install --global` tag swap over an+ * existing global install fails with DependencyLoop on Bun 1.3 and, on Bun+ * 1.4, exits 0 without swapping while it corrupts the global package.json+ * and bun.lock.+ */+export function bunReinstallCommand(ref: string): string {+ return `bun remove -g gbrain && bun add -g github:${GBRAIN_GITHUB_REPO}${ref}`;+}+/*** #5311: the exact Git tag the bun global install pins gbrain to* (`github:garrytan/gbrain#v0.51.0`), or null for an unpinned or branch spec.diff --git a/test/upgrade-exact-tag-pin.test.ts b/test/upgrade-exact-tag-pin.test.tsindex 35e6f42b5a..cb2603014b 100644--- a/test/upgrade-exact-tag-pin.test.ts+++ b/test/upgrade-exact-tag-pin.test.ts@@ -14,7 +14,7 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, wrimport { join, resolve } from 'path';import { tmpdir } from 'os';-import { bunGlobalExactTagPin } from '../src/commands/upgrade.ts';+import { bunGlobalExactTagPin, bunReinstallCommand } from '../src/commands/upgrade.ts';import { VERSION } from '../src/version.ts';const REPO = resolve(import.meta.dir, '..');@@ -67,17 +67,25 @@ describe('#5311 bare upgrade on an exact-tag pin', () => {expect(r.exitCode).toBe(1);expect(r.stderr).toContain('Upgrade did not take effect');expect(r.stderr).toContain(`pinned to github:garrytan/gbrain#v${VERSION}`);- expect(r.stderr).toContain('bun add -g github:garrytan/gbrain');+ // #5034 / B-NEW-5: remove before add; an in-place global tag swap fails (Bun 1.3) or silently corrupts the lock (Bun 1.4).+ expect(r.stderr).toContain('bun remove -g gbrain && bun add -g github:garrytan/gbrain');expect(readFileSync(join(r.home, 'bun-calls.log'), 'utf-8')).toContain('update gbrain');// No false "just upgraded" breadcrumb for an upgrade that never happened.expect(existsSync(join(r.home, '.gbrain', 'just-upgraded-from'))).toBe(false);const errors = readFileSync(join(r.home, '.gbrain', 'upgrade-errors.jsonl'), 'utf-8').trim().split('\n').map(l => JSON.parse(l));- expect(errors.some(e => e.phase === 'verify-pin' && e.hint.startsWith('bun add -g github:garrytan/gbrain'))).toBe(true);+ expect(errors.some(e => e.phase === 'verify-pin' && e.hint.startsWith('bun remove -g gbrain && bun add -g github:garrytan/gbrain'))).toBe(true);} finally {rmSync(r.home, { recursive: true, force: true });}}, 60_000);+ test('every reinstall hint removes the global package before adding the tag (#5034, B-NEW-5)', () => {+ expect(bunReinstallCommand('#v0.60.1.0')).toBe('bun remove -g gbrain && bun add -g github:garrytan/gbrain#v0.60.1.0');+ expect(bunReinstallCommand('')).toBe('bun remove -g gbrain && bun add -g github:garrytan/gbrain');+ const source = readFileSync(join(REPO, 'src/commands/upgrade.ts'), 'utf-8');+ expect(source).not.toMatch(/`bun (add|install) -g github:[^`]*#v\$\{/);+ });+test('an unpinned install that is already current still succeeds', async () => {const r = await runBareUpgrade('github:garrytan/gbrain', VERSION);try {