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.
feat(wiki): surface actionable Personal Wiki refresh failure reasons
Dongdong Chen99394333f78a
diff --git a/apps/node-services/src/llm-wiki/AGENTS.md b/apps/node-services/src/llm-wiki/AGENTS.mdindex 15e81719..c83af201 100644--- a/apps/node-services/src/llm-wiki/AGENTS.md+++ b/apps/node-services/src/llm-wiki/AGENTS.md@@ -40,10 +40,12 @@files, traversal, normalization collisions, symlinks, and special files. CheckOKF frontmatter, registered node types, and evidence references beforereturning a candidate.-- An invalid candidate or a request too large for one invocation is terminal;- an offline Computer, an unready Runtime, a timeout, or a normalization or- infrastructure failure is retryable, and a generation stopped by this- process's own shutdown answers `WIKI_SERVICE_STOPPING`.+- An invalid candidate, a request too large for one invocation, an incompatible+ Runtime (`WIKI_RUNTIME_INCOMPATIBLE`), or an unauthenticated Runtime+ (`WIKI_RUNTIME_AUTH_REQUIRED`) is terminal; an offline Computer, an unready or+ unavailable Runtime (`WIKI_RUNTIME_UNAVAILABLE`), a timeout, or a+ normalization or infrastructure failure is retryable, and a generation stopped+ by this process's own shutdown answers `WIKI_SERVICE_STOPPING`.- A model task that stalls twice, stays too large after its halvings, or doesnot start before the generation deadline is skipped with an ERROR log, neverfails the refresh. Report the sources a failed task left unwritten, anddiff --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 42ff172e..40c1d1c1 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@@ -3,14 +3,19 @@ export type GenerationFailureDisposition = "retryable" | "terminal";export type ActorAssetErrorCode =| "WIKI_OPERATION_FAILED"| "WIKI_OPERATION_RETRYABLE"- | "WIKI_COMPUTER_OFFLINE";+ | "WIKI_COMPUTER_OFFLINE"+ | "WIKI_RUNTIME_INCOMPATIBLE"+ | "WIKI_RUNTIME_AUTH_REQUIRED"+ | "WIKI_RUNTIME_UNAVAILABLE";export class ActorAssetError extends Error {constructor(readonly code: ActorAssetErrorCode,message: string,readonly disposition: GenerationFailureDisposition = code ===- "WIKI_OPERATION_FAILED"+ "WIKI_OPERATION_FAILED" ||+ code === "WIKI_RUNTIME_INCOMPATIBLE" ||+ code === "WIKI_RUNTIME_AUTH_REQUIRED"? "terminal": "retryable",options?: ErrorOptions,diff --git a/apps/node-services/src/llm-wiki/wiki-candidate-tree.ts b/apps/node-services/src/llm-wiki/wiki-candidate-tree.tsindex 35d7a52f..a571dd89 100644--- a/apps/node-services/src/llm-wiki/wiki-candidate-tree.ts+++ b/apps/node-services/src/llm-wiki/wiki-candidate-tree.ts@@ -129,6 +129,28 @@ export function generationInvocationError(error: unknown): ActorAssetError {"retryable",{ cause: error },);+ if (error instanceof ModelCallError && error.kind === "runtime_unavailable") {+ if (error.runtimeOutcome === "runtime_incompatible")+ return new ActorAssetError(+ "WIKI_RUNTIME_INCOMPATIBLE",+ `The Wiki owner's Local Computer Runtime is incompatible${detail ? `: ${detail}` : ""}`,+ "terminal",+ { cause: error },+ );+ if (error.runtimeOutcome === "auth_required")+ return new ActorAssetError(+ "WIKI_RUNTIME_AUTH_REQUIRED",+ `The Wiki owner's Local Computer Runtime requires sign-in${detail ? `: ${detail}` : ""}`,+ "terminal",+ { cause: error },+ );+ return new ActorAssetError(+ "WIKI_RUNTIME_UNAVAILABLE",+ `The Wiki owner's Local Computer Runtime is unavailable${detail ? `: ${detail}` : ""}`,+ "retryable",+ { cause: error },+ );+ }return new ActorAssetError("WIKI_OPERATION_RETRYABLE",`Wiki Runtime run is temporarily unavailable${detail ? `: ${detail}` : ""}`,diff --git a/apps/node-services/src/llm-wiki/wiki-refresh-candidates.ts b/apps/node-services/src/llm-wiki/wiki-refresh-candidates.tsindex 71dac363..edd68408 100644--- a/apps/node-services/src/llm-wiki/wiki-refresh-candidates.ts+++ b/apps/node-services/src/llm-wiki/wiki-refresh-candidates.ts@@ -57,6 +57,9 @@ export class WikiRefreshCandidateError extends Error {constructor(readonly code:| "WIKI_COMPUTER_OFFLINE"+ | "WIKI_RUNTIME_INCOMPATIBLE"+ | "WIKI_RUNTIME_AUTH_REQUIRED"+ | "WIKI_RUNTIME_UNAVAILABLE"| "WIKI_SERVICE_STOPPING"| "WIKI_REFRESH_CANDIDATE_REQUEST_INVALID"| "WIKI_REFRESH_GENERATION_INVALID"@@ -220,6 +223,42 @@ export class WikiRefreshCandidateService {{ cause: error },);}+ 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"+ ) {+ throw new WikiRefreshCandidateError(+ "WIKI_RUNTIME_UNAVAILABLE",+ "retryable",+ 503,+ "The Wiki owner's Local Computer Runtime is unavailable",+ { cause: error },+ );+ }if (error instanceof ActorAssetError &&error.disposition === "terminal"diff --git a/apps/node-services/src/runtime-model-call.ts b/apps/node-services/src/runtime-model-call.tsindex e4864986..5a5292ae 100644--- a/apps/node-services/src/runtime-model-call.ts+++ b/apps/node-services/src/runtime-model-call.ts@@ -236,6 +236,11 @@ export type ModelCallErrorKind =| "yielded"| "failed";+export type ModelCallRuntimeOutcome =+ | "runtime_unavailable"+ | "auth_required"+ | "runtime_incompatible";+/** Shared by every offline ModelCallError, so a failure that only survives as* a message can still be recognized. */export const COMPUTER_OFFLINE_MESSAGE = "The owner's Local Computer is offline";@@ -245,14 +250,20 @@ export class ModelCallError extends Error {/** The model's text when it did not match the schema, for a correction,* or what it streamed before it timed out or passed its output cap. */readonly output?: string;+ /** The Daemon's structured outcome when kind is runtime_unavailable. */+ readonly runtimeOutcome?: ModelCallRuntimeOutcome;constructor(readonly kind: ModelCallErrorKind,message: string,- options?: ErrorOptions & { readonly output?: string },+ options?: ErrorOptions & {+ readonly output?: string;+ readonly runtimeOutcome?: ModelCallRuntimeOutcome;+ },) {super(message, options);this.output = options?.output;+ this.runtimeOutcome = options?.runtimeOutcome;}}@@ -1234,6 +1245,7 @@ function outcomeFailure(return new ModelCallError("runtime_unavailable",`The Local Computer Runtime cannot run model calls (${outcome.outcome})${reason}`,+ { runtimeOutcome: outcome.outcome },);case "timed_out":return new ModelCallError(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 5cc645c0..a881ca2d 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@@ -18,9 +18,11 @@ import type {LlmWikiGenerateResult,} from "../../src/llm-wiki/backend.js";import { ActorAssetError } from "../../src/llm-wiki/actor-wiki/actor-asset-client.js";+import { generationInvocationError } from "../../src/llm-wiki/wiki-candidate-tree.js";import { renderWikiPage } from "../../src/llm-wiki/wiki-page-template.js";import { WikiRefreshCandidateService } from "../../src/llm-wiki/wiki-refresh-candidates.js";import { WikiCandidateValidationError } from "../../src/llm-wiki/wiki-candidate-validation.js";+import { ModelCallError } from "../../src/runtime-model-call.js";import { closeWikiServers, startWikiServer } from "./wiki-server-host.js";const serviceToken = "wiki-candidate-service-token-for-test";@@ -684,6 +686,70 @@ describe("Wiki refresh candidate HTTP API", () => {});});+ it.each([+ [+ "WIKI_RUNTIME_INCOMPATIBLE",+ "terminal",+ 500,+ "The Wiki owner's Local Computer Runtime is incompatible",+ ],+ [+ "WIKI_RUNTIME_AUTH_REQUIRED",+ "terminal",+ 500,+ "The Wiki owner's Local Computer Runtime requires sign-in",+ ],+ [+ "WIKI_RUNTIME_UNAVAILABLE",+ "retryable",+ 503,+ "The Wiki owner's Local Computer Runtime is unavailable",+ ],+ ] as const)(+ "reports %s with its own code and disposition",+ async (code, disposition, status, message) => {+ const { httpUrl } = await startServer({+ backend: {+ id: "test-openwiki",+ async generate() {+ throw new ActorAssetError(code, message);+ },+ },+ });++ const response = await fetch(+ `${httpUrl}/internal/v1/wiki-refreshes/refresh-a/candidates`,+ requestInit(candidateRequest(1)),+ );++ expect(response.status).toBe(status);+ await expect(response.json()).resolves.toEqual({+ error: { code, disposition, message },+ });+ },+ );++ it.each([+ ["runtime_incompatible", "WIKI_RUNTIME_INCOMPATIBLE", "terminal"],+ ["auth_required", "WIKI_RUNTIME_AUTH_REQUIRED", "terminal"],+ ["runtime_unavailable", "WIKI_RUNTIME_UNAVAILABLE", "retryable"],+ [undefined, "WIKI_RUNTIME_UNAVAILABLE", "retryable"],+ ] as const)(+ "maps ModelCallError runtimeOutcome %s to %s (%s)",+ (runtimeOutcome, wantCode, wantDisposition) => {+ const mapped = generationInvocationError(+ new ModelCallError("runtime_unavailable", "Runtime cannot run", {+ ...(runtimeOutcome ? { runtimeOutcome } : {}),+ }),+ );+ expect(mapped).toBeInstanceOf(ActorAssetError);+ expect(mapped).toMatchObject({+ code: wantCode,+ disposition: wantDisposition,+ });+ },+ );+it("does not retry a terminal OpenWiki invocation failure", async () => {const { httpUrl } = await startServer({backend: {diff --git a/apps/node-services/tests/runtime-model-call.test.ts b/apps/node-services/tests/runtime-model-call.test.tsindex 512c5bb0..7cf2f372 100644--- a/apps/node-services/tests/runtime-model-call.test.ts+++ b/apps/node-services/tests/runtime-model-call.test.ts@@ -358,22 +358,29 @@ describe("Runtime model call", () => {});it.each([- ["unavailable", "computer_offline"],- ["runtime_unavailable", "runtime_unavailable"],- ["auth_required", "runtime_unavailable"],- ["runtime_incompatible", "runtime_unavailable"],- ["timed_out", "timed_out"],- ["output_limited", "output_limited"],- ["failed", "failed"],- ] as const)("maps a %s outcome to %s", async (outcome, kind) => {- const { modelCall } = setup({- placements: [alice],- outcomes: [{ outcome, duration_ms: 0 }],- });- await expect(- modelCall.text({ ...work, kind: "approval", input: "x" }),- ).rejects.toMatchObject({ name: "ModelCallError", kind });- });+ ["unavailable", "computer_offline", undefined],+ ["runtime_unavailable", "runtime_unavailable", "runtime_unavailable"],+ ["auth_required", "runtime_unavailable", "auth_required"],+ ["runtime_incompatible", "runtime_unavailable", "runtime_incompatible"],+ ["timed_out", "timed_out", undefined],+ ["output_limited", "output_limited", undefined],+ ["failed", "failed", undefined],+ ] as const)(+ "maps a %s outcome to %s",+ async (outcome, kind, runtimeOutcome) => {+ const { modelCall } = setup({+ placements: [alice],+ outcomes: [{ outcome, duration_ms: 0 }],+ });+ await expect(+ modelCall.text({ ...work, kind: "approval", input: "x" }),+ ).rejects.toMatchObject({+ name: "ModelCallError",+ kind,+ ...(runtimeOutcome ? { runtimeOutcome } : {}),+ });+ },+ );it("corrects an answer that breaks the schema within the kind's attempts", async () => {const corrected = setup({diff --git a/apps/teamhub/internal/app/handlers_personal_wiki.go b/apps/teamhub/internal/app/handlers_personal_wiki.goindex cc857fd9..6157819a 100644--- a/apps/teamhub/internal/app/handlers_personal_wiki.go+++ b/apps/teamhub/internal/app/handlers_personal_wiki.go@@ -199,6 +199,10 @@ func personalWikiModel(wiki document.PersonalWiki) httpapi.PersonalWiki {if wiki.LatestRefreshID != "" {model.LatestRefreshId = &wiki.LatestRefreshID}+ if wiki.FailureReason != "" {+ reason := httpapi.PersonalWikiFailureReason(wiki.FailureReason)+ model.FailureReason = &reason+ }if wiki.CurrentRevisionID != "" {model.CurrentRevisionId = &wiki.CurrentRevisionID}diff --git a/apps/teamhub/internal/document/personal_wiki.go b/apps/teamhub/internal/document/personal_wiki.goindex c6f4f416..63db3014 100644--- a/apps/teamhub/internal/document/personal_wiki.go+++ b/apps/teamhub/internal/document/personal_wiki.go@@ -20,7 +20,10 @@ type PersonalWiki struct {OwnerActorID stringPublishedGeneration int64// State is idle, refreshing or failed (WikiRefreshState).- State string+ State string+ // FailureReason names an actionable Computer or Runtime cause when State is+ // failed, otherwise empty.+ FailureReason stringLatestRefreshID stringPreviewRevision int64CurrentRevisionID string@@ -52,7 +55,7 @@ func (s *Service) GetPersonalWiki(ctx context.Context, accountID, tenantID strinreturn PersonalWiki{}, err}wiki.PreviewRevision = state.PreviewRevision- wiki.State, wiki.LatestRefreshID = state.State, state.LatestRefreshID+ wiki.State, wiki.FailureReason, wiki.LatestRefreshID = state.State, state.FailureReason, state.LatestRefreshIDreturn wiki, nil}diff --git a/apps/teamhub/internal/document/wiki_candidate_dispatch_test.go b/apps/teamhub/internal/document/wiki_candidate_dispatch_test.goindex 0ddf32b7..09b0c213 100644--- a/apps/teamhub/internal/document/wiki_candidate_dispatch_test.go+++ b/apps/teamhub/internal/document/wiki_candidate_dispatch_test.go@@ -103,6 +103,42 @@ func TestUnifiedWikiCandidateGeneratorClassifiesStoppingService(t *testing.T) {}}+func TestUnifiedWikiCandidateGeneratorClassifiesRuntimeErrors(t *testing.T) {+ for _, testCase := range []struct {+ code string+ disposition string+ status int+ want error+ }{+ {"WIKI_RUNTIME_INCOMPATIBLE", "terminal", http.StatusInternalServerError, document.ErrWikiCandidateRuntimeIncompatible},+ {"WIKI_RUNTIME_AUTH_REQUIRED", "terminal", http.StatusInternalServerError, document.ErrWikiCandidateRuntimeAuthRequired},+ {"WIKI_RUNTIME_UNAVAILABLE", "retryable", http.StatusServiceUnavailable, document.ErrWikiCandidateRuntimeUnavailable},+ } {+ t.Run(testCase.code, func(t *testing.T) {+ server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {+ writer.Header().Set("Content-Type", "application/json")+ writer.WriteHeader(testCase.status)+ _ = json.NewEncoder(writer).Encode(map[string]any{+ "error": map[string]any{+ "code": testCase.code,+ "disposition": testCase.disposition,+ "message": "runtime failure",+ },+ })+ }))+ defer server.Close()+ generator, err := document.NewHTTPWikiCandidateGenerator(server.URL, "service-token-for-test", server.Client())+ if err != nil {+ t.Fatal(err)+ }+ _, err = generator.GenerateWikiCandidates(context.Background(), wikiCandidateRequest())+ if !errors.Is(err, testCase.want) {+ t.Fatalf("error=%v want %v", err, testCase.want)+ }+ })+ }+}+func TestUnifiedWikiCandidateGeneratorRejectsLegacyOrInvalidSettlementShape(t *testing.T) {server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {_, _ = writer.Write([]byte(`{"wiki_refresh_id":"document_wiki_refresh_test","pages":[],"generation_id":"legacy"}`))diff --git a/apps/teamhub/internal/document/wiki_candidate_http.go b/apps/teamhub/internal/document/wiki_candidate_http.goindex 86b86fd0..98068afc 100644--- a/apps/teamhub/internal/document/wiki_candidate_http.go+++ b/apps/teamhub/internal/document/wiki_candidate_http.go@@ -30,6 +30,18 @@ const wikiComputerOfflineCode = "WIKI_COMPUTER_OFFLINE"// restarting process stopped.const wikiServiceStoppingCode = "WIKI_SERVICE_STOPPING"+// wikiRuntimeIncompatibleCode is the LLM Wiki error code when the owner's+// Local Computer Runtime rejects the model invocation as incompatible.+const wikiRuntimeIncompatibleCode = "WIKI_RUNTIME_INCOMPATIBLE"++// wikiRuntimeAuthRequiredCode is the LLM Wiki error code when the owner's+// Local Computer Runtime needs sign-in before running model calls.+const wikiRuntimeAuthRequiredCode = "WIKI_RUNTIME_AUTH_REQUIRED"++// wikiRuntimeUnavailableCode is the LLM Wiki error code when the owner's+// Local Computer Runtime is not ready to run model calls.+const wikiRuntimeUnavailableCode = "WIKI_RUNTIME_UNAVAILABLE"+var wikiCandidateIDPattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$`)type HTTPWikiCandidateGenerator struct {@@ -146,6 +158,15 @@ func (g *HTTPWikiCandidateGenerator) GenerateWikiCandidates(if decodeErr == nil && failure.Error.Code == wikiServiceStoppingCode {return WikiCandidateGenerationResult{}, fmt.Errorf("%w: Wiki candidate response status=%d", ErrWikiCandidateServiceStopping, response.StatusCode)}+ if decodeErr == nil && failure.Error.Code == wikiRuntimeIncompatibleCode {+ return WikiCandidateGenerationResult{}, fmt.Errorf("%w: Wiki candidate response status=%d", ErrWikiCandidateRuntimeIncompatible, response.StatusCode)+ }+ if decodeErr == nil && failure.Error.Code == wikiRuntimeAuthRequiredCode {+ return WikiCandidateGenerationResult{}, fmt.Errorf("%w: Wiki candidate response status=%d", ErrWikiCandidateRuntimeAuthRequired, response.StatusCode)+ }+ if decodeErr == nil && failure.Error.Code == wikiRuntimeUnavailableCode {+ return WikiCandidateGenerationResult{}, fmt.Errorf("%w: Wiki candidate response status=%d", ErrWikiCandidateRuntimeUnavailable, response.StatusCode)+ }if decodeErr == nil && failure.Error.Disposition == nodeservicesinternal.Terminal {// Do not include the remote message: it may contain provider/source data.sentinel := ErrWikiCandidateTerminaldiff --git a/apps/teamhub/internal/document/wiki_dispatch_recovery_test.go b/apps/teamhub/internal/document/wiki_dispatch_recovery_test.goindex 19c1ac7c..41f91315 100644--- a/apps/teamhub/internal/document/wiki_dispatch_recovery_test.go+++ b/apps/teamhub/internal/document/wiki_dispatch_recovery_test.go@@ -49,7 +49,7 @@ func TestWikiDispatchWaitsForOfflineComputerWithoutSpendingAttempts(t *testing.T})}_, _, code, err := validateWikiCandidateGenerationResult("refresh", WikiCandidateGenerationResult{}, offline)- if code != "candidate_unavailable" || !errors.Is(err, ErrWikiCandidateComputerOffline) || isWikiCandidateTerminal(err) {+ if code != "computer_offline" || !errors.Is(err, ErrWikiCandidateComputerOffline) || isWikiCandidateTerminal(err) {t.Fatalf("code=%s error=%v", code, err)}}@@ -71,6 +71,9 @@ func TestWikiCandidateGenerationResultPreservesFailureCodeAndRetrySemantics(t *t}{{name: "valid", result: valid},{name: "terminal", result: valid, err: fmt.Errorf("wrapped: %w", ErrWikiCandidateTerminal), wantCode: "candidate_unavailable", wantCause: ErrWikiCandidateTerminal, wantTerminal: true},+ {name: "runtime incompatible", result: valid, err: fmt.Errorf("wrapped: %w", ErrWikiCandidateRuntimeIncompatible), wantCode: "runtime_incompatible", wantCause: ErrWikiCandidateRuntimeIncompatible, wantTerminal: true},+ {name: "runtime auth required", result: valid, err: fmt.Errorf("wrapped: %w", ErrWikiCandidateRuntimeAuthRequired), wantCode: "runtime_auth_required", wantCause: ErrWikiCandidateRuntimeAuthRequired, wantTerminal: true},+ {name: "runtime unavailable", result: valid, err: fmt.Errorf("wrapped: %w", ErrWikiCandidateRuntimeUnavailable), wantCode: "runtime_unavailable", wantCause: ErrWikiCandidateRuntimeUnavailable},{name: "invalid frozen input", result: valid, err: fmt.Errorf("wrapped: %w", ErrWikiCandidateInvalidRequest), wantCode: "candidate_invalid", wantCause: ErrWikiCandidateInvalidRequest, wantTerminal: true},{name: "transport", result: valid, err: transportErr, wantCode: "candidate_unavailable", wantCause: transportErr, wantRuntime: true},{name: "source read", result: valid, err: fmt.Errorf("wrapped: %w", &wikiSourceReadError{code: "object_unavailable", err: sourceErr}), wantCode: "object_unavailable", wantCause: sourceErr},@@ -176,6 +179,24 @@ func TestWikiDuplicateCandidateConflictIsRetryable(t *testing.T) {// and it looks only at jobs running longer than the client's rescue horizon.// The dispatch timeout must exceed that horizon so a long generation is not// rescued while it is still running.+func TestPersonalWikiFailureReasonExposesOnlyActionableCodes(t *testing.T) {+ for code, want := range map[string]string{+ "computer_offline": "computer_offline",+ "runtime_incompatible": "runtime_incompatible",+ "runtime_auth_required": "runtime_auth_required",+ "runtime_unavailable": "runtime_unavailable",+ "candidate_unavailable": "",+ "candidate_invalid": "",+ "object_unavailable": "",+ "settlement_unavailable": "",+ "": "",+ } {+ if got := personalWikiFailureReason(code); got != want {+ t.Fatalf("personalWikiFailureReason(%q) = %q, want %q", code, got, want)+ }+ }+}+func TestWikiRefreshDispatchTimeoutExceedsRescueHorizon(t *testing.T) {horizon := jobs.RescueStuckJobsAfterworker := &wikiRefreshDispatchWorker{dispatcher: &WikiRefreshDispatcher{options: WikiRefreshDispatchOptions{diff --git a/apps/teamhub/internal/document/wiki_dispatcher.go b/apps/teamhub/internal/document/wiki_dispatcher.goindex 11a3c7d6..888d0cfd 100644--- a/apps/teamhub/internal/document/wiki_dispatcher.go+++ b/apps/teamhub/internal/document/wiki_dispatcher.go@@ -116,6 +116,19 @@ var ErrWikiCandidateComputerOffline = errors.New("Wiki owner's Computer is offli// without spending an attempt.var ErrWikiCandidateServiceStopping = errors.New("LLM Wiki is stopping")+// ErrWikiCandidateRuntimeIncompatible means the Wiki owner's Local Computer+// Runtime rejected model invocation as incompatible. Retrying the same refresh+// cannot fix it, while a later refresh can retry once the Runtime is updated.+var ErrWikiCandidateRuntimeIncompatible = errors.New("Wiki owner's Local Computer Runtime is incompatible")++// ErrWikiCandidateRuntimeAuthRequired means the Wiki owner's Local Computer+// Runtime requires sign-in before running model calls.+var ErrWikiCandidateRuntimeAuthRequired = errors.New("Wiki owner's Local Computer Runtime requires sign-in")++// ErrWikiCandidateRuntimeUnavailable means the Wiki owner's Local Computer+// Runtime is not currently ready to run model calls.+var ErrWikiCandidateRuntimeUnavailable = errors.New("Wiki owner's Local Computer Runtime is unavailable")+// ErrWikiCandidateInvalidRequest marks frozen input that cannot be normalized,// a request or result that fails TeamHub's own candidate checks, or page heads// that cannot be reconciled without a new source delta. The same source set@@ -234,8 +247,19 @@ func validateWikiCandidateGenerationResult(if errors.Is(err, ErrWikiCandidateInvalidRequest) || errors.Is(err, ErrInvalidInput) {return nil, "", "candidate_invalid", err}- if errors.Is(err, ErrWikiCandidateTerminal) || errors.Is(err, ErrWikiCandidateComputerOffline) ||- errors.Is(err, ErrWikiCandidateServiceStopping) {+ if errors.Is(err, ErrWikiCandidateComputerOffline) {+ return nil, "", "computer_offline", err+ }+ if errors.Is(err, ErrWikiCandidateRuntimeIncompatible) {+ return nil, "", "runtime_incompatible", err+ }+ if errors.Is(err, ErrWikiCandidateRuntimeAuthRequired) {+ return nil, "", "runtime_auth_required", err+ }+ if errors.Is(err, ErrWikiCandidateRuntimeUnavailable) {+ return nil, "", "runtime_unavailable", err+ }+ if errors.Is(err, ErrWikiCandidateTerminal) || errors.Is(err, ErrWikiCandidateServiceStopping) {return nil, "", "candidate_unavailable", err}return nil, "", "candidate_unavailable", errors.Join(ErrRuntimeUnavailable, err)@@ -603,5 +627,7 @@ func (d *WikiRefreshDispatcher) readExactObject(// isWikiCandidateTerminal reports rejections that retrying cannot fix.func isWikiCandidateTerminal(err error) bool {- return errors.Is(err, ErrWikiCandidateTerminal) || errors.Is(err, ErrWikiCandidateInvalidRequest) || errors.Is(err, ErrInvalidInput)+ return errors.Is(err, ErrWikiCandidateTerminal) || errors.Is(err, ErrWikiCandidateInvalidRequest) ||+ errors.Is(err, ErrWikiCandidateRuntimeIncompatible) || errors.Is(err, ErrWikiCandidateRuntimeAuthRequired) ||+ errors.Is(err, ErrInvalidInput)}diff --git a/apps/teamhub/internal/document/wiki_state.go b/apps/teamhub/internal/document/wiki_state.goindex 00270d33..d121977a 100644--- a/apps/teamhub/internal/document/wiki_state.go+++ b/apps/teamhub/internal/document/wiki_state.go@@ -12,6 +12,9 @@ type WikiRefreshState struct {// State is refreshing while a refresh runs or its follow-up is queued,// failed when the latest refresh failed or conflicted, otherwise idle.State string+ // FailureReason names an actionable Computer or Runtime cause when State is+ // failed, otherwise empty.+ FailureReason string// LatestRefreshID names the latest refresh, so a client that saw an// earlier failure can tell a new one apart.LatestRefreshID string@@ -22,22 +25,44 @@ type WikiRefreshState struct {// no Wiki root yet is idle.func LoadWikiRefreshState(ctx context.Context, tx pgx.Tx, tenantID, ownerActorID string) (WikiRefreshState, error) {var state WikiRefreshState+ var lastErrorCode stringerr := tx.QueryRow(ctx, `SELECT coalesce(refresh.id,''), coalesce(refresh.preview_revision,0),CASEWHEN refresh.status='staging' THEN 'refreshing'WHEN refresh.id IS NOT NULL AND `+wikiRefreshFollowupPendingSQL+` THEN 'refreshing'WHEN refresh.status IN ('failed','conflicted') THEN 'failed'ELSE 'idle'+ END,+ CASE+ WHEN refresh.status='failed' THEN coalesce(refresh.dispatch_last_error_code,'')+ ELSE ''ENDFROM (SELECT $1::text AS tenant_id,$2::text AS actor_id) ownerLEFT JOIN personal_wikis wiki ON wiki.tenant_id=owner.tenant_idAND wiki.owner_actor_id=owner.actor_id AND wiki.deleted_at IS NULLLEFT JOIN LATERAL (- SELECT id,status,preview_revision FROM document_wiki_refreshes+ SELECT id,status,preview_revision,dispatch_last_error_code FROM document_wiki_refreshesWHERE wiki_id=wiki.id AND tenant_id=wiki.tenant_idORDER BY created_at DESC,id DESC LIMIT 1) refresh ON true`, tenantID, ownerActorID).Scan(- &state.LatestRefreshID, &state.PreviewRevision, &state.State,+ &state.LatestRefreshID, &state.PreviewRevision, &state.State, &lastErrorCode,)- return state, err+ if err != nil {+ return WikiRefreshState{}, err+ }+ if state.State == "failed" {+ state.FailureReason = personalWikiFailureReason(lastErrorCode)+ }+ return state, nil+}++// personalWikiFailureReason maps stored dispatch error codes to the actionable+// reasons exposed on the Personal Wiki status response.+func personalWikiFailureReason(code string) string {+ switch code {+ case "computer_offline", "runtime_incompatible", "runtime_auth_required", "runtime_unavailable":+ return code+ default:+ return ""+ }}diff --git a/apps/teamhub/migrations/00883_wiki_refresh_failure_codes.sql b/apps/teamhub/migrations/00883_wiki_refresh_failure_codes.sqlnew file mode 100644index 00000000..010e34d4--- /dev/null+++ b/apps/teamhub/migrations/00883_wiki_refresh_failure_codes.sql@@ -0,0 +1,25 @@+-- +goose Up+-- Carry structured Computer and Runtime failure codes on Wiki refreshes so the+-- Wiki status banner can surface actionable causes such as runtime_incompatible.+ALTER TABLE public.document_wiki_refreshes+ DROP CONSTRAINT document_wiki_refreshes_dispatch_last_error_code_check;++ALTER TABLE public.document_wiki_refreshes+ ADD CONSTRAINT document_wiki_refreshes_dispatch_last_error_code_check CHECK (+ dispatch_last_error_code IS NULL OR dispatch_last_error_code = ANY (ARRAY[+ 'object_unavailable'::text,+ 'object_mismatch'::text,+ 'candidate_unavailable'::text,+ 'candidate_invalid'::text,+ 'settlement_unavailable'::text,+ 'computer_offline'::text,+ 'runtime_incompatible'::text,+ 'runtime_auth_required'::text,+ 'runtime_unavailable'::text+ ])+ );++-- +goose Down+-- +goose StatementBegin+DO $$ BEGIN RAISE EXCEPTION 'wiki refresh failure codes migration is forward-only'; END $$;+-- +goose StatementEnddiff --git a/apps/web/src/features/wiki/wiki-home-page.test.tsx b/apps/web/src/features/wiki/wiki-home-page.test.tsxindex 588b0c66..020ab133 100644--- a/apps/web/src/features/wiki/wiki-home-page.test.tsx+++ b/apps/web/src/features/wiki/wiki-home-page.test.tsx@@ -113,3 +113,40 @@ it("shows the pages a refresh has written as ordinary cards that open as pages",);expect(screen.queryByText("No topics yet.")).toBeNull();});++it("shows the actionable failure reason when the latest Wiki refresh failed", async () => {+ const runtime = createTestTeamHubRuntime();+ serveWikiDocuments(runtime).mockResolvedValue({+ items: [],+ page: { has_more: false },+ });+ serveWikiStatus(runtime).mockResolvedValue({+ created_at: "2026-08-23T00:00:00.000Z",+ failure_reason: "runtime_incompatible",+ id: "wiki-tenant-northstar",+ latest_refresh_id: "refresh-2",+ owner_actor_id: "actor-human",+ published_generation: 0,+ state: "failed",+ tenant_id: "tenant-northstar",+ updated_at: "2026-08-23T00:00:00.000Z",+ });+ const router = createMemoryRouter(+ [{ path: "/t/:tenantId/library/wiki", element: <WikiHomePage /> }],+ { initialEntries: ["/t/tenant-northstar/library/wiki?tab=wiki"] },+ );+ render(+ <QueryClientProvider+ client={+ new QueryClient({ defaultOptions: { queries: { retry: false } } })+ }+ >+ <TeamHubRuntimeProvider runtime={runtime}>+ <RouterProvider router={router} />+ </TeamHubRuntimeProvider>+ </QueryClientProvider>,+ );+ expect(await screen.findByRole("alert")).toHaveTextContent(+ "Wiki update failed — Runtime incompatible. Update your local CLI or Linger.",+ );+});diff --git a/apps/web/src/features/wiki/wiki-refresh-status.test.tsx b/apps/web/src/features/wiki/wiki-refresh-status.test.tsxindex ed9616d1..42033999 100644--- a/apps/web/src/features/wiki/wiki-refresh-status.test.tsx+++ b/apps/web/src/features/wiki/wiki-refresh-status.test.tsx@@ -10,6 +10,36 @@ it("shows one quiet line while a refresh writes pages, and the failure", () => {expect(screen.getByRole("status")).not.toHaveTextContent(/ready/u);rerender(<WikiRefreshBanner failed refreshing={false} />);expect(screen.getByRole("alert")).toHaveTextContent("Wiki update failed");+ rerender(+ <WikiRefreshBanner+ failed+ failureReason="runtime_incompatible"+ refreshing={false}+ />,+ );+ expect(screen.getByRole("alert")).toHaveTextContent(+ "Wiki update failed — Runtime incompatible. Update your local CLI or Linger.",+ );+ rerender(+ <WikiRefreshBanner+ failed+ failureReason="runtime_auth_required"+ refreshing={false}+ />,+ );+ expect(screen.getByRole("alert")).toHaveTextContent(+ "Wiki update failed — Runtime sign-in required.",+ );+ rerender(+ <WikiRefreshBanner+ failed+ failureReason="computer_offline"+ refreshing={false}+ />,+ );+ expect(screen.getByRole("alert")).toHaveTextContent(+ "Wiki update failed — Your Computer was offline.",+ );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 486d0ede..2ebe22d1 100644--- a/apps/web/src/features/wiki/wiki-refresh-status.tsx+++ b/apps/web/src/features/wiki/wiki-refresh-status.tsx@@ -1,16 +1,28 @@import { AlertCircleIcon } from "@hugeicons/core-free-icons";import { Icon } from "@/components/ui/icon";-import type { WikiRefreshStatus } from "./wiki-refresh";+import type {+ WikiRefreshFailureReason,+ WikiRefreshStatus,+} from "./wiki-refresh";import { WikiWorkingLine } from "./wiki-working-card";+const failureMessages: Record<WikiRefreshFailureReason, string> = {+ computer_offline: "Wiki update failed — Your Computer was offline.",+ runtime_auth_required: "Wiki update failed — Runtime sign-in required.",+ runtime_incompatible:+ "Wiki update failed — Runtime incompatible. Update your local CLI or Linger.",+ runtime_unavailable: "Wiki update failed — Local Runtime is unavailable.",+};+/** What the Wiki home says while a refresh writes pages, or after one failed.* The pages written so far appear in their collections as ordinary cards. */export function WikiRefreshBanner({agentActorId,failed,+ failureReason,refreshing,-}: Pick<WikiRefreshStatus, "failed" | "refreshing"> & {+}: Pick<WikiRefreshStatus, "failed" | "failureReason" | "refreshing"> & {agentActorId?: string;}) {if (refreshing)@@ -22,13 +34,16 @@ export function WikiRefreshBanner({/>);if (!failed) return null;+ const message = 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)]"role="alert"><Icon icon={AlertCircleIcon} size={14} />- Wiki update failed+ {message}</div>);}diff --git a/apps/web/src/features/wiki/wiki-refresh.ts b/apps/web/src/features/wiki/wiki-refresh.tsindex 86f1d3dc..3ce22aed 100644--- a/apps/web/src/features/wiki/wiki-refresh.ts+++ b/apps/web/src/features/wiki/wiki-refresh.ts@@ -1,3 +1,4 @@+import type { components } from "@linger/wire-contracts/teamhub-public/types";import { useQuery, useQueryClient } from "@tanstack/react-query";import { useEffect, useRef } from "react";@@ -5,9 +6,13 @@ import { personalWikiDocumentsQueryKey } from "@/features/teamhub/document-queriimport { teamHubData } from "@/features/teamhub/teamhub-api";import { useTeamHubRuntime } from "@/features/teamhub/teamhub-runtime";+export type WikiRefreshFailureReason =+ components["schemas"]["PersonalWikiFailureReason"];+export interface WikiRefreshStatus {preview?: Record<string, string>;failed: boolean;+ failureReason?: WikiRefreshFailureReason;initializing: boolean;refreshing: boolean;}@@ -91,6 +96,8 @@ export function usePersonalWikiRefresh(tenantId: string): WikiRefreshStatus {return {preview: refreshing && revision ? preview.data : undefined,failed: wiki.data?.state === "failed",+ failureReason:+ wiki.data?.state === "failed" ? wiki.data.failure_reason : undefined,initializing: refreshing && wiki.data?.published_generation === 0,refreshing,};diff --git a/contracts/generated/go/teamhubpublic/openapi.gen.go b/contracts/generated/go/teamhubpublic/openapi.gen.goindex b144a665..d366fffd 100644--- a/contracts/generated/go/teamhubpublic/openapi.gen.go+++ b/contracts/generated/go/teamhubpublic/openapi.gen.go@@ -3062,6 +3062,30 @@ func (e PersonalProfileSourceSelectionKind) Valid() bool {}}+// Defines values for PersonalWikiFailureReason.+const (+ ComputerOffline PersonalWikiFailureReason = "computer_offline"+ RuntimeAuthRequired PersonalWikiFailureReason = "runtime_auth_required"+ RuntimeIncompatible PersonalWikiFailureReason = "runtime_incompatible"+ RuntimeUnavailable PersonalWikiFailureReason = "runtime_unavailable"+)++// Valid indicates whether the value is a known member of the PersonalWikiFailureReason enum.+func (e PersonalWikiFailureReason) Valid() bool {+ switch e {+ case ComputerOffline:+ return true+ case RuntimeAuthRequired:+ return true+ case RuntimeIncompatible:+ return true+ case RuntimeUnavailable:+ return true+ default:+ return false+ }+}+// Defines values for PersonalWikiState.const (PersonalWikiStateFailed PersonalWikiState = "failed"@@ -7619,6 +7643,9 @@ type PersonalWiki struct {// CurrentRevisionId Opaque, case-sensitive identifier. Clients must not infer type or time from it.CurrentRevisionId *Id `json:"current_revision_id,omitempty"`+ // FailureReason Actionable cause of the latest failed refresh when known: computer_offline, runtime_incompatible, runtime_auth_required, or runtime_unavailable.+ FailureReason *PersonalWikiFailureReason `json:"failure_reason,omitempty"`+// Id Opaque, case-sensitive identifier. Clients must not infer type or time from it.Id *Id `json:"id,omitempty"`@@ -7644,6 +7671,9 @@ type PersonalWiki struct {UpdatedAt *Timestamp `json:"updated_at,omitempty"`}+// PersonalWikiFailureReason Actionable cause of the latest failed refresh when known: computer_offline, runtime_incompatible, runtime_auth_required, or runtime_unavailable.+type PersonalWikiFailureReason string+// PersonalWikiState refreshing while a refresh runs or its follow-up is queued; failed when the latest refresh failed or conflicted.type PersonalWikiState stringdiff --git a/contracts/generated/typescript/src/generated/node-services-internal/types.ts b/contracts/generated/typescript/src/generated/node-services-internal/types.tsindex b963a3db..bdb0105f 100644--- a/contracts/generated/typescript/src/generated/node-services-internal/types.ts+++ b/contracts/generated/typescript/src/generated/node-services-internal/types.ts@@ -2096,7 +2096,7 @@ export interface components {"application/json": components["schemas"]["WikiRefreshCandidateErrorResponse"];};};- /** @description Candidate generation encountered a retryable infrastructure or provider failure. The code WIKI_COMPUTER_OFFLINE means the Wiki owner's Computer is offline; TeamHub waits for it without spending a refresh attempt. The code WIKI_SERVICE_STOPPING means LLM Wiki stopped the generation because its process is restarting; TeamHub runs it again shortly, also without spending an attempt. */+ /** @description Candidate generation encountered a retryable infrastructure or provider failure. The code WIKI_COMPUTER_OFFLINE means the Wiki owner's Computer is offline; TeamHub waits for it without spending a refresh attempt. The code WIKI_SERVICE_STOPPING means LLM Wiki stopped the generation because its process is restarting; TeamHub runs it again shortly, also without spending an attempt. The code WIKI_RUNTIME_UNAVAILABLE means the owner's Local Computer Runtime is not ready for model calls. */WikiOperationRetryable: {headers: {[name: string]: unknown;@@ -3241,7 +3241,7 @@ export interface operations {};};413: components["responses"]["WikiRefreshBadRequest"];- /** @description The generated candidate is invalid; do not retry the same refresh. */+ /** @description The refresh cannot be completed without user action or new inputs; do not retry the same refresh. Codes WIKI_RUNTIME_INCOMPATIBLE and WIKI_RUNTIME_AUTH_REQUIRED indicate that the owner's Local Computer Runtime must be updated or signed in before a later refresh runs. */500: {headers: {[name: string]: unknown;diff --git a/contracts/generated/typescript/src/generated/teamhub-public/types.ts b/contracts/generated/typescript/src/generated/teamhub-public/types.tsindex 1e22136a..96d24e94 100644--- a/contracts/generated/typescript/src/generated/teamhub-public/types.ts+++ b/contracts/generated/typescript/src/generated/teamhub-public/types.ts@@ -6800,6 +6800,15 @@ export interface components {* @enum {string}*/PersonalWikiState: "idle" | "refreshing" | "failed";+ /**+ * @description Actionable cause of the latest failed refresh when known: computer_offline, runtime_incompatible, runtime_auth_required, or runtime_unavailable.+ * @enum {string}+ */+ PersonalWikiFailureReason:+ | "computer_offline"+ | "runtime_incompatible"+ | "runtime_auth_required"+ | "runtime_unavailable";PersonalWiki: {/** @description Absent until a write (binding or uploading a source, a refresh request from Memory) creates the Wiki root. */id?: components["schemas"]["Id"];@@ -6811,6 +6820,8 @@ export interface components {*/published_generation: number;state: components["schemas"]["PersonalWikiState"];+ /** @description Present when state is failed and the refresh failed for an actionable Computer or Runtime cause. */+ failure_reason?: components["schemas"]["PersonalWikiFailureReason"];/*** Format: int64* @description Advances when the active refresh has a new three-minute preview.diff --git a/contracts/openapi/components/personal-wiki.yaml b/contracts/openapi/components/personal-wiki.yamlindex 722638c4..f0055cee 100644--- a/contracts/openapi/components/personal-wiki.yaml+++ b/contracts/openapi/components/personal-wiki.yaml@@ -4,6 +4,16 @@ components:type: stringdescription: refreshing while a refresh runs or its follow-up is queued; failed when the latest refresh failed or conflicted.enum: [idle, refreshing, failed]+ PersonalWikiFailureReason:+ type: string+ description: >-+ Actionable cause of the latest failed refresh when known: computer_offline,+ runtime_incompatible, runtime_auth_required, or runtime_unavailable.+ enum:+ - computer_offline+ - runtime_incompatible+ - runtime_auth_required+ - runtime_unavailablePersonalWiki:type: objectadditionalProperties: false@@ -23,6 +33,9 @@ components:description: Advances by one with each published Revision.state:$ref: "#/components/schemas/PersonalWikiState"+ failure_reason:+ description: Present when state is failed and the refresh failed for an actionable Computer or Runtime cause.+ $ref: "#/components/schemas/PersonalWikiFailureReason"preview_revision:type: integerformat: int64diff --git a/contracts/openapi/node-services-internal/openapi.yaml b/contracts/openapi/node-services-internal/openapi.yamlindex 935277fc..816b775f 100644--- a/contracts/openapi/node-services-internal/openapi.yaml+++ b/contracts/openapi/node-services-internal/openapi.yaml@@ -1195,7 +1195,11 @@ paths:"413":$ref: "#/components/responses/WikiRefreshBadRequest""500":- description: The generated candidate is invalid; do not retry the same refresh.+ description: >-+ The refresh cannot be completed without user action or new inputs; do+ not retry the same refresh. Codes WIKI_RUNTIME_INCOMPATIBLE and+ WIKI_RUNTIME_AUTH_REQUIRED indicate that the owner's Local Computer+ Runtime must be updated or signed in before a later refresh runs.content:application/json:schema:@@ -3118,7 +3122,8 @@ components:is offline; TeamHub waits for it without spending a refresh attempt.The code WIKI_SERVICE_STOPPING means LLM Wiki stopped the generationbecause its process is restarting; TeamHub runs it again shortly,- also without spending an attempt.+ also without spending an attempt. The code WIKI_RUNTIME_UNAVAILABLE+ means the owner's Local Computer Runtime is not ready for model calls.content:application/json:schema: