Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(wiki): guard unknown failure reasons and simplify runtime error mapping
Dongdong Chen0043a8b2b25c
diff --git a/apps/node-services/src/llm-wiki/actor-wiki/actor-asset-client.ts b/apps/node-services/src/llm-wiki/actor-wiki/actor-asset-client.tsindex 40c1d1c1..7fda4f4e 100644--- a/apps/node-services/src/llm-wiki/actor-wiki/actor-asset-client.ts+++ b/apps/node-services/src/llm-wiki/actor-wiki/actor-asset-client.ts@@ -13,9 +13,7 @@ export class ActorAssetError extends Error {readonly code: ActorAssetErrorCode,message: string,readonly disposition: GenerationFailureDisposition = code ===- "WIKI_OPERATION_FAILED" ||- code === "WIKI_RUNTIME_INCOMPATIBLE" ||- code === "WIKI_RUNTIME_AUTH_REQUIRED"+ "WIKI_OPERATION_FAILED"? "terminal": "retryable",options?: ErrorOptions,diff --git a/apps/node-services/src/llm-wiki/wiki-refresh-candidates.ts b/apps/node-services/src/llm-wiki/wiki-refresh-candidates.tsindex edd68408..c5dd4887 100644--- a/apps/node-services/src/llm-wiki/wiki-refresh-candidates.ts+++ b/apps/node-services/src/llm-wiki/wiki-refresh-candidates.ts@@ -53,6 +53,44 @@ const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/u;const SHA256_PATTERN = /^[a-f0-9]{64}$/u;const MAX_SOURCE_BYTES = 50 * 1024 * 1024;+type RuntimeActorAssetErrorCode =+ | "WIKI_RUNTIME_INCOMPATIBLE"+ | "WIKI_RUNTIME_AUTH_REQUIRED"+ | "WIKI_RUNTIME_UNAVAILABLE";++interface RuntimeActorErrorSpec {+ readonly disposition: "retryable" | "terminal";+ readonly status: 500 | 503;+ readonly message: string;+}++const RUNTIME_ACTOR_ERRORS: Record<+ RuntimeActorAssetErrorCode,+ RuntimeActorErrorSpec+> = {+ WIKI_RUNTIME_INCOMPATIBLE: {+ disposition: "terminal",+ status: 500,+ message: "The Wiki owner's Local Computer Runtime is incompatible",+ },+ WIKI_RUNTIME_AUTH_REQUIRED: {+ disposition: "terminal",+ status: 500,+ message: "The Wiki owner's Local Computer Runtime requires sign-in",+ },+ WIKI_RUNTIME_UNAVAILABLE: {+ disposition: "retryable",+ status: 503,+ message: "The Wiki owner's Local Computer Runtime is unavailable",+ },+};++function isRuntimeActorAssetErrorCode(+ code: ActorAssetError["code"],+): code is RuntimeActorAssetErrorCode {+ return Object.hasOwn(RUNTIME_ACTOR_ERRORS, code);+}+export class WikiRefreshCandidateError extends Error {constructor(readonly code:@@ -225,37 +263,14 @@ export class WikiRefreshCandidateService {}if (error instanceof ActorAssetError &&- error.code === "WIKI_RUNTIME_INCOMPATIBLE"- ) {- throw new WikiRefreshCandidateError(- "WIKI_RUNTIME_INCOMPATIBLE",- "terminal",- 500,- "The Wiki owner's Local Computer Runtime is incompatible",- { cause: error },- );- }- if (- error instanceof ActorAssetError &&- error.code === "WIKI_RUNTIME_AUTH_REQUIRED"- ) {- throw new WikiRefreshCandidateError(- "WIKI_RUNTIME_AUTH_REQUIRED",- "terminal",- 500,- "The Wiki owner's Local Computer Runtime requires sign-in",- { cause: error },- );- }- if (- error instanceof ActorAssetError &&- error.code === "WIKI_RUNTIME_UNAVAILABLE"+ isRuntimeActorAssetErrorCode(error.code)) {+ const spec = RUNTIME_ACTOR_ERRORS[error.code];throw new WikiRefreshCandidateError(- "WIKI_RUNTIME_UNAVAILABLE",- "retryable",- 503,- "The Wiki owner's Local Computer Runtime is unavailable",+ error.code,+ spec.disposition,+ spec.status,+ spec.message,{ cause: error },);}diff --git a/apps/node-services/tests/llm-wiki/wiki-refresh-candidates.llm-wiki.test.ts b/apps/node-services/tests/llm-wiki/wiki-refresh-candidates.llm-wiki.test.tsindex a881ca2d..0995e73c 100644--- a/apps/node-services/tests/llm-wiki/wiki-refresh-candidates.llm-wiki.test.ts+++ b/apps/node-services/tests/llm-wiki/wiki-refresh-candidates.llm-wiki.test.ts@@ -712,7 +712,7 @@ describe("Wiki refresh candidate HTTP API", () => {backend: {id: "test-openwiki",async generate() {- throw new ActorAssetError(code, message);+ throw new ActorAssetError(code, message, disposition);},},});diff --git a/apps/web/src/features/wiki/wiki-refresh-status.test.tsx b/apps/web/src/features/wiki/wiki-refresh-status.test.tsxindex 42033999..63dcba80 100644--- a/apps/web/src/features/wiki/wiki-refresh-status.test.tsx+++ b/apps/web/src/features/wiki/wiki-refresh-status.test.tsx@@ -1,5 +1,6 @@import { render, screen } from "@testing-library/react";import { expect, it } from "vitest";+import type { WikiRefreshFailureReason } from "./wiki-refresh";import { WikiRefreshBanner } from "./wiki-refresh-status";it("shows one quiet line while a refresh writes pages, and the failure", () => {@@ -40,6 +41,14 @@ it("shows one quiet line while a refresh writes pages, and the failure", () => {expect(screen.getByRole("alert")).toHaveTextContent("Wiki update failed — Your Computer was offline.",);+ rerender(+ <WikiRefreshBanner+ failed+ failureReason={"future_reason" as WikiRefreshFailureReason}+ refreshing={false}+ />,+ );+ expect(screen.getByRole("alert")).toHaveTextContent("Wiki update failed");rerender(<WikiRefreshBanner failed={false} refreshing={false} />);expect(screen.queryByRole("status")).toBeNull();});diff --git a/apps/web/src/features/wiki/wiki-refresh-status.tsx b/apps/web/src/features/wiki/wiki-refresh-status.tsxindex 2ebe22d1..b8da6986 100644--- a/apps/web/src/features/wiki/wiki-refresh-status.tsx+++ b/apps/web/src/features/wiki/wiki-refresh-status.tsx@@ -34,9 +34,10 @@ export function WikiRefreshBanner({/>);if (!failed) return null;- const message = failureReason- ? failureMessages[failureReason]- : "Wiki update failed";+ const message =+ failureReason && Object.hasOwn(failureMessages, failureReason)+ ? failureMessages[failureReason]+ : "Wiki update failed";return (<divclassName="mb-6 flex min-h-9 items-center gap-2 rounded-lg border border-[var(--app-status-danger-border)] bg-[var(--app-status-danger-surface)] px-4 py-2 text-xs font-medium text-[var(--app-status-danger-text)]"