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 24, 14:00 UTC
fix(server): preserve usage cache outside walked roots (#8540)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>
Simone committed
Sep 1, 2026 at 00:59 UTC
6d15c5bbc3f3c331a7466bb94c17413a35f7b659
2 files changed
+26
-1
apps/server/src/usage/usageScanCache.test.ts
+14
@@ -193,6 +193,20 @@ describe("pruneScanCache with an unwalked root", () => {
193
expect(removed).toBe(0);
194
expect(cache.size).toBe(1);
195
});
196
+
197
+ it("keeps entries under a sibling path that only shares the walked root prefix", () => {
198
+ const cache = cacheWith([["/claude/projects-copy/a.jsonl", 5000, [record()]]]);
199
+
200
+ const removed = pruneScanCache(cache, {
201
+ livePaths: new Set(),
202
+ walkedRoots: ["/claude/projects"],
203
+ windowStartMs: 4000,
204
+ retentionCutoffMs: 1000,
205
+ });
206
+
207
+ expect(removed).toBe(0);
208
+ expect(cache.size).toBe(1);
209
+ });
210
});
211
212
describe("dedupeWithinFile", () => {
apps/server/src/usage/usageScanCache.ts
+12
-1
@@ -14,6 +14,9 @@
14
*
15
* @module usageScanCache
16
*/
17
+// @effect-diagnostics nodeBuiltinImport:off
18
+import * as NodePath from "node:path";
19
+
20
import type { UsageProviderKind } from "@t3tools/contracts";
21
22
import type { UsageRecord } from "./usageTranscripts.ts";
@@ -229,7 +232,15 @@ export function pruneScanCache(cache: ScanCache, options: PruneOptions): number
232
let removed = 0;
233
for (const [path, entry] of cache) {
234
const agedOut = entry.mtimeMs < options.retentionCutoffMs;
232
- const underWalkedRoot = options.walkedRoots.some((root) => path.startsWith(root));
235
+ const underWalkedRoot = options.walkedRoots.some((root) => {
236
+ const relative = NodePath.relative(root, path);
237
+ return (
238
+ relative === "" ||
239
+ (relative !== ".." &&
240
+ !relative.startsWith(`..${NodePath.sep}`) &&
241
+ !NodePath.isAbsolute(relative))
242
+ );
243
+ });
244
const deleted =
245
underWalkedRoot && entry.mtimeMs >= options.windowStartMs && !options.livePaths.has(path);
246
if (agedOut || deleted) {