Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(desktop): recover failed update installs (#153)
Leo68bc5891feb4
diff --git a/apps/desktop/src/app/DesktopEnvironment.test.ts b/apps/desktop/src/app/DesktopEnvironment.test.tsindex 40582a169..df2029511 100644--- a/apps/desktop/src/app/DesktopEnvironment.test.ts+++ b/apps/desktop/src/app/DesktopEnvironment.test.ts@@ -118,6 +118,20 @@ describe("DesktopEnvironment", () => {}),);+ it.effect("ignores an ambient development port in packaged apps", () =>+ Effect.gen(function* () {+ const environment = yield* makeEnvironment(+ {+ isPackaged: true,+ appPath: "/Applications/Akeru Bot.app/Contents/Resources/app.asar",+ },+ { T3CODE_PORT: "3773" },+ );++ assert.deepEqual(environment.configuredBackendPort, Option.none());+ }),+ );+it.effect("keeps implicit development state separate from production state", () =>Effect.gen(function* () {const development = yield* makeEnvironment(diff --git a/apps/desktop/src/app/DesktopEnvironment.ts b/apps/desktop/src/app/DesktopEnvironment.tsindex c035bea7d..16b0e67ff 100644--- a/apps/desktop/src/app/DesktopEnvironment.ts+++ b/apps/desktop/src/app/DesktopEnvironment.ts@@ -219,7 +219,7 @@ const make = Effect.fn("desktop.environment.make")(function* (: path.join(input.appPath, "dev-app-update.yml"),devServerUrl,devRemoteT3ServerEntryPath: config.devRemoteT3ServerEntryPath,- configuredBackendPort: config.configuredBackendPort,+ configuredBackendPort: input.isPackaged ? Option.none() : config.configuredBackendPort,commitHashOverride: config.commitHashOverride,otlpTracesUrl: config.otlpTracesUrl,otlpExportIntervalMs: config.otlpExportIntervalMs,diff --git a/apps/desktop/src/updates/DesktopUpdates.test.ts b/apps/desktop/src/updates/DesktopUpdates.test.tsindex 55a6560e4..c2e05e8ed 100644--- a/apps/desktop/src/updates/DesktopUpdates.test.ts+++ b/apps/desktop/src/updates/DesktopUpdates.test.ts@@ -31,6 +31,7 @@ interface UpdatesHarnessOptions {readonly setUpdateChannelError?: DesktopAppSettings.DesktopSettingsWriteError;readonly setDisableDifferentialDownload?: Effect.Effect<void>;readonly stopBackend?: Effect.Effect<void>;+ readonly startBackend?: Effect.Effect<void>;readonly env?: Record<string, string | undefined>;}@@ -116,7 +117,7 @@ function makeHarness(options: UpdatesHarnessOptions = {}) {const stubBackendInstance: DesktopBackendPool.DesktopBackendInstance = {id: DesktopBackendPool.PRIMARY_INSTANCE_ID,label: Effect.succeed("Windows"),- start: Effect.void,+ start: options.startBackend ?? Effect.void,stop: () => options.stopBackend ?? Effect.void,currentConfig: Effect.succeed(Option.none()),snapshot: Effect.succeed({@@ -542,6 +543,36 @@ describe("DesktopUpdates", () => {).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));});+ it.effect("restarts stopped backends when update installation fails", () => {+ let starts = 0;+ const harness = makeHarness({+ startBackend: Effect.sync(() => {+ starts += 1;+ }),+ });++ return Effect.scoped(+ Effect.gen(function* () {+ const desktopState = yield* DesktopState.DesktopState;+ const updates = yield* DesktopUpdates.DesktopUpdates;+ yield* updates.configure;+ harness.emit("update-downloaded", { version: "1.2.4" });+ yield* flushCallbacks;++ const install = yield* updates.install;+ assert.isTrue(install.accepted);++ harness.emit("error", new Error("installer failed"));+ yield* flushCallbacks;++ assert.equal(starts, 1);+ assert.isFalse(yield* Ref.get(desktopState.quitting));+ const state = yield* updates.getState;+ assert.equal(state.errorContext, "install");+ }),+ ).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));+ });+it.effect("logs bounded updater failure context without exposing the cause", () => {const cause = new Error("request failed for https://user:[email protected]/update?token=secret",diff --git a/apps/desktop/src/updates/DesktopUpdates.ts b/apps/desktop/src/updates/DesktopUpdates.tsindex 894b12f53..0619f4c93 100644--- a/apps/desktop/src/updates/DesktopUpdates.ts+++ b/apps/desktop/src/updates/DesktopUpdates.ts@@ -635,6 +635,11 @@ export const make = Effect.gen(function* () {if (Option.isSome(activeAction) && activeAction.value === "install") {yield* finishUpdateAction("install");yield* Ref.set(desktopState.quitting, false);+ const instances = yield* pool.list;+ yield* Effect.forEach(instances, (instance) => instance.start, {+ concurrency: "unbounded",+ discard: true,+ });yield* updateState((current) =>reduceDesktopUpdateStateOnInstallFailure(current, error.message),);