Skip to content

Commit 5b00203

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 b50d3a0 commit 5b00203

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
@@ -466,17 +466,24 @@ export class InlineScriptEnvManager implements EnvironmentManager, Disposable {
466466
}
467467

468468
if (checkForSnapshotChanges) {
469+
let finalEntryNames: string[] | undefined;
469470
try {
470-
const finalEntryNames = await fs.readdir(cacheRoot.fsPath);
471+
finalEntryNames = await fs.readdir(cacheRoot.fsPath);
472+
} catch (error) {
473+
if (this.isDefinitivelyStalePathError(error)) {
474+
finalEntryNames = [];
475+
} else {
476+
shouldRetry = true;
477+
}
478+
}
479+
if (finalEntryNames !== undefined) {
471480
const initialEntries = new Set(entryNames);
472481
if (
473482
finalEntryNames.length !== entryNames.length ||
474483
finalEntryNames.some((entryName) => !initialEntries.has(entryName))
475484
) {
476485
shouldRetry = true;
477486
}
478-
} catch {
479-
shouldRetry = true;
480487
}
481488
}
482489

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

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

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

0 commit comments

Comments
 (0)