fix(sidebar): empty environment children from cache poisoning + watcher gap - #905
Merged
Merged
Conversation
…er gap (#903) Two bugs combined to make resolved (non-workspace) environment nodes expand with nothing beneath them: 1. Cache poisoning: readDirectoryEntries swallows errors and returns []. The webview cached [] (truthy), so all !childrenCache[path] guards evaluated false, permanently suppressing re-requests. Fix: never cache empty arrays — delete the key instead, leaving undefined (falsy) so future renders re-request children. 2. Watcher gap: setupWatcher uses createFileSystemWatcher('**/*') which is workspace-scoped, and the handler checks getWorkspaceFolder(uri) which drops non-workspace URIs. Resolved environments (source: 'resolved', auto-surfaced from the registry) are not workspace folders, so filesystem changes inside them never invalidated the poisoned cache. Fix: create per-path FileSystemWatcher using RelativePattern for resolved environment paths. Watchers are refreshed on roots changes, deduped, debounced (300ms), and disposed cleanly. Also adds console.warn to readDirectoryEntries catch block for future diagnosis visibility.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Expanding a resolved (non-workspace) environment root in the sidebar shows nothing beneath it — the chevron rotates but zero filesystem children render, despite the directory having contents.
Root cause
Two bugs combine:
1. Cache poisoning (
sidebar_webview.ts)readDirectoryEntriescatches all errors and returns[]. The webview caches this aschildrenCache[path] = []. Because[]is truthy in JavaScript, all!childrenCache[path]guards evaluatefalse, permanently suppressing re-requests for that path.2. Watcher gap (
sidebar_view.ts)setupWatcherusescreateFileSystemWatcher('**/*')(workspace-scoped) and the handler checksgetWorkspaceFolder(uri)— both drop non-workspace URIs. Resolved environments (source: "resolved", auto-surfaced from the registry) are not workspace folders, so filesystem changes inside them never invalidate the poisoned cache.Fix
Fix 1: Never cache empty arrays —
deletethe key on empty responses soundefined(falsy) lets future renders re-request children.Fix 2: Create per-path
FileSystemWatcherusingRelativePatternfor resolved environment paths. Watchers are refreshed on roots changes, deduped by path set, debounced (300ms), and disposed cleanly.Bonus: Added
console.warntoreadDirectoryEntriescatch block for future diagnosis.Verification
pnpm -r build— cleanpnpm --filter amicode test— 2980 passed, 0 failures (including all 278 sidebar tests)Closes #903