Skip to content

Commit 5ff8cad

Browse files
fix(server): don't cache transient git failures in status lookups
Set failure TTL to Duration.zero for defaultBranchCache and originExistsCache so transient git errors aren't held for 5 min. Adds a retry test that proves the cache expires after TTL: caches hasOriginRemote=false via normal read, bypasses invalidation by adding origin through raw git, then advances past the 5-min TTL with TestClock and confirms the next read picks up the new value.
1 parent 5212502 commit 5ff8cad

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,33 @@ it.effect("invalidates origin remote cache when a driver mutation adds origin",
171171
}).pipe(Effect.provide(TestLayer)),
172172
);
173173

174+
it.effect("re-reads origin remote status after cache TTL expiry and bypassed invalidation", () =>
175+
Effect.gen(function* () {
176+
const driver = yield* GitVcsDriver.GitVcsDriver;
177+
const cwd = yield* makeTmpDir();
178+
const remote = yield* makeTmpDir("git-vcs-driver-remote-");
179+
yield* initRepoWithCommit(cwd);
180+
yield* git(remote, ["init", "--bare"]);
181+
182+
// First call caches hasOriginRemote = false (5-min TTL)
183+
assert.equal((yield* driver.statusDetailsLocal(cwd)).hasOriginRemote, false);
184+
185+
// Add origin via raw git (bypasses invalidation hook)
186+
yield* git(cwd, ["remote", "add", "origin", remote]);
187+
188+
// Cache still has the stale false (TTL not yet expired)
189+
const stillCached = yield* driver.statusDetailsLocal(cwd);
190+
assert.equal(stillCached.hasOriginRemote, false);
191+
192+
// Advance past the 5-minute TTL so the cache entry expires
193+
yield* TestClock.adjust("6 minutes");
194+
195+
// After expiry, the next call re-executes and picks up the remote
196+
const afterExpiry = yield* driver.statusDetailsLocal(cwd);
197+
assert.equal(afterExpiry.hasOriginRemote, true);
198+
}).pipe(Effect.provide(TestLayer)),
199+
);
200+
174201
it.effect("coalesces concurrent ref pages into one repository snapshot", () =>
175202
Effect.scoped(
176203
Effect.gen(function* () {

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
11411141
}),
11421142
{
11431143
capacity: 2_048,
1144-
timeToLive: () => STATUS_DEFAULT_BRANCH_CACHE_TTL,
1144+
timeToLive: Exit.match({
1145+
onSuccess: () => STATUS_DEFAULT_BRANCH_CACHE_TTL,
1146+
onFailure: () => Duration.zero,
1147+
}),
11451148
},
11461149
);
11471150
const originExistsCache = yield* Cache.makeWith(
@@ -1159,7 +1162,10 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
11591162
}),
11601163
{
11611164
capacity: 2_048,
1162-
timeToLive: () => STATUS_ORIGIN_EXISTS_CACHE_TTL,
1165+
timeToLive: Exit.match({
1166+
onSuccess: () => STATUS_ORIGIN_EXISTS_CACHE_TTL,
1167+
onFailure: () => Duration.zero,
1168+
}),
11631169
},
11641170
);
11651171
const invalidateStatusStaticCaches = (cwd: string) =>

0 commit comments

Comments
 (0)