The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): missing files in previews name the checked path instead of asking to reconnect (#32994)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 10, 2026 at 04:08 UTC
5a9866d50130080fccfd5af2d951edfa1ebc57d0
6 files changed
+79
-13
apps/mobile/src/components/ui/FilePreviewSession.test.tsx
+29
-2
@@ -1,10 +1,16 @@
1
import { act, useState } from "react";
2
import { createRoot } from "react-dom/client";
3
import { expect, it, vi } from "vite-plus/test";
4
-import { EnvironmentId, SOURCE_CONTROL_MEDIA_ASSET } from "@t3tools/contracts";
4
+import {
5
+ AssetWorkspaceAssetNotFoundError,
6
+ EnvironmentId,
7
+ SOURCE_CONTROL_MEDIA_ASSET,
8
+ ThreadId,
9
+} from "@t3tools/contracts";
10
11
const harness = vi.hoisted(() => ({
7
- refreshAssetUrl: vi.fn<(environmentId: string, resource: { url: string }) => Promise<string>>(),
12
+ refreshAssetUrl:
13
+ vi.fn<(environmentId: string, resource: { url: string }) => Promise<string | null>>(),
14
alert: vi.fn(),
15
previews: [] as unknown[],
16
mounts: 0,
@@ -144,3 +150,24 @@ it("closes the preview when the selected image cannot be resolved", async () =>
150
expect(preview.onRequestClose).toHaveBeenCalledOnce();
151
expect(harness.alert).toHaveBeenCalledOnce();
152
});
153
+
154
+it("names the checked path when the server cannot find the file", async () => {
155
+ const resource = {
156
+ _tag: "media-file" as const,
157
+ threadId: ThreadId.make("thread"),
158
+ path: "v2/extended/duo-color-3-extended-FINAL.png",
159
+ };
160
+ const checkedPath = "/repo/v2/extended/duo-color-3-extended-FINAL.png";
161
+ harness.refreshAssetUrl.mockRejectedValue(
162
+ new AssetWorkspaceAssetNotFoundError({ resource, checkedPath }),
163
+ );
164
+ const selected: FilePreviewItem = { kind: "image", environmentId, resource };
165
+ await using preview = await openGallery(selected, [selected], false);
166
+
167
+ expect(preview.onRequestClose).toHaveBeenCalledOnce();
168
+ expect(harness.alert).toHaveBeenCalledWith(
169
+ "Could not open preview",
170
+ expect.stringContaining(checkedPath),
171
+ );
172
+ expect(harness.alert.mock.calls[0]?.[1]).not.toMatch(/reconnect/i);
173
+});
apps/mobile/src/components/ui/FilePreviewSession.tsx
+11
-2
@@ -1,3 +1,4 @@
1
+import { AssetWorkspaceAssetNotFoundError } from "@t3tools/contracts";
2
import * as Schema from "effect/Schema";
3
import * as Dialog from "./Dialog";
4
import { useContext, useEffect, useEffectEvent, useState, type ComponentType } from "react";
@@ -36,6 +37,15 @@ class PreviewResolutionError extends Schema.TaggedError<PreviewResolutionError>(
37
}
38
39
const isPreviewResolutionError = Schema.is(PreviewResolutionError);
40
+const isAssetNotFoundError = Schema.is(AssetWorkspaceAssetNotFoundError);
41
+
42
+function remotePreviewFailureMessage(error: unknown): string {
43
+ if (!isAssetNotFoundError(error)) {
44
+ return "Reconnect to this environment and try again. The file may have been moved or deleted.";
45
+ }
46
+ const path = error.checkedPath ?? ("path" in error.resource ? error.resource.path : undefined);
47
+ return path ? `The file was not found at ${path}.` : error.message;
48
+}
49
50
interface ResolvedPreviewUri {
51
readonly uri: string;
@@ -64,8 +74,7 @@ async function resolvePreviewUri(
74
.catch((error: unknown) => {
75
throw new PreviewResolutionError({
76
cause: error,
67
- fallbackMessage:
68
- "Reconnect to this environment and try again. The file may have been moved or deleted.",
77
+ fallbackMessage: remotePreviewFailureMessage(error),
78
});
79
});
80
return { uri: url + (item.srcFragment ?? "") };
apps/mobile/src/components/ui/VideoPreviewModal.tsx
+2
-2
@@ -50,7 +50,7 @@ function NativeVideoPreview(props: {
50
const resolvePlaybackUrl = useEffectEvent(async (): Promise<string> => {
51
if (source.type !== "media") throw new Error("Could not load this video.");
52
if (!("resource" in source)) return source.uri;
53
- const url = await refreshAssetUrl(source.environmentId, source.resource);
53
+ const url = await refreshAssetUrl(source.environmentId, source.resource).catch(() => null);
54
const playbackUrl = mediaVideoPreviewUri(source, url);
55
if (playbackUrl !== null) return playbackUrl;
56
throw new Error(
@@ -61,7 +61,7 @@ function NativeVideoPreview(props: {
61
});
62
const reauthorize = useEffectEvent(() => {
63
if (source.type === "media" && "resource" in source) {
64
- void refreshAssetUrl(source.environmentId, source.resource);
64
+ void refreshAssetUrl(source.environmentId, source.resource).catch(() => {});
65
}
66
});
67
apps/mobile/src/lib/attachmentDocument.ts
+1
-1
@@ -44,7 +44,7 @@ async function readAttachmentText(key: AttachmentTextKey, signal: AbortSignal) {
44
const refreshed =
45
key.environmentId === null
46
? null
47
- : await refreshAssetUrl(key.environmentId, key.resource, signal);
47
+ : await refreshAssetUrl(key.environmentId, key.resource, signal).catch(() => null);
48
if (!refreshed) throw new Error("Reconnect to this environment and try again.");
49
target = refreshed;
50
}
apps/mobile/src/state/assets.test.ts
+29
-3
@@ -1,4 +1,5 @@
1
import {
2
+ AssetWorkspaceAssetNotFoundError,
3
AuthFilesystemReadScope,
4
EnvironmentAuthorizationError,
5
EnvironmentId,
@@ -6,7 +7,7 @@ import {
7
type AuthSessionState,
8
} from "@t3tools/contracts";
9
import * as Cause from "effect/Cause";
9
-import { AsyncResult } from "effect/reactivity";
10
+import { Atom, AsyncResult } from "effect/reactivity";
11
import { beforeEach, expect, it, vi } from "vite-plus/test";
12
13
const state = vi.hoisted(() => ({
@@ -15,6 +16,8 @@ const state = vi.hoisted(() => ({
16
assetAtom: {},
17
mint: vi.fn(),
18
assetQuery: vi.fn(),
19
+ executeQuery: vi.fn(),
20
+ preparedConnectionAtom: null as unknown,
21
}));
22
23
vi.mock("react", () => ({ useCallback: <A>(callback: A) => callback }));
@@ -27,7 +30,10 @@ vi.mock("@effect/atom-react", () => ({
30
: AsyncResult.initial(false),
31
}));
32
vi.mock("./session", () => ({
30
- environmentSession: { sessionStateAtom: () => ({}) },
33
+ environmentSession: {
34
+ sessionStateAtom: () => ({}),
35
+ preparedConnectionValueAtom: () => state.preparedConnectionAtom,
36
+ },
37
usePreparedConnection: () => ({ _tag: "Some", value: { httpBaseUrl: "https://host.test" } }),
38
}));
39
vi.mock("./presentation", () => ({
@@ -48,9 +54,13 @@ vi.mock("@t3tools/client-runtime/state/assets", async (importOriginal) => ({
54
...(await importOriginal<typeof import("@t3tools/client-runtime/state/assets")>()),
55
createAssetEnvironmentAtoms: () => ({ createUrl: state.assetQuery }),
56
}));
57
+vi.mock("@t3tools/client-runtime/state/runtime", async (importOriginal) => ({
58
+ ...(await importOriginal<typeof import("@t3tools/client-runtime/state/runtime")>()),
59
+ executeAtomQuery: state.executeQuery,
60
+}));
61
vi.mock("./use-atom-query-runner", () => ({ useAtomQueryRunner: () => state.mint }));
62
53
-import { useRefreshAssetUrl, useAssetUrlState } from "./assets";
63
+import { refreshAssetUrl, useRefreshAssetUrl, useAssetUrlState } from "./assets";
64
65
const environmentId = EnvironmentId.make("asset-environment");
66
const threadId = ThreadId.make("asset-thread");
@@ -107,3 +117,19 @@ it("lets the server authorize an explicit refresh before the client grant loads"
117
state.mint.mockResolvedValue(AsyncResult.failure(Cause.fail(denied)));
118
await expect(useRefreshAssetUrl(environmentId, resource)()).resolves.toBeNull();
119
});
120
+
121
+it("rejects with the server's error and resolves null only without a connection", async () => {
122
+ const missing = new AssetWorkspaceAssetNotFoundError({
123
+ resource,
124
+ checkedPath: "/repo/missing.png",
125
+ });
126
+ state.executeQuery.mockResolvedValue(AsyncResult.failure(Cause.fail(missing)));
127
+ state.preparedConnectionAtom = Atom.make({
128
+ _tag: "Some",
129
+ value: { httpBaseUrl: "https://host.test" },
130
+ });
131
+ await expect(refreshAssetUrl(environmentId, resource)).rejects.toBe(missing);
132
+
133
+ state.preparedConnectionAtom = Atom.make({ _tag: "None" });
134
+ await expect(refreshAssetUrl(environmentId, resource)).resolves.toBeNull();
135
+});
apps/mobile/src/state/assets.ts
+7
-3
@@ -8,7 +8,7 @@ import {
8
EMPTY_ASSET_URL_ATOM,
9
makeRevisionedAssetUrlFamily,
10
} from "@t3tools/client-runtime/state/assets";
11
-import { executeAtomQuery } from "@t3tools/client-runtime/state/runtime";
11
+import { executeAtomQuery, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
12
import type { AssetResource, EnvironmentId } from "@t3tools/contracts";
13
import * as Clock from "effect/Clock";
14
import * as Effect from "effect/Effect";
@@ -109,7 +109,10 @@ export function useRefreshAssetUrl(
109
};
110
}
111
112
-/** {@link useRefreshAssetUrl} for async tasks that resolve several resources at once. */
112
+/**
113
+ * {@link useRefreshAssetUrl} for async tasks that resolve several resources at once. Resolves
114
+ * null without a connection and rejects with the server's error when it refuses the URL.
115
+ */
116
export async function refreshAssetUrl(
117
environmentId: EnvironmentId,
118
resource: AssetResource,
@@ -124,6 +127,7 @@ export async function refreshAssetUrl(
127
reportFailure: false,
128
...(signal ? { signal } : {}),
129
});
130
+ if (result._tag === "Failure") throw squashAtomCommandFailure(result);
131
// A route can change while the query runs; resolve against the connection now current.
132
const connection = appAtomRegistry.get(connectionAtom);
133
if (connection._tag === "None") return null;
@@ -160,7 +164,7 @@ const freshAssetUrlFamily = Atom.family((key: FreshAssetUrlKey) =>
164
try: async (signal) =>
165
key.environmentId === null
166
? null
163
- : await refreshAssetUrl(key.environmentId, key.resource, signal),
167
+ : await refreshAssetUrl(key.environmentId, key.resource, signal).catch(() => null),
168
catch: (cause) =>
169
new AssetUrlUnavailableError({
170
message: cause instanceof Error ? cause.message : "The attachment is unavailable.",