The best way to control Claude Code, Codex and more from any computer or phone
fix(shared): allow atomic saves through 40 symlinks (#25604)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Simone committed
Nov 1, 2026 at 03:06 UTC
d7a78f08a2d7940f46348157492576cb449a51d9
2 files changed
+32
-1
packages/shared/src/atomicWrite.test.ts
+30
@@ -14,6 +14,36 @@ import { writeFileStringAtomically } from "./atomicWrite.ts";
14
import * as HostProcess from "./HostProcess.ts";
15
16
it.layer(NodeServices.layer)("writeFileStringAtomically", (it) => {
17
+ it.effect.each(HostProcess.Platform.defaultValue() === "linux" ? [39, 40, 41] : [])(
18
+ "matches native file access for a chain of %i symlinks",
19
+ (hops) =>
20
+ Effect.gen(function* () {
21
+ const fs = yield* FileSystem.FileSystem;
22
+ const path = yield* Path.Path;
23
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-atomic-write-" });
24
+ const destination = path.join(root, "settings.json");
25
+ const first = path.join(root, "link-0");
26
+ yield* fs.writeFileString(destination, "before");
27
+ for (let index = hops - 1; index >= 0; index--) {
28
+ const target = index === hops - 1 ? "settings.json" : `link-${index + 1}`;
29
+ yield* fs.symlink(target, path.join(root, `link-${index}`));
30
+ }
31
+
32
+ const read = yield* Effect.exit(fs.readFileString(first));
33
+ const write = yield* Effect.exit(
34
+ writeFileStringAtomically({ filePath: first, contents: "after" }),
35
+ );
36
+
37
+ assert.strictEqual(Exit.isSuccess(read), hops <= 40);
38
+ assert.strictEqual(Exit.isSuccess(write), Exit.isSuccess(read));
39
+ assert.strictEqual(
40
+ yield* fs.readFileString(destination),
41
+ Exit.isSuccess(read) ? "after" : "before",
42
+ );
43
+ assert.strictEqual(yield* fs.readLink(first), "link-1");
44
+ }),
45
+ );
46
+
47
it.effect("keeps a symlinked file linked and rewrites its destination", () =>
48
Effect.gen(function* () {
49
const fs = yield* FileSystem.FileSystem;
packages/shared/src/symlink.ts
+2
-1
@@ -23,7 +23,8 @@ export const resolveSymlinkTarget = Effect.fn("symlink.resolveSymlinkTarget")(fu
23
const fs = yield* FileSystem.FileSystem;
24
const path = yield* Path.Path;
25
let current = path.resolve(filePath);
26
- for (let hop = 0; hop < MAX_SYMLINK_HOPS; hop++) {
26
+ // The terminal file needs a probe after the last permitted link is followed.
27
+ for (let hop = 0; hop <= MAX_SYMLINK_HOPS; hop++) {
28
const link = yield* fs.readLink(current).pipe(
29
Effect.asSome,
30
Effect.catchIf(isNotASymlink, () => Effect.succeedNone),