Skip to content

Commit 4bfe030

Browse files
committed
fix(server): session import skips T3 Code's own folders behind a symlinked home
1 parent 60b35a1 commit 4bfe030

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

‎apps/server/src/project/AgentSessionScanner.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,36 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
895895
}),
896896
);
897897

898+
it.effect.skipIf(!symlinksSupported)(
899+
"excludes T3 Code's own folders when its home is reached through a symlink",
900+
() =>
901+
Effect.gen(function* () {
902+
const path = yield* Path.Path;
903+
const fileSystem = yield* FileSystem.FileSystem;
904+
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
905+
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
906+
const realBaseDir = yield* fileSystem.realPath(
907+
yield* makeTempDir("t3code-scanner-base-"),
908+
);
909+
const linkParent = yield* makeTempDir("t3code-scanner-links-");
910+
const configBaseDir = path.join(linkParent, "t3-home");
911+
yield* fileSystem.symlink(realBaseDir, configBaseDir);
912+
913+
// Providers record the resolved cwd, so a projectless chat shows up under the real home.
914+
const scratchCwd = path.join(realBaseDir, "scratch", "2026-01-01-quiet-fox");
915+
yield* fileSystem.makeDirectory(scratchCwd, { recursive: true });
916+
yield* writeTranscript({
917+
filePath: path.join(claudeHomePath, "projects", "-slug", "a.jsonl"),
918+
contents: claudeSessionLine(scratchCwd),
919+
mtimeMs: Date.parse("2026-01-01T00:00:00.000Z"),
920+
});
921+
922+
const result = yield* runScan({ claudeHomePath, codexHomePath, configBaseDir });
923+
924+
expect(result.candidates).toEqual([]);
925+
}),
926+
);
927+
898928
it.effect("finds the cwd on a later line when the first records carry none", () =>
899929
Effect.gen(function* () {
900930
const path = yield* Path.Path;

‎apps/server/src/project/AgentSessionScanner.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,14 @@ export const make = Effect.gen(function* () {
639639
const serverConfig = yield* ServerConfig.ServerConfig;
640640
const serverSettings = yield* ServerSettings.ServerSettingsService;
641641
const projectStore = yield* ProjectStore.ProjectStoreV2;
642-
const baseDir = path.resolve(serverConfig.baseDir);
643-
const worktreesDir = path.resolve(serverConfig.worktreesDir);
642+
const withResolvedLinks = (directory: string) =>
643+
fileSystem.realPath(directory).pipe(
644+
Effect.map((realPath) => [directory, realPath]),
645+
Effect.orElseSucceed(() => [directory]),
646+
);
647+
// Candidates are also checked with links resolved, so T3's own folders need both spellings.
648+
const baseDirs = yield* withResolvedLinks(path.resolve(serverConfig.baseDir));
649+
const worktreesDirs = yield* withResolvedLinks(path.resolve(serverConfig.worktreesDir));
644650
const foldWorktreeCase = (yield* HostProcess.Platform) === "win32";
645651
const hostEnvironment = yield* HostProcess.Environment;
646652
const homeDir = yield* HostProcess.HomeDirectory;
@@ -662,10 +668,14 @@ export const make = Effect.gen(function* () {
662668
normalizeForWorktreeMatch(ancestor, foldWorktreeCase),
663669
),
664670
) ||
665-
normalizeForWorktreeMatch(candidatePath, foldWorktreeCase).startsWith(
666-
normalizeForWorktreeMatch(baseDir, foldWorktreeCase),
671+
baseDirs.some((baseDir) =>
672+
normalizeForWorktreeMatch(candidatePath, foldWorktreeCase).startsWith(
673+
normalizeForWorktreeMatch(baseDir, foldWorktreeCase),
674+
),
667675
) ||
668-
isT3ManagedWorktree(candidatePath, worktreesDir, foldWorktreeCase);
676+
worktreesDirs.some((worktreesDir) =>
677+
isT3ManagedWorktree(candidatePath, worktreesDir, foldWorktreeCase),
678+
);
669679

670680
const listDirectory = (directory: string) =>
671681
fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));

0 commit comments

Comments
 (0)