[BUG] FileStore::Directory#list returns nothing when a file vanishes mid-listing

Open
#1,672 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@yorzi is already working on this.

Since Nov 15, 2026.

  • #1676 by @yorzi — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
32/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
ruby
Domain
backend

Research direction

Start in the file store's directory implementation, at FileStore::Directory#list and #walk, where Find.find yields names and File.lstat raises. The reporter's stub deletes one file right before lstat, so reproduce with that before changing anything. Done means a listing with a vanished name still returns every other file, while permission errors still end the listing — but note an open PR (#1676) already proposes exactly this fix, so coordinate before writing code.

Written by the indexing model from the issue text.

Description

bug
Basic checks
  • I searched existing issues - this hasn't been reported
  • I can reproduce this consistently
  • This is a RubyLLM bug, not my application code
What's broken?

FileStore::Directory#list walks the folder with Find.find, which reads a folder's names and then yields them one at a time. #walk calls File.lstat on each name it is given. When a name disappears between the two, Errno::ENOENT escapes #walk, and the rescue SystemCallError in #list turns the whole listing into []. The same happens with Errno::ENOTDIR when a folder is replaced by a file.

The store causes this itself: #write writes a hidden temporary file and renames it into place. #list does not take the store's lock, so a listing that runs while another thread or process writes can see the temporary name and lose it before lstat. list_files then tells the model the chat has no files, and search_files finds nothing. Find already skips names that vanish when it checks them itself, so the file store is the only place that turns one vanished name into an empty result.

This is not about which files a listing shows while it races a write. It is about losing every other file in the folder.

How to reproduce
require "ruby_llm"
require "tmpdir"

Dir.mktmpdir do |folder|
  store = RubyLLM::FileStore::Directory.new(folder)
  store.write("a.txt", "a")
  writer = Thread.new { 3000.times { |i| store.write("notes-#{i % 5}.txt", i.to_s) } }
  listings = []
  listings << store.list.size while writer.alive?
  writer.join
  puts "#{listings.count(0)} of #{listings.size} listings were empty"
end

a.txt exists the whole time, so no listing should be empty. On my machine 279 to 519 of every 6,000 to 8,000 listings came back empty (about 4 to 7 percent). The rate depends on timing, but the cause is deterministic: a stub that deletes one file right before File.lstat reaches it empties the listing every time.

Expected behavior

list returns the files that are still there, and leaves out only the one that vanished.

What actually happened
519 of 7884 listings were empty

I have a small local fix with specs and can open a PR: #walk skips a name that raises Errno::ENOENT or Errno::ENOTDIR, as Find does. Other errors, such as a permission error, still end the listing as they do now.

Environment
  • Ruby version: ruby 3.3.5
  • RubyLLM version: main at 9c20ca61
  • Provider: none (file store only)
  • OS: macOS (Darwin 27, APFS)
Dominant language
Ruby
Stars
4.5k
Forks
537
Avg merge
7h 30m
Merged PRs (30d)
378

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from crmne/ruby_llm

All issues in crmne/ruby_llm

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.