The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 16:00 UTC
fix(server): prevent legacy terminal history collisions across threads (#24574)
Co-authored-by: Batuhan1999 <Batuhan.Ckr@outlook.de>
Julius Marminge committed
Nov 13, 2026 at 23:45 UTC
96051c630d5e5e6673cbf850517a364fd8885f1d
2 files changed
+31
-4
apps/server/src/terminal/Manager.test.ts
+22
@@ -1676,6 +1676,28 @@ it.layer(
1676
}),
1677
);
1678
1679
+ // Case-insensitive filesystems resolve "Terminal_YQ.log" to thread "a"'s "terminal_YQ.log",
1680
+ // so the mixed-case file stands in for that alias on case-sensitive hosts.
1681
+ it.effect.each(["terminal_", "Terminal_"])(
1682
+ "never resolves a %s legacy history name to another thread's history file",
1683
+ (prefix) =>
1684
+ Effect.gen(function* () {
1685
+ const { manager, logsDir } = yield* createManager();
1686
+ const fs = yield* FileSystem.FileSystem;
1687
+ const path = yield* Path.Path;
1688
+ const threadId = `${prefix}${Base64Url.encode("a")}`;
1689
+ const otherThreadPath = path.join(logsDir, `${threadId}.log`);
1690
+ yield* fs.makeDirectory(logsDir, { recursive: true });
1691
+ yield* fs.writeFileString(otherThreadPath, "thread a\n");
1692
+
1693
+ expect((yield* manager.open(openInput({ threadId }))).history).toBe("");
1694
+ yield* manager.close({ threadId, terminalId: DEFAULT_TERMINAL_ID, deleteHistory: true });
1695
+ yield* manager.close({ threadId, deleteHistory: true });
1696
+
1697
+ expect(yield* fs.readFileString(otherThreadPath)).toBe("thread a\n");
1698
+ }),
1699
+ );
1700
+
1701
it.effect("keeps reading and deleting history at an encoded path that already fit", () =>
1702
Effect.gen(function* () {
1703
const threadId = "x".repeat(48);
apps/server/src/terminal/Manager.ts
+9
-4
@@ -1861,14 +1861,19 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
1861
);
1862
};
1863
1864
- const legacyHistoryPath = (threadId: string) =>
1865
- path.join(logsDir, `${legacySafeThreadId(threadId)}.log`);
1864
+ const legacyHistoryName = (threadId: string) => `${legacySafeThreadId(threadId)}.log`;
1865
+ // Legacy names in the current "terminal_" namespace would alias another thread's history,
1866
+ // case-insensitively on some filesystems.
1867
+ const hasLegacyHistoryName = (threadId: string) =>
1868
+ !legacySafeThreadId(threadId).toLowerCase().startsWith("terminal_");
1869
1870
const historyPaths = (threadId: string, terminalId: string) => [
1871
...new Set([
1872
historyPath(threadId, terminalId),
1873
encodedHistoryPath(threadId, terminalId),
1871
- ...(terminalId === DEFAULT_TERMINAL_ID ? [legacyHistoryPath(threadId)] : []),
1874
+ ...(terminalId === DEFAULT_TERMINAL_ID && hasLegacyHistoryName(threadId)
1875
+ ? [path.join(logsDir, legacyHistoryName(threadId))]
1876
+ : []),
1877
]),
1878
];
1879
@@ -2340,7 +2345,7 @@ export const makeWithOptions = Effect.fn("TerminalManager.makeWithOptions")(func
2345
yield* Effect.forEach(
2346
entries.filter(
2347
(name) =>
2343
- name === `${legacySafeThreadId(threadId)}.log` ||
2348
+ (hasLegacyHistoryName(threadId) && name === legacyHistoryName(threadId)) ||
2349
threadParts.some((part) => name === `${part}.log` || name.startsWith(`${part}_`)),
2350
),
2351
(name) =>