Skip to content

Commit a013754

Browse files
t3dotggclaude
andcommitted
fix: a retry clears the shown repair failure at once
Publish the status after clearing the old failure, so Settings shows the restart instead of a stale failure with the button still enabled. The temp directory check now also requires search permission, as SQLite does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 089e593 commit a013754

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎apps/server/src/persistence/DatabaseMaintenance.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,15 @@ const sqliteTempDirectory = Effect.gen(function* () {
299299
if (directory === undefined || directory === "") continue;
300300
const info = yield* fs.stat(directory).pipe(Effect.option);
301301
if (Option.isNone(info) || info.value.type !== "Directory") continue;
302-
// SQLite skips directories it cannot write to.
303-
const writable = yield* fs.access(directory, { writable: true }).pipe(
302+
// SQLite skips directories it cannot write to and search: osAccess(zDir, 03).
303+
const usable = yield* Effect.tryPromise({
304+
try: () => NodeFSP.access(directory, NodeFSP.constants.W_OK | NodeFSP.constants.X_OK),
305+
catch: (cause) => new DiskSpaceCheckError({ path: directory, cause }),
306+
}).pipe(
304307
Effect.as(true),
305308
Effect.orElseSucceed(() => false),
306309
);
307-
if (writable) return directory;
310+
if (usable) return directory;
308311
}
309312
return ".";
310313
});

‎apps/server/src/persistence/DatabaseStorage.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as Effect from "effect/Effect";
55
import * as FileSystem from "effect/FileSystem";
66
import * as Layer from "effect/Layer";
77
import * as Path from "effect/Path";
8+
import * as Option from "effect/Option";
9+
import * as Stream from "effect/Stream";
810
import * as TestClock from "effect/testing/TestClock";
911
import * as SqlClient from "effect/sql/SqlClient";
1012

@@ -160,7 +162,18 @@ it.effect(
160162
assert.isFalse(yield* fs.exists(files.request));
161163

162164
yield* fs.writeFileString(files.failure, "an earlier failure");
163-
yield* request.pipe(Effect.provide(reclaimLayer(restart)));
165+
yield* Effect.gen(function* () {
166+
const storage = yield* DatabaseStorage.DatabaseStorage;
167+
const shownFailure = storage.status.pipe(
168+
Stream.filter((status) => status !== null),
169+
Stream.runHead,
170+
Effect.map((status) => Option.getOrThrow(status)?.reclaimFailure),
171+
);
172+
assert.equal(yield* shownFailure, "an earlier failure");
173+
yield* storage.requestReclaim;
174+
// The retry clears it at once, so Settings shows the restart, not the old failure.
175+
assert.isUndefined(yield* shownFailure);
176+
}).pipe(Effect.provide(reclaimLayer(restart)));
164177
assert.isTrue(yield* fs.exists(files.request));
165178
assert.isFalse(yield* fs.exists(files.failure));
166179
assert.isFalse(yield* Deferred.isDone(restarted), "the reply must go out before the restart");

‎apps/server/src/persistence/DatabaseStorage.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ const make = Effect.gen(function* () {
211211
}
212212
yield* fs.remove(reclaimFiles.failure, { force: true });
213213
reclaimFailure = undefined;
214+
yield* publishStatus;
214215
const requestedAt = yield* Clock.currentTimeMillis;
215216
// One step: a request interrupted between them would repair on some unrelated later exit.
216217
yield* Effect.uninterruptible(

0 commit comments

Comments
 (0)