Skip to content

Commit b7f25f2

Browse files
Handle missing final discovery snapshot
Avoid bounded retries when the cache remains definitively empty. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6b12d843-8011-4bfc-9ba9-f75761eadee2
1 parent 0802643 commit b7f25f2

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/managers/builtin/inlineScript/envManager.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,17 +498,24 @@ export class InlineScriptEnvManager implements EnvironmentManager, Disposable {
498498
}
499499

500500
if (checkForSnapshotChanges) {
501+
let finalEntryNames: string[] | undefined;
501502
try {
502-
const finalEntryNames = await fs.readdir(cacheRoot.fsPath);
503+
finalEntryNames = await fs.readdir(cacheRoot.fsPath);
504+
} catch (error) {
505+
if (this.isDefinitivelyStalePathError(error)) {
506+
finalEntryNames = [];
507+
} else {
508+
shouldRetry = true;
509+
}
510+
}
511+
if (finalEntryNames !== undefined) {
503512
const initialEntries = new Set(entryNames);
504513
if (
505514
finalEntryNames.length !== entryNames.length ||
506515
finalEntryNames.some((entryName) => !initialEntries.has(entryName))
507516
) {
508517
shouldRetry = true;
509518
}
510-
} catch {
511-
shouldRetry = true;
512519
}
513520
}
514521

src/test/managers/builtin/inlineScript/envManager.unit.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,23 @@ suite('InlineScriptEnvManager', () => {
15881588
assert.deepStrictEqual(await manager.getEnvironments('all'), [environment]);
15891589
});
15901590

1591+
test('does not retry when the final cache-root snapshot is definitively absent and empty', async () => {
1592+
const readdirStub = sinon.stub(fsExtra, 'readdir');
1593+
readdirStub.onFirstCall().resolves([]);
1594+
readdirStub.onSecondCall().rejects(Object.assign(new Error('cache root removed'), { code: 'ENOENT' }));
1595+
const retryManager = manager as unknown as {
1596+
getDiscoveryRetryDelayMs(attempt: number): number | undefined;
1597+
};
1598+
sinon.stub(retryManager, 'getDiscoveryRetryDelayMs').returns(0);
1599+
1600+
manager.startActivationDiscovery();
1601+
await waitForStubCallCount(readdirStub, 2);
1602+
await new Promise((resolve) => setTimeout(resolve, 25));
1603+
1604+
assert.strictEqual(readdirStub.callCount, 2);
1605+
assert.deepStrictEqual(await manager.getEnvironments('all'), []);
1606+
});
1607+
15911608
test('refresh skips missing, invalid, unavailable, and non-directory cache entries', async () => {
15921609
const valid = await createOwnedEnvironment();
15931610
const cacheRoot = cacheLayout.getScriptEnvCacheRoot(globalStorageUri).fsPath;

0 commit comments

Comments
 (0)