The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): pass -NoGateway/--no-gateway on the update hand-off when a remote gateway serves the app
ethernet590c68e7ab5e
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 53682a63ec8..8d760499d3d 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -3273,6 +3273,7 @@ function resolveCheckoutUpdateStrategy(): UpdaterStrategy {}),resolveUpdateRoot,resolveUpdaterBinary,+ remoteGatewayActive: globalRemoteActive,emitUpdateProgress,rememberLog,diff --git a/apps/desktop/electron/updater/checkout-legacy.test.ts b/apps/desktop/electron/updater/checkout-legacy.test.tsindex 2caa1e4479b..b5a937c8631 100644--- a/apps/desktop/electron/updater/checkout-legacy.test.ts+++ b/apps/desktop/electron/updater/checkout-legacy.test.ts@@ -32,6 +32,7 @@ it('offers manual recovery only for a missing source probe, never for a broken pupdateHandoffDwellMs: 0,resolveUpdateRoot: (): string => root,resolveUpdaterBinary: vi.fn((): string => 'frozen-updater'),+ remoteGatewayActive: (): boolean => false,emitUpdateProgress: vi.fn(),rememberLog: vi.fn(),startHermes: vi.fn(async (): Promise<void> => {}),diff --git a/apps/desktop/electron/updater/checkout-ownership.test.ts b/apps/desktop/electron/updater/checkout-ownership.test.tsindex aedee23d871..bc84b0a855b 100644--- a/apps/desktop/electron/updater/checkout-ownership.test.ts+++ b/apps/desktop/electron/updater/checkout-ownership.test.ts@@ -18,6 +18,7 @@ it.each(['not-a-git-checkout', 'update-root-steward-owned-git-tree', 'fetch-failupdateHandoffDwellMs: 0,resolveUpdateRoot: (): string => 'repo',resolveUpdaterBinary: vi.fn((): null => null),+ remoteGatewayActive: (): boolean => false,emitUpdateProgress: vi.fn(),rememberLog: vi.fn(),startHermes: vi.fn(async (): Promise<void> => {}),diff --git a/apps/desktop/electron/updater/checkout-remote-gateway.test.ts b/apps/desktop/electron/updater/checkout-remote-gateway.test.tsnew file mode 100644index 00000000000..837171e5adf--- /dev/null+++ b/apps/desktop/electron/updater/checkout-remote-gateway.test.ts@@ -0,0 +1,79 @@+import * as fs from 'node:fs'+import * as os from 'node:os'+import * as path from 'node:path'++import { afterEach, expect, it, vi } from 'vitest'++import * as updaterProcess from '../updater-process'++import { type CheckoutStrategyDeps, createCheckoutStrategy } from './checkout'+import type { SourceUpdate } from './checkout-source'++const IS_WINDOWS: boolean = process.platform === 'win32'+const NO_GATEWAY_FLAG: string = IS_WINDOWS ? '-NoGateway' : '--no-gateway'++afterEach((): void => {+ vi.restoreAllMocks()+})++// One gateway per host (#117529): a Desktop served by a remote gateway must+// tell the hand-off script not to (re)start a local one, and a locally-owned+// Desktop must keep the default so its gateway comes back after the update.+it.each([true, false])('hand-off passes the no-gateway flag iff a remote gateway serves the app: %s', async (remote: boolean): Promise<void> => {+ const root: string = fs.mkdtempSync(path.join(os.tmpdir(), 'checkout-remote-gateway-'))+ const home: string = path.join(root, 'profile')+ const scriptDirectory: string = path.join(root, 'scripts', 'desktop-update')+ fs.mkdirSync(home)+ fs.mkdirSync(scriptDirectory, { recursive: true })+ fs.writeFileSync(path.join(scriptDirectory, IS_WINDOWS ? 'windows.ps1' : 'posix.sh'), '')+ fs.writeFileSync(path.join(scriptDirectory, 'runtime.ps1'), '')+ fs.mkdirSync(path.join(root, '.hermes', 'bin'), { recursive: true })+ fs.writeFileSync(path.join(root, '.hermes', 'bin', 'hermes.exe'), '')++ const status: SourceUpdate = { supported: true, branch: 'main', targetSha: 'a'.repeat(40), updateAvailable: true }++ const deps: CheckoutStrategyDeps = {+ readSourceUpdate: async (): Promise<SourceUpdate> => status,+ hermesHome: home,+ isWindows: IS_WINDOWS,+ isMac: process.platform === 'darwin',+ defaultUpdateBranch: 'main',+ updateHandoffDwellMs: 0,+ resolveUpdateRoot: (): string => root,+ resolveUpdaterBinary: (): null => null,+ remoteGatewayActive: (): boolean => remote,+ emitUpdateProgress: vi.fn(),+ rememberLog: vi.fn(),+ startHermes: async (): Promise<void> => {},+ stopBackendsForUpdate: async (): Promise<void> => {},+ repairMacUpdaterHelper: (): void => {},+ preflightStateDb: (): void => {},+ runningAppBundle: (): null => null,+ markQuittingForHandoff: (): void => {},+ quit: (): void => {}+ }++ const spawned: string[][] = []+ vi.spyOn(updaterProcess, 'spawnUpdaterProcess').mockImplementation(+ (_command: string, args: string[]): updaterProcess.UpdaterChild => {+ spawned.push(args)++ return { unref: (): void => {} }+ }+ )++ try {+ expect(await createCheckoutStrategy(deps).apply()).toMatchObject({ ok: true, handedOff: true })+ expect(spawned).toHaveLength(1)+ const args: string[] = spawned[0]!+ expect(args).toContain(IS_WINDOWS ? '-Branch' : '--branch')++ if (remote) {+ expect(args).toContain(NO_GATEWAY_FLAG)+ } else {+ expect(args).not.toContain(NO_GATEWAY_FLAG)+ }+ } finally {+ fs.rmSync(root, { recursive: true, force: true })+ }+})diff --git a/apps/desktop/electron/updater/checkout-source.test.ts b/apps/desktop/electron/updater/checkout-source.test.tsindex 2b52c09a672..5fade69b769 100644--- a/apps/desktop/electron/updater/checkout-source.test.ts+++ b/apps/desktop/electron/updater/checkout-source.test.ts@@ -376,6 +376,7 @@ urllib.request.build_opener = local_buildforce: opts.force}),resolveUpdaterBinary: (): null => null,+ remoteGatewayActive: (): boolean => false,emitUpdateProgress: vi.fn(),rememberLog: vi.fn(),diff --git a/apps/desktop/electron/updater/checkout.ts b/apps/desktop/electron/updater/checkout.tsindex 10bcb90ae63..fc1f95d5607 100644--- a/apps/desktop/electron/updater/checkout.ts+++ b/apps/desktop/electron/updater/checkout.ts@@ -34,6 +34,13 @@ export interface CheckoutStrategyDeps {defaultUpdateBranch: stringupdateHandoffDwellMs: numberresolveUpdaterBinary: () => string | null+ /**+ * True when one remote gateway serves this Desktop (app-global remote /+ * cloud / SSH). The hand-off then tells `hermes update` not to (re)start a+ * local messaging gateway: with the same channel credentials as the remote+ * host it would become a competing long-poll consumer (#117529).+ */+ remoteGatewayActive: () => booleanemitUpdateProgress: (payload: { stage: string; message: string; percent: number | null }) => voidrememberLog: (chunk: unknown) => void@@ -244,7 +251,7 @@ export function createCheckoutStrategy(deps: CheckoutStrategyDeps): UpdaterStrat// wrapper cmd.exe exits immediately, so child.pid is NOT the script's// pid — the script claims the update marker itself with its own $PID// as its first action, and a relaunched Desktop parks on that.- const wrapped = wrapHandoffForDetachedConsole(scriptHandoff, [+ const wrappedArgs: string[] = ['-InstallRoot',updateRoot,...(status.channel ? ['-Channel', status.channel] : ['-Branch', branch]),@@ -252,7 +259,15 @@ export function createCheckoutStrategy(deps: CheckoutStrategyDeps): UpdaterStratString(process.pid),'-RelaunchExe',process.execPath- ])+ ]++ // Same remote-ownership rule as the posix hand-off (#117529): a+ // remote-served Desktop owns no local messaging gateway.+ if (deps.remoteGatewayActive()) {+ wrappedArgs.push('-NoGateway')+ }++ const wrapped = wrapHandoffForDetachedConsole(scriptHandoff, wrappedArgs)child = spawnUpdaterProcess(wrapped.command, wrapped.args, {cwd: deps.hermesHome,@@ -389,6 +404,14 @@ export function createCheckoutStrategy(deps: CheckoutStrategyDeps): UpdaterStratString(process.pid)]+ // A remote-served Desktop owns no local messaging gateway: `hermes update+ // --gateway` would (re)start one here anyway, and with the same channel+ // credentials as the remote host it becomes a competing long-poll consumer+ // (#117529). Keep --gateway for the local-ownership default.+ if (deps.remoteGatewayActive()) {+ args.push('--no-gateway')+ }+const updateStartedAt = Math.floor(Date.now() / 1000)// Relaunch target: the running .app bundle on mac (script swaps the