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

Aperta
#1,672 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@yorzi ci sta già lavorando.

Dal 15/11/2026.

  • #1676 di @yorzi — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
32/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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)
Lingua principale
Ruby
Stelle
4.5k
Fork
537
Merge medio
7h 30m
PR unite (30g)
378

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di crmne/ruby_llm

Tutte le issue di crmne/ruby_llm

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.