Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(checkpointing): skip checkpoint when cwd is the home directory #1294

Closedmurataslan1(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1294/headopened View on GitHub

Showing 1 changed file with 14 additions and 0 deletions.

x
0 of 1 viewed, 1 left
14 additions and 0 deletionsapps/server/src/checkpointing/Layers/CheckpointStore.tsModified
View file
@@ -10,6 +10,7 @@
* @module CheckpointStoreLive
*/
import { randomUUID } from "node:crypto";
+import { homedir } from "node:os";
​
import { Effect, Layer, FileSystem, Path } from "effect";
​
@@ -91,6 +92,19 @@
Effect.gen(function* () {
const operation = "CheckpointStore.captureCheckpoint";
​
+ // Skip checkpointing for the home directory — git add -A on ~/ scans
+ // thousands of unrelated files and will time out.
+ const resolvedCwd = yield* Effect.try(() => path.resolve(input.cwd));
+ const home = yield* Effect.try(() => homedir());
Thread on lines 97 to 98

path.resolve(input.cwd) and homedir() are synchronous/non-throwing; wrapping them in Effect.try(() => …) unnecessarily introduces an UnknownException failure path (and can widen the effect error type beyond CheckpointStoreError). Prefer computing these values directly (or use Effect.sync / Effect.succeed), and if you want to guard against unexpected exceptions, map them into a CheckpointInvariantError so the service’s typed error channel stays consistent.

Suggested change
97- const resolvedCwd = yield* Effect.try(() => path.resolve(input.cwd));
98- const home = yield* Effect.try(() => homedir());
97+ const resolvedCwd = path.resolve(input.cwd);
98+ const home = homedir();
Thread on line 98

The home-directory check compares resolvedCwd (normalized via path.resolve) against the raw homedir() string. To avoid false negatives due to trailing separators, normalization differences, or platform-specific casing, resolve/normalize the home path via the same Path service before comparing (and consider realpath if symlinks are common).

Suggested change
98- const home = yield* Effect.try(() => homedir());
98+ const home = yield* Effect.try(() => path.resolve(homedir()));
+ if (resolvedCwd === home) {
+ return yield* new CheckpointInvariantError({
+ operation,
+ detail:
+ "Skipping checkpoint: working directory is the home directory. " +
+ "Please open a specific project folder instead.",
+ });
+ }
Thread on lines 95 to 106

This introduces a new behavioral branch (skipping checkpoint capture when cwd is the home directory) but there’s no direct regression test covering it. Consider adding a test that sets cwd to os.homedir() and asserts captureCheckpoint fails with CheckpointInvariantError (and that no git commands are executed), so this guard doesn’t regress.

+​
yield* Effect.acquireUseRelease(
fs.makeTempDirectory({ prefix: "t3-fs-checkpoint-" }),