Skip to content

[Draft] Sidebar directories stuck in "Loading..." #159

Closed

Description

@adamatan

An expanded directory in the sidebar file tree sometimes shows "Loading…" forever. It happens after the repo contents change (an agent turn writing files, a build step, a checkout), and it never resolves on its own.

Image

Repro

No reliable one yet. Both @adamatan and @simion have hit it, always after files changed on disk while a folder was open.

Workaround, and the first thing to check when it happens

Collapse the stuck folder and expand it again. That drops it out of the children cache and forces a fresh read.

This also splits the search space, so please note which one you see:

  • Contents appear right away: the tree lost the cached listing (a state bug in the frontend).
  • Still stuck: the directory read itself is failing or hanging (a task_dir_list bug).

A console check helps too. ensureLoaded logs dir list failed and refetchDir logs refetch dir failed, but the settle-triggered reload swallows its errors silently. A stuck row with a clean console points at the reload path.

Where it can come from

Not reproduced, so these are readings of the code, not a diagnosis. All three break the same invariant: a directory is in expanded with no entry in children, nothing in flight, and no retry.

The row itself never checks whether a read is running. src/components/task/FileTree.tsx:499 renders "Loading…" whenever an open directory has no cached children, so a dropped listing and a genuinely slow read look identical.

  1. The settle reload drops directories whose read failed. FileTree.tsx:148 turns a rejected taskDirList into null and skips that key, then FileTree.tsx:157 replaces the whole children map rather than merging. A directory being rewritten on disk at that moment (a build output dir, a generated tree) reads as an error, gets dropped, and stays stuck. This fits the screenshot: build and reference are both stuck while hand-written directories are fine. It also explains why it only shows up when the repo changes, since sameChildren at FileTree.tsx:156 skips the replace entirely when nothing changed.

  2. Expanding a folder during an in-flight reload. ensureLoaded writes children[rel], then the reload's wholesale replace at FileTree.tsx:157 clobbers it. The folder is still expanded, so it renders "Loading…" with nothing left to fill it.

  3. Restoring expanded folders on task switch. The mount effect (FileTree.tsx:120) has the same drop-on-failure shape for folders restored from expandedByTask.

Fix direction

Merge the reload result into the children cache instead of replacing it. Drive the "Loading…" row off the in-flight loading set (FileTree.tsx:88) so a stuck folder is visibly different from a slow one. Retry or surface a failed directory read rather than swallowing it.


@simion I have not found a clean repro either. I will dig into it, starting with whether the collapse/expand test above heals it.

Activity

  1. simion commented on Aug 4, 2026

    @simion
    Owner

    Happened to me too. Any ideas on how to reproduce?

  2. adamatan commented on Aug 4, 2026

    @adamatan
    ContributorAuthor

    Not yet, it's inconsistent.

  3. added
    bug
    on Aug 14, 2026
  4. simion commented on Aug 18, 2026

    @simion
    Owner

    Fix on main, 0863bdf. Still no repro, so this closes the state hole rather than the trigger.

    The mechanism, as far as the code goes. The settle reload (bumped by fsRevision, so it fires exactly when files just changed) re-read root plus every expanded dir, dropped the ones whose read rejected, and then replaced the whole children map with what was left. task_dir_list rejects on a transient miss: safe_task_path canonicalizes, so a directory that is momentarily absent while a build or a generator rewrites it is ENOENT. The dir stayed in expanded with no listing, nothing in flight and no retry, and the row rendered "Loading…" off isOpen && !kids alone. That is your cause 1, and it fits build and reference being the two stuck rows.

    Changes:

    • reloads merge into the cache instead of replacing it. A failed dir keeps the listing it had, a folder expanded while the reload was in flight survives (cause 2), only collapsed dirs get pruned. This also fixes a second thing in those lines: a failed ROOT read used to set rootEntries to [] and blank the tree.
    • a reconcile effect enforces the invariant that every expanded dir has a listing, a read in flight, or a failed mark. That heals a dropped listing whatever dropped it, cause 3 included.
    • a read gets one automatic retry, then the row says "Couldn't read this folder" with a retry, instead of spinning. A stuck folder is now diagnosable at a glance.
    • in-flight dirs moved to a ref. toggle starts a load from inside a setExpanded updater, so the state loading could lag and fire a duplicate read.

    Cache logic is in src/lib/explorer/dirCache.ts with unit tests, since there is nothing to test against otherwise. Two e2e cases in files.e2e.ts drive a real failure with chmod 000; the merge one fails against the old replace, verified by reverting it.

    Leaving this open. If it was something else, the retry row will say so next time instead of looking the same as a slow read.

  5. simion commented on Aug 18, 2026

    @simion
    Owner

    Closing. Fixed by 0863bdf, details above.

    It cannot sit on "Loading…" now: an expanded folder either has a listing, has a read in flight, or shows a retry row. If a folder ever shows that row, that is a directory read genuinely failing, which is a different bug from this one. Open a new issue with the path and I will look at what task_dir_list is rejecting.

  6. simion commented on Aug 19, 2026

    @simion
    Owner

    This shipped in v0.28.0, released today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions