@devries-cameron20 / t3code-1 / commits / 7c511b3d28
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(shared): preserve files outside log rotation naming (#27503)

Co-authored-by: maria-rcks <maria@kuuro.net>

maco committed Nov 1, 2026 at 22:46 UTC 7c511b3d28b8814131dd255c2de1d1cf1aab3adb
2 files changed +38 -5
packages/shared/src/logging.test.ts
+30 -1
@@ -33,7 +33,36 @@ afterEach(() => {
33 }
34 });
35
36 -effectIt.layer(NodeServices.layer)("asynchronous rotating file sink", (it) => {
36 +effectIt.layer(NodeServices.layer)("rotating file sinks", (it) => {
37 + it.effect.each(["synchronous", "asynchronous"] as const)(
38 + "%s startup prunes only canonical rotation suffixes",
39 + (mode) =>
40 + Effect.gen(function* () {
41 + const directory = makeTempDirectory();
42 + const filePath = NodePath.join(directory, "debug.log");
43 + const retained = ["1", "3", "04", "4.0", "4e0", "0x4", "+4", "notes"];
44 + for (const suffix of [...retained, "4", "50"]) {
45 + NodeFS.writeFileSync(`${filePath}.${suffix}`, suffix);
46 + }
47 + const options = { filePath, maxBytes: 100, maxFiles: 3 };
48 +
49 + const sink =
50 + mode === "synchronous"
51 + ? new RotatingFileSink(options)
52 + : yield* makeAsyncRotatingFileSink(options);
53 + if (sink instanceof RotatingFileSink) sink.write("current");
54 + else yield* sink.write("current");
55 +
56 + expect(NodeFS.readdirSync(directory).sort()).toEqual(
57 + ["debug.log", ...retained.map((suffix) => `debug.log.${suffix}`)].sort(),
58 + );
59 + expect(NodeFS.readFileSync(filePath, "utf8")).toBe("current");
60 + for (const suffix of retained) {
61 + expect(NodeFS.readFileSync(`${filePath}.${suffix}`, "utf8")).toBe(suffix);
62 + }
63 + }),
64 + );
65 +
66 it.effect("serializes concurrent appends across rotation and resumes an existing file", () =>
67 Effect.gen(function* () {
68 const directory = makeTempDirectory();
packages/shared/src/logging.ts
+8 -4
@@ -150,8 +150,10 @@ export class RotatingFileSink {
150 const baseName = NodePath.basename(this.filePath);
151 for (const entry of NodeFS.readdirSync(dir)) {
152 if (!entry.startsWith(`${baseName}.`)) continue;
153 - const suffix = Number(entry.slice(baseName.length + 1));
154 - if (!Number.isInteger(suffix) || suffix <= this.maxFiles) continue;
153 + const suffixText = entry.slice(baseName.length + 1);
154 + const suffix = Number(suffixText);
155 + if (!Number.isInteger(suffix) || String(suffix) !== suffixText || suffix <= this.maxFiles)
156 + continue;
157 NodeFS.rmSync(NodePath.join(dir, entry), { force: true });
158 }
159 } catch (cause) {
@@ -212,8 +214,10 @@ export const makeAsyncRotatingFileSink = Effect.fnUntraced(function* (
214 yield* Effect.gen(function* () {
215 for (const entry of yield* fs.readDirectory(directory)) {
216 if (!entry.startsWith(`${basename}.`)) continue;
215 - const suffix = Number(entry.slice(basename.length + 1));
216 - if (!Number.isInteger(suffix) || suffix <= options.maxFiles) continue;
217 + const suffixText = entry.slice(basename.length + 1);
218 + const suffix = Number(suffixText);
219 + if (!Number.isInteger(suffix) || String(suffix) !== suffixText || suffix <= options.maxFiles)
220 + continue;
221 yield* fs.remove(path.join(directory, entry), { force: true });
222 }
223 }).pipe(Effect.mapError(failure("prune")));