Skip to content

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.

[codex] Preserve detached desktop action causes (#3371)

Julius Marmingefccecd874905
diff --git a/apps/desktop/src/app/DesktopDetachedActionErrors.test.ts b/apps/desktop/src/app/DesktopDetachedActionErrors.test.ts
new file mode 100644
index 000000000..ae7808053
--- /dev/null
+++ b/apps/desktop/src/app/DesktopDetachedActionErrors.test.ts
@@ -0,0 +1,37 @@
+import { assert, describe, it } from "@effect/vitest";
+import * as Cause from "effect/Cause";
+
+import { DesktopLifecycleRelaunchError } from "./DesktopLifecycle.ts";
+import { DesktopApplicationMenuActionError } from "../window/DesktopApplicationMenu.ts";
+
+describe("desktop detached action errors", () => {
+ it("preserves the complete relaunch failure cause and reason", () => {
+ const cause = Cause.combine(
+ Cause.fail(new Error("shutdown failed")),
+ Cause.die(new Error("relaunch defect")),
+ );
+ const error = new DesktopLifecycleRelaunchError({
+ reason: "apply update",
+ cause,
+ });
+
+ assert.strictEqual(error.cause, cause);
+ assert.equal(error.reason, "apply update");
+ assert.equal(error.message, 'Desktop relaunch failed for reason "apply update".');
+ });
+
+ it("preserves the complete menu action failure cause and action", () => {
+ const cause = Cause.combine(
+ Cause.fail(new Error("window unavailable")),
+ Cause.die(new Error("dispatch defect")),
+ );
+ const error = new DesktopApplicationMenuActionError({
+ action: "open-settings",
+ cause,
+ });
+
+ assert.strictEqual(error.cause, cause);
+ assert.equal(error.action, "open-settings");
+ assert.equal(error.message, 'Desktop menu action "open-settings" failed.');
+ });
+});
diff --git a/apps/desktop/src/app/DesktopLifecycle.ts b/apps/desktop/src/app/DesktopLifecycle.ts
index ad08d2f5a..c5264332b 100644
--- a/apps/desktop/src/app/DesktopLifecycle.ts
+++ b/apps/desktop/src/app/DesktopLifecycle.ts
@@ -1,8 +1,8 @@
-import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Ref from "effect/Ref";
+import * as Schema from "effect/Schema";
import * as Scope from "effect/Scope";
import type * as Electron from "electron";
@@ -15,6 +15,18 @@ import * as ElectronTheme from "../electron/ElectronTheme.ts";
import * as DesktopState from "./DesktopState.ts";
import * as DesktopWindow from "../window/DesktopWindow.ts";
+export class DesktopLifecycleRelaunchError extends Schema.TaggedErrorClass<DesktopLifecycleRelaunchError>()(
+ "DesktopLifecycleRelaunchError",
+ {
+ reason: Schema.String,
+ cause: Schema.Defect(),
+ },
+) {
+ override get message(): string {
+ return `Desktop relaunch failed for reason "${this.reason}".`;
+ }
+}
+
export type DesktopLifecycleRuntimeServices =
| DesktopEnvironment.DesktopEnvironment
| DesktopShutdown.DesktopShutdown
@@ -142,11 +154,10 @@ export const make = DesktopLifecycle.of({
});
yield* electronApp.exit(0);
}).pipe(
- Effect.catchCause((cause) =>
- logLifecycleError("desktop relaunch failed", {
- cause: Cause.pretty(cause),
- }),
- ),
+ Effect.catchCause((cause) => {
+ const error = new DesktopLifecycleRelaunchError({ reason, cause });
+ return logLifecycleError(error.message, { error });
+ }),
Effect.forkDetach,
Effect.asVoid,
);
diff --git a/apps/desktop/src/window/DesktopApplicationMenu.ts b/apps/desktop/src/window/DesktopApplicationMenu.ts
index cfe4f5702..a52707627 100644
--- a/apps/desktop/src/window/DesktopApplicationMenu.ts
+++ b/apps/desktop/src/window/DesktopApplicationMenu.ts
@@ -1,8 +1,8 @@
-import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
+import * as Schema from "effect/Schema";
import type * as Electron from "electron";
@@ -14,6 +14,18 @@ import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
import * as DesktopUpdates from "../updates/DesktopUpdates.ts";
import * as DesktopWindow from "./DesktopWindow.ts";
+export class DesktopApplicationMenuActionError extends Schema.TaggedErrorClass<DesktopApplicationMenuActionError>()(
+ "DesktopApplicationMenuActionError",
+ {
+ action: Schema.String,
+ cause: Schema.Defect(),
+ },
+) {
+ override get message(): string {
+ return `Desktop menu action "${this.action}" failed.`;
+ }
+}
+
export class DesktopApplicationMenu extends Context.Service<
DesktopApplicationMenu,
{
@@ -100,12 +112,10 @@ export const make = Effect.gen(function* () {
effect.pipe(
Effect.annotateLogs({ action }),
Effect.withSpan("desktop.menu.action"),
- Effect.catchCause((cause) =>
- logMenuError("desktop menu action failed", {
- action,
- cause: Cause.pretty(cause),
- }),
- ),
+ Effect.catchCause((cause) => {
+ const error = new DesktopApplicationMenuActionError({ action, cause });
+ return logMenuError(error.message, { error });
+ }),
),
);
};