Skip to content

Commit 1fe0b4f

Browse files
only21milclaude
andauthored
fix(server): clear unreachable preview downloads after a server restart (#25436)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 68a1956 commit 1fe0b4f

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,27 @@ it.live.each(["save failed", "oversized"])(
12651265
).pipe(Effect.provide(layer)),
12661266
);
12671267

1268+
it.live("a restarted server removes the previous run's downloads and keeps its profiles", () =>
1269+
Effect.scoped(
1270+
Effect.gen(function* () {
1271+
const { stateDir } = yield* ServerConfig.ServerConfig;
1272+
const fs = yield* FileSystem.FileSystem;
1273+
const path = yield* Path.Path;
1274+
const previousTab = path.join(stateDir, "server-browser", "downloads", "previous-tab");
1275+
const profile = path.join(stateDir, "server-browser", "profiles", "default");
1276+
yield* fs.makeDirectory(previousTab, { recursive: true });
1277+
yield* fs.makeDirectory(profile, { recursive: true });
1278+
yield* fs.writeFileString(path.join(previousTab, "report.csv"), "a,b");
1279+
yield* fs.writeFileString(path.join(profile, "Preferences"), "{}");
1280+
1281+
yield* Layer.build(ServerBrowser.layer);
1282+
1283+
expect(yield* fs.exists(previousTab)).toBe(false);
1284+
expect(yield* fs.readFileString(path.join(profile, "Preferences"))).toBe("{}");
1285+
}),
1286+
).pipe(Effect.provide(dependencies)),
1287+
);
1288+
12681289
it.live("a page's file picker goes to the controller and takes its uploaded files", () =>
12691290
Effect.scoped(
12701291
Effect.gen(function* () {

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,12 @@ const make = Effect.gen(function* () {
992992
};
993993

994994
const downloadsRoot = NodePath.join(config.stateDir, "server-browser", "downloads");
995+
// Saved downloads are indexed in memory, so an earlier run's files can never be opened again.
996+
yield* Effect.tryPromise(() => NodeFSP.rm(downloadsRoot, { recursive: true, force: true })).pipe(
997+
Effect.catch((cause) =>
998+
Effect.logWarning("server preview could not clear earlier downloads", { cause }),
999+
),
1000+
);
9951001
// Tab ids are opaque server strings; hashing keeps them out of the path.
9961002
const downloadDir = (tab: ServerTab) =>
9971003
NodePath.join(

0 commit comments

Comments
 (0)