The loader opened the model file again for every batch of tensors, in every
worker thread: once per component at startup (text encoder, UNet, VAE) and
then again each time weights are loaded back from disk (per segment, per
residency swap, per request). Each open is a chance to fail, and on Windows
it can fail exactly when the system is short of memory or handles
("failed to open '...safetensors'" at VAE decode, after RAM hit 100%).
A new FileHandlePool keeps the read streams open and hands them out to the
workers one at a time. ModelLoader owns one; copies and the per-file readers
used for LoRA tensors share it. A stream is dropped when the file's size or
modification time changes, when it is in an error state, or when its source
is removed. If a read fails the worker reopens the file once and repeats the
read, so a stream that went bad while idle (removable or network storage)
no longer fails the whole generation. The open retry with errno/doserrno
logging moves into the pool and now also covers .ckpt (zip) files.
Measured with a synthetic SD 1.5 checkpoint on CPU: the file is opened 5
times for three server requests instead of 9 per request; an injected EIO is
absorbed and the image is pixel-identical; persistent read errors end in a
clean error. test/file_handle_pool_test.cpp covers reuse, changed and
replaced files, failed streams, limits and concurrent use, and passes under
ASan/UBSan and ThreadSanitizer.
Claude-Session: https://claude.ai/code/session_01EhZzDBkuuMp1jBf4WtEySC