The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 23:15 UTC
fix(server): a missing t3.json is no longer a failed read (#19949)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wish committed
Oct 20, 2026 at 10:10 UTC
b430de5c9bdd318b89defeae9340f47df2aacca1
9 files changed
+223
-45
apps/mobile/src/features/threads/new-task-flow-provider.tsx
+6
-2
@@ -453,13 +453,17 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
453
canReadFiles && selectedProject !== null && selectedProject.workspaceRoot !== ""
454
? projectEnvironment.readFile({
455
environmentId: selectedProject.environmentId,
456
- input: { cwd: selectedProject.workspaceRoot, relativePath: T3_PROJECT_FILE_NAME },
456
+ input: {
457
+ cwd: selectedProject.workspaceRoot,
458
+ relativePath: T3_PROJECT_FILE_NAME,
459
+ allowMissing: true,
460
+ },
461
})
462
: null,
463
);
464
const t3ProjectFileData = t3ProjectFileQuery.data as ProjectReadFileResult | null;
465
const t3ProjectFile =
462
- t3ProjectFileData === null || t3ProjectFileData.truncated
466
+ t3ProjectFileData === null || t3ProjectFileData.exists === false || t3ProjectFileData.truncated
467
? null
468
: parseT3ProjectFile(t3ProjectFileData.contents);
469
const projectSettings = resolveProjectSettings(
apps/server/src/workspace/WorkspaceFileSystem.test.ts
+65
-10
@@ -4,9 +4,11 @@ import * as NodeChildProcess from "node:child_process";
4
import * as NodeServices from "@effect/platform-node/NodeServices";
5
import { it, describe, expect } from "@effect/vitest";
6
import * as Effect from "effect/Effect";
7
+import * as Exit from "effect/Exit";
8
import * as FileSystem from "effect/FileSystem";
9
import * as Layer from "effect/Layer";
10
import * as Path from "effect/Path";
11
+import * as Tracer from "effect/Tracer";
12
13
import * as ServerConfig from "../config.ts";
14
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
@@ -274,6 +276,19 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
276
resolvedPath,
277
});
278
expect("cause" in error).toBe(false);
279
+
280
+ yield* fileSystem.symlink(outsideDir, path.join(cwd, "linked-dir"));
281
+ const missingChildError = yield* workspaceFileSystem
282
+ .readFile(
283
+ Object.assign(
284
+ { cwd, relativePath: "linked-dir/missing/t3.json" },
285
+ { allowMissing: true },
286
+ ),
287
+ )
288
+ .pipe(Effect.flip);
289
+ expect(missingChildError).toBeInstanceOf(
290
+ WorkspaceFileSystem.WorkspaceFilePathEscapeError,
291
+ );
292
}),
293
);
294
@@ -285,18 +300,20 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
300
const cwd = yield* makeTempDir;
301
yield* fileSystem.makeDirectory(path.join(cwd, "src"));
302
288
- const error = yield* workspaceFileSystem
289
- .readFile({ cwd, relativePath: "src" })
290
- .pipe(Effect.flip);
303
const resolvedPath = yield* fileSystem.realPath(path.join(cwd, "src"));
304
+ for (const options of [{}, { allowMissing: true }]) {
305
+ const error = yield* workspaceFileSystem
306
+ .readFile(Object.assign({ cwd, relativePath: "src" }, options))
307
+ .pipe(Effect.flip);
308
293
- expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspacePathNotFileError);
294
- expect(error).toMatchObject({
295
- workspaceRoot: cwd,
296
- relativePath: "src",
297
- resolvedPath,
298
- });
299
- expect("cause" in error).toBe(false);
309
+ expect(error).toBeInstanceOf(WorkspaceFileSystem.WorkspacePathNotFileError);
310
+ expect(error).toMatchObject({
311
+ workspaceRoot: cwd,
312
+ relativePath: "src",
313
+ resolvedPath,
314
+ });
315
+ expect("cause" in error).toBe(false);
316
+ }
317
}),
318
);
319
@@ -348,6 +365,44 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
365
expect((error.cause as NodeJS.ErrnoException).code).toBe("ENOENT");
366
}),
367
);
368
+
369
+ it.effect("returns an absent optional file without any failed spans", () =>
370
+ Effect.gen(function* () {
371
+ const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
372
+ const cwd = yield* makeTempDir;
373
+ const spans: Array<Tracer.NativeSpan> = [];
374
+ const tracer = Tracer.make({
375
+ span: (options) => {
376
+ const span = new Tracer.NativeSpan(options);
377
+ spans.push(span);
378
+ return span;
379
+ },
380
+ });
381
+
382
+ const result = yield* workspaceFileSystem
383
+ .readFile(Object.assign({ cwd, relativePath: "t3.json" }, { allowMissing: true }))
384
+ .pipe(Effect.withTracer(tracer), Effect.exit);
385
+
386
+ expect(spans.length).toBeGreaterThan(0);
387
+ // Diagnostics counts nested failures even when the outer read recovers.
388
+ expect
389
+ .soft(
390
+ spans
391
+ .filter((span) => span.status._tag === "Ended" && Exit.isFailure(span.status.exit))
392
+ .map((span) => span.name),
393
+ )
394
+ .toEqual([]);
395
+ expect(result).toEqual(
396
+ Exit.succeed({
397
+ relativePath: "t3.json",
398
+ contents: "",
399
+ byteLength: 0,
400
+ truncated: false,
401
+ exists: false,
402
+ }),
403
+ );
404
+ }),
405
+ );
406
});
407
408
describe("writeFile", () => {
apps/server/src/workspace/WorkspaceFileSystem.ts
+72
-18
@@ -240,7 +240,13 @@ export const make = Effect.gen(function* () {
240
operation: "realpath-target",
241
cause,
242
}),
243
- });
243
+ }).pipe(
244
+ Effect.catchIf(
245
+ (error) =>
246
+ input.allowMissing === true && (error.cause as NodeJS.ErrnoException).code === "ENOENT",
247
+ () => Effect.succeed(null),
248
+ ),
249
+ );
250
return { relativePath: requestedPath, realTargetPath };
251
}
252
@@ -261,8 +267,36 @@ export const make = Effect.gen(function* () {
267
cause,
268
}),
269
});
264
- const realTargetPath = yield* Effect.tryPromise({
265
- try: () => NodeFSP.realpath(target.absolutePath),
270
+ const resolved = yield* Effect.tryPromise({
271
+ try: async () => {
272
+ let candidate = target.absolutePath;
273
+ for (;;) {
274
+ try {
275
+ return {
276
+ realTargetPath: path.join(
277
+ await NodeFSP.realpath(candidate),
278
+ path.relative(candidate, target.absolutePath),
279
+ ),
280
+ exists: candidate === target.absolutePath,
281
+ };
282
+ } catch (error) {
283
+ if (!input.allowMissing || (error as NodeJS.ErrnoException).code !== "ENOENT") {
284
+ throw error;
285
+ }
286
+ // Like writes, missing reads must check the nearest existing ancestor.
287
+ // An existing entry that cannot resolve is a dangling link, not absence.
288
+ const exists = await NodeFSP.lstat(candidate).then(
289
+ () => true,
290
+ (cause: NodeJS.ErrnoException) => {
291
+ if (cause.code !== "ENOENT") throw cause;
292
+ return false;
293
+ },
294
+ );
295
+ if (exists || path.dirname(candidate) === candidate) throw error;
296
+ candidate = path.dirname(candidate);
297
+ }
298
+ }
299
+ },
300
catch: (cause) =>
301
new WorkspaceFileSystemOperationError({
302
workspaceRoot: input.cwd,
@@ -273,22 +307,33 @@ export const make = Effect.gen(function* () {
307
cause,
308
}),
309
});
276
- if (!isInsideRealRoot(realWorkspaceRoot, realTargetPath)) {
310
+ if (!isInsideRealRoot(realWorkspaceRoot, resolved.realTargetPath)) {
311
return yield* new WorkspaceFilePathEscapeError({
312
workspaceRoot: input.cwd,
313
relativePath: input.relativePath,
314
resolvedWorkspaceRoot: realWorkspaceRoot,
281
- resolvedPath: realTargetPath,
315
+ resolvedPath: resolved.realTargetPath,
316
});
317
}
284
- return { relativePath: target.relativePath, realTargetPath };
318
+ return {
319
+ relativePath: target.relativePath,
320
+ realTargetPath: resolved.exists ? resolved.realTargetPath : null,
321
+ };
322
});
323
324
const readFile: WorkspaceFileSystem["Service"]["readFile"] = Effect.fn(
325
"WorkspaceFileSystem.readFile",
326
)(function* (input) {
327
const target = yield* resolveReadTarget(input);
328
+ const absentResult = {
329
+ relativePath: target.relativePath,
330
+ contents: "",
331
+ byteLength: 0,
332
+ truncated: false,
333
+ exists: false,
334
+ };
335
const realTargetPath = target.realTargetPath;
336
+ if (realTargetPath === null) return absentResult;
337
338
return yield* Effect.acquireUseRelease(
339
Effect.tryPromise({
@@ -308,9 +353,16 @@ export const make = Effect.gen(function* () {
353
operation: "open",
354
cause,
355
}),
311
- }),
356
+ }).pipe(
357
+ Effect.catchIf(
358
+ (error) =>
359
+ input.allowMissing === true && (error.cause as NodeJS.ErrnoException).code === "ENOENT",
360
+ () => Effect.succeed(null),
361
+ ),
362
+ ),
363
(handle) =>
364
Effect.gen(function* () {
365
+ if (handle === null) return absentResult;
366
const stat = yield* Effect.tryPromise({
367
try: () => handle.stat(),
368
catch: (cause) =>
@@ -362,18 +414,20 @@ export const make = Effect.gen(function* () {
414
};
415
}),
416
(handle) =>
365
- Effect.tryPromise({
366
- try: () => handle.close(),
367
- catch: (cause) =>
368
- new WorkspaceFileSystemOperationError({
369
- workspaceRoot: input.cwd,
370
- relativePath: input.relativePath,
371
- resolvedPath: realTargetPath,
372
- operationPath: realTargetPath,
373
- operation: "close",
374
- cause,
417
+ handle === null
418
+ ? Effect.void
419
+ : Effect.tryPromise({
420
+ try: () => handle.close(),
421
+ catch: (cause) =>
422
+ new WorkspaceFileSystemOperationError({
423
+ workspaceRoot: input.cwd,
424
+ relativePath: input.relativePath,
425
+ resolvedPath: realTargetPath,
426
+ operationPath: realTargetPath,
427
+ operation: "close",
428
+ cause,
429
+ }),
430
}),
376
- }),
431
);
432
});
433
apps/web/src/components/files/projectFilesQueryState.ts
+14
-6
@@ -4,6 +4,7 @@ import {
4
type ProjectListEntriesResult,
5
ProjectReadFileError,
6
type ProjectReadFileResult,
7
+ T3_PROJECT_FILE_NAME,
8
} from "@t3tools/contracts";
9
import * as Cause from "effect/Cause";
10
import * as Option from "effect/Option";
@@ -71,7 +72,11 @@ export function getProjectFileQueryAtom(
72
) {
73
return projectEnvironment.readFile({
74
environmentId,
74
- input: { cwd, relativePath: relativePath ?? EMPTY_PROJECT_FILE_PATH },
75
+ input: {
76
+ cwd,
77
+ relativePath: relativePath ?? EMPTY_PROJECT_FILE_PATH,
78
+ ...(relativePath === T3_PROJECT_FILE_NAME ? { allowMissing: true } : {}),
79
+ },
80
});
81
}
82
@@ -112,7 +117,8 @@ export function getProjectFileContents(
117
const optimistic = getOptimisticProjectFileQueryData(environmentId, cwd, relativePath);
118
if (optimistic) return optimistic.contents;
119
const result = appAtomRegistry.get(getProjectFileQueryAtom(environmentId, cwd, relativePath));
115
- return Option.getOrUndefined(AsyncResult.value(result))?.contents;
120
+ const data = Option.getOrUndefined(AsyncResult.value(result));
121
+ return data?.exists === false ? undefined : data?.contents;
122
}
123
124
export function getUnsavedProjectFileQueryData(
@@ -259,15 +265,15 @@ export function useProjectFileQuery(
265
const result = useAtomValue(atom);
266
const refreshAtom = useAtomRefresh(atom);
267
const refresh = () => refreshAtom();
268
+ const readData = Option.getOrNull(AsyncResult.value(result));
269
+ const isMissing = readData?.exists === false;
270
const optimisticResult = useAtomValue(
271
optimisticFileAtom(environmentId, cwd, relativePath ?? EMPTY_PROJECT_FILE_PATH),
272
);
273
const optimisticFile = relativePath === null ? null : optimisticResult;
274
const cause = failureCause(result);
275
const readError = isProjectReadFileError(cause) ? cause : null;
268
- const data = canReadFiles
269
- ? (optimisticFile?.data ?? Option.getOrNull(AsyncResult.value(result)))
270
- : null;
276
+ const data = canReadFiles ? (optimisticFile?.data ?? (isMissing ? null : readData)) : null;
277
const isNotFile = readError?.failure === "path_not_file";
278
279
return {
@@ -276,7 +282,9 @@ export function useProjectFileQuery(
282
!isQueryEnabled || fileAccess.isPending
283
? null
284
: canReadFiles
279
- ? errorMessage(cause)
285
+ ? isMissing && !optimisticFile
286
+ ? `'${relativePath}' does not exist.`
287
+ : errorMessage(cause)
288
: (fileAccess.error ?? "This connection cannot read host files."),
289
isPending: isQueryEnabled && (fileAccess.isPending || result.waiting),
290
readError,
apps/web/src/components/settings/SettingsScopeContext.tsx
+3
-1
@@ -33,7 +33,9 @@ const memberProjectFilesAtom = Atom.family((membersKey: string) => {
33
Option.getOrNull(AsyncResult.value(result));
34
files.set(
35
physicalProjectKey,
36
- data === null || data.truncated ? null : parseT3ProjectFile(data.contents),
36
+ data === null || data.exists === false || data.truncated
37
+ ? null
38
+ : parseT3ProjectFile(data.contents),
39
);
40
}
41
return files;
apps/web/src/lib/t3ProjectFileDefaults.ts
+1
-1
@@ -23,6 +23,6 @@ export async function readT3ProjectFile(
23
T3_PROJECT_FILE_NAME,
24
result._tag === "Success" ? result.value : null,
25
);
26
- if (data === null || data.truncated) return null;
26
+ if (data === null || data.exists === false || data.truncated) return null;
27
return parseT3ProjectFile(data.contents);
28
}
packages/client-runtime/src/state/projectCommands.test.ts
+54
-6
@@ -3,6 +3,8 @@ import {
3
AuthFilesystemWriteScope,
4
EnvironmentId,
5
ProjectId,
6
+ ProjectReadFileInput,
7
+ ProjectReadFileResult,
8
ThreadId,
9
type AuthSessionState,
10
type ScopedProjectRef,
@@ -15,6 +17,7 @@ import * as Deferred from "effect/Deferred";
17
import * as Fiber from "effect/Fiber";
18
import * as Layer from "effect/Layer";
19
import * as Option from "effect/Option";
20
+import * as Schema from "effect/Schema";
21
import * as SubscriptionRef from "effect/SubscriptionRef";
22
import * as Stream from "effect/Stream";
23
import { Atom, AtomRegistry, AsyncResult } from "effect/reactivity";
@@ -26,6 +29,8 @@ import type { RpcSession } from "../rpc/session.ts";
29
import type { EnvironmentProject } from "./models.ts";
30
import { createProjectEnvironmentAtoms } from "./projectCommands.ts";
31
32
+const decodeReadFileInput = Schema.decodeUnknownSync(ProjectReadFileInput);
33
+const decodeReadFileResult = Schema.decodeUnknownSync(ProjectReadFileResult);
34
const ENVIRONMENT_ID = EnvironmentId.make("environment-1");
35
vi.mock("./session.ts", () => ({
36
createEnvironmentSessionAtoms: () => ({ sessionStateAtom: sessions }),
@@ -43,7 +48,10 @@ const PROJECT = {
48
const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () {
49
const metadataRequests: string[][] = [];
50
const file = { byteLength: 5 };
46
- const readResponse = { wait: Effect.void as Effect.Effect<void> };
51
+ const readResponse = {
52
+ wait: Effect.void as Effect.Effect<void>,
53
+ missing: false,
54
+ };
55
const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
56
target: { environmentId: ENVIRONMENT_ID },
57
session: yield* SubscriptionRef.make(
@@ -54,7 +62,17 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () {
62
Effect.gen(function* () {
63
const byteLength = file.byteLength;
64
yield* readResponse.wait;
57
- return { relativePath: "foo", byteLength, contents: "old", truncated: false };
65
+ return decodeReadFileResult(
66
+ readResponse.missing
67
+ ? {
68
+ relativePath: "foo",
69
+ byteLength: 0,
70
+ contents: "",
71
+ truncated: false,
72
+ exists: false,
73
+ }
74
+ : { relativePath: "foo", byteLength, contents: "old", truncated: false },
75
+ );
76
}),
77
[WS_METHODS.projectsWriteFile]: () =>
78
Effect.sync(() => {
@@ -65,10 +83,11 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () {
83
Effect.sync(() => {
84
metadataRequests.push(input.paths);
85
return {
68
- entries: input.paths.map(() => ({
69
- kind: "file" as const,
70
- byteLength: file.byteLength,
71
- })),
86
+ entries: input.paths.map(() =>
87
+ readResponse.missing
88
+ ? null
89
+ : { kind: "file" as const, byteLength: file.byteLength },
90
+ ),
91
};
92
}),
93
},
@@ -126,6 +145,35 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () {
145
});
146
147
describe("writeFile metadata", () => {
148
+ it.effect("preserves optional read results without seeding metadata for an absent file", () =>
149
+ Effect.gen(function* () {
150
+ const h = yield* makeHarness();
151
+ h.readResponse.missing = true;
152
+ const input = { cwd: "/repo", relativePath: "foo", allowMissing: true };
153
+ expect.soft(decodeReadFileInput(input)).toEqual(input);
154
+ const result = yield* AtomRegistry.getResult(
155
+ h.registry,
156
+ h.commands.readFile({ environmentId: ENVIRONMENT_ID, input }),
157
+ { suspendOnWaiting: true },
158
+ );
159
+ expect.soft(result).toEqual({
160
+ relativePath: "foo",
161
+ byteLength: 0,
162
+ contents: "",
163
+ truncated: false,
164
+ exists: false,
165
+ });
166
+ const metadata = h.commands.fileMetadata({
167
+ environmentId: ENVIRONMENT_ID,
168
+ input: { path: "/repo/foo" },
169
+ });
170
+ expect(
171
+ yield* AtomRegistry.getResult(h.registry, metadata, { suspendOnWaiting: true }),
172
+ ).toBeNull();
173
+ expect(h.metadataRequests).toEqual([["/repo/foo"]]);
174
+ }).pipe(Effect.scoped),
175
+ );
176
+
177
it.effect("reuses a current file read without another metadata request", () =>
178
Effect.gen(function* () {
179
const h = yield* makeHarness();
packages/client-runtime/src/state/projectCommands.ts
+4
-1
@@ -143,7 +143,10 @@ export function createProjectEnvironmentAtoms<R, E>(
143
execute: (input) =>
144
fileMetadata.seedAfterRead(
145
request(WS_METHODS.projectsReadFile, input),
146
- (result, isCurrent) => fileMetadata.rememberFile(input.cwd, result, isCurrent),
146
+ (result, isCurrent) =>
147
+ result.exists === false
148
+ ? Effect.void
149
+ : fileMetadata.rememberFile(input.cwd, result, isCurrent),
150
),
151
}),
152
optimisticFile: (target: OptimisticProjectFileTarget) =>
packages/contracts/src/project.ts
+4
@@ -418,6 +418,8 @@ export const ProjectReadFileInput = Schema.Struct({
418
// Workspace-relative, or an absolute host path for a file outside the
419
// workspace. Only workspace-relative paths can be written back.
420
relativePath: TrimmedNonEmptyString.check(Schema.isMaxLength(PROJECT_READ_FILE_PATH_MAX_LENGTH)),
421
+ // Optional files can be absent without failing the read.
422
+ allowMissing: Schema.optional(Schema.Boolean),
423
});
424
export type ProjectReadFileInput = typeof ProjectReadFileInput.Type;
425
@@ -426,6 +428,8 @@ export const ProjectReadFileResult = Schema.Struct({
428
contents: Schema.String,
429
byteLength: NonNegativeInt,
430
truncated: Schema.Boolean,
431
+ // Omitted by older servers; false only for an absent optional file.
432
+ exists: Schema.optional(Schema.Boolean),
433
});
434
export type ProjectReadFileResult = typeof ProjectReadFileResult.Type;
435