Skip to content

The agent that grows with you

fix: retain desktop update and profile gates before canonical ensure

Tekniuma7821f635e28
diff --git a/apps/desktop/electron/local-gateway.test.ts b/apps/desktop/electron/local-gateway.test.ts
index 2713789d06b..449a046e87b 100644
--- a/apps/desktop/electron/local-gateway.test.ts
+++ b/apps/desktop/electron/local-gateway.test.ts
@@ -2,6 +2,16 @@ import { expect, test } from 'vitest'
import { createLocalGatewayDials, ensureLocalGateway } from './local-gateway'
+test('canonical ensure cannot cross a rejected update or profile lifecycle gate', async () => {
+ let ran = false
+ await expect(ensureLocalGateway(async () => { ran = true;
+
+ return { code: 0, stdout: '{}' } }, async () => {
+ throw new Error('profile retired during update')
+ })).rejects.toThrow('profile retired during update')
+ expect(ran).toBe(false)
+})
+
test('native HTTP mints fresh purpose-bound grants without browser credentials', async () => {
const fs = await import('node:fs/promises')
const os = await import('node:os')
diff --git a/apps/desktop/electron/local-gateway.ts b/apps/desktop/electron/local-gateway.ts
index d5354230669..cc4cb7524a1 100644
--- a/apps/desktop/electron/local-gateway.ts
+++ b/apps/desktop/electron/local-gateway.ts
@@ -32,7 +32,8 @@ export interface GatewayEndpoint {
supervisor: string
}
-export async function ensureLocalGateway(run: () => Promise<{ code: number; stdout: string }>) {
+export async function ensureLocalGateway(run: () => Promise<{ code: number; stdout: string }>, beforeEnsure?: () => Promise<void>) {
+ await beforeEnsure?.()
const result = await run()
const payload = JSON.parse(result.stdout)
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 214ebd1ac78..b1638610f39 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -12585,8 +12585,20 @@ async function spawnPoolBackend(profile, entry, opts: { forceLocal?: boolean; po
assertLocalProfileCanStart(profile, profileDeletionGate, key =>
directoryExists(path.join(HERMES_HOME, 'profiles', key))
)
- const backend = await ensureRuntime(resolveHermesBackend(['--profile', profile, 'gateway', 'ensure', '--json']))
- const connection = await ensureLocalGateway(() => runGatewayEnsure(backend, resolveHermesCwd(), HERMES_HOME))
+
+ const connection = await ensureLocalGateway(async () => {
+ const backend = await ensureRuntime(resolveHermesBackend(['--profile', profile, 'gateway', 'ensure', '--json']))
+ profileDeletionGate.assertCanStart(profile)
+ assertPoolEntryStillOwned(poolKey, entry)
+
+ return runGatewayEnsure(backend, resolveHermesCwd(), HERMES_HOME)
+ }, async () => {
+ await waitForUpdateClearance(updateGateDeps(), { pollMs: UPDATE_WAIT_POLL_MS, timeoutMs: UPDATE_WAIT_TIMEOUT_MS })
+ // Update waits yield: retirement or profile deletion may win in that gap.
+ assertPoolEntryStillOwned(poolKey, entry)
+ assertLocalProfileCanStart(profile, profileDeletionGate, key => directoryExists(path.join(HERMES_HOME, 'profiles', key)))
+ })
+
assertPoolEntryStillOwned(poolKey, entry)
return { ...connection, profile, logs: hermesLog.slice(-80), ...getWindowState() }
@@ -12856,6 +12868,7 @@ async function startHermes() {
setWslBridgeProfileState(primaryProfile, true)
const connection = await ensureLocalGateway(() => runGatewayEnsure(setup.backend, resolveHermesCwd(), HERMES_HOME))
+ void showPluginCompatNoticeOnce()
if (!backendConnectionState.isCurrentAttempt(connectionAttempt)) {
throw new Error('Hermes backend start was superseded by a newer connection attempt.')