Repository navigation
Studio sd.cpp: stage server-mode image LoRAs as hard links so sd-server lists them - #14860
Conversation
sd-server master-982 canonicalizes every file under --lora-model-dir and skips one that resolves outside it, so the symlink Studio staged into the LoRA cache was never listed and a request naming it was rejected. Server staging now hard links the adapter (copy fallback), which keeps the canonical path inside the server directory. sd-cli staging is unchanged.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4cf7333b3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| materialized = diffusion_lora.materialize_native_dir( | ||
| lora_resolved, lora_stage, real_files = True | ||
| ) |
There was a problem hiding this comment.
Restage LoRAs after restarting the server on CPU
This stages the hard links only in the current server's lora_dir. If generation triggers the unsupported-GPU-op fallback, _restart_server_on_cpu_backend stops that server—deleting its scratch directory—and starts a replacement with a different lora_dir, but the retry reuses the original lora payload. Consequently, LoRA requests requiring the automatic CPU fallback reference a nonexistent gen_* path and fail; restage the adapters in the replacement server and rebuild the payload, as is already done for the hires upscaler.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, fixed. LoRA staging now lives in a per-server helper, like the hires upscaler. When the CPU-backend restart replaces the server, the adapters are staged again in the new server's lora_dir and the retried payload's lora block is rebuilt. If the replacement has no LoRA directory, the request fails with a clear error instead of silently dropping the LoRAs. All staged directories are removed in the existing finally. Covered by test_server_cpu_restart_restages_loras_in_the_new_server_dir, which fails on the previous head.
| except OSError: | ||
| import shutil | ||
| shutil.copy2(r.path, link) |
There was a problem hiding this comment.
Remove partial staging files when the copy fallback fails
When the cache and server scratch directory are on different filesystems, os.link raises EXDEV and this branch copies the potentially multi-GB adapter. If copy2 then fails, such as when /tmp runs out of space, it leaves the partial file and any earlier adapters in dest; the server caller invokes materialization before entering its cleanup try/finally, so that gen_* directory persists until the server is stopped and repeated attempts can retain exhausted disk space. Clean dest on failure or move server staging inside the cleanup scope.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed. A failed copy fallback now removes its partial file before re-raising. Server staging also moved inside the generation try/finally, so any adapters already staged in the gen_* directory are removed on failure too. Covered by test_server_lora_staging_failure_leaves_no_partial_stage (hard link refused, copy fails part-way), which fails on the previous head.
…ed copies The CPU-backend fallback replaces sd-server with one that has its own scratch directory, but the retry reused the LoRA payload staged in the stopped server's directory. Stage the adapters again in the replacement, as the hires upscaler already is. Staging now runs inside the cleanup scope, and a copy fallback that fails removes its partial file. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
Since the master-982 pin (#14565), the resident sd-server ignores image LoRAs that Studio stages for it.
materialize_native_dirstages each adapter as a symlink from the per-requestgen_*directory, under--lora-model-dir, to the file in the LoRA cache. In sd-server at0518b34(unchanged in the Unsloth patch set):examples/server/runtime.cpp:294-298(refresh_lora_cache) callsfs::canonicalon every entry and skips any entry that resolves outside the LoRA directory.examples/server/runtime.cpp:336-338(get_lora_full_path) repeats the containment check on the canonical path and requires a regular file.So the staged symlink is never listed. The structured
loraentry then fails to resolve, and the request is rejected.With the real master-982 CPU
sd-server,/sdapi/v1/loraslists a regular file and a hard link but leaves out Studio's symlink. The server log showsskipping inaccessible LoRA or path outside LoRA directory ... runtime.cpp:297.Fix
materialize_native_dirgainsreal_files=True, which stages a hard link with the existing copy fallback (for example across filesystems). The server generation path passes it. A hard link's canonical path stays inside the server directory, so sd-server's containment check is satisfied and stays fully in force. sd-cli staging is unchanged: it resolves<lora:...>tags withfs::exists/is_regular_file, which follow symlinks.Tests
test_materialize_native_dir_real_files_hardlinks_inside_dest: checks the staged file is not a symlink, its canonical path is inside the destination, and it is the same inode as the source.test_materialize_native_dir_real_files_copies_when_hardlink_fails: checks the copy fallback whenos.linkraises.test_generate_server_stages_loras_as_real_files_inside_the_lora_dir: runs the real materializer through server-modegenerate, checks the staged file resolves inside--lora-model-dir, and checks that cleanup leaves the source intact.test_diffusion_lora.pyandtest_sd_cpp_backend.pygive 190 passed.sd-server, the main materializer's output is skipped and the fixed materializer's output is listed.Not covered
os.linkon NTFS should work, and the copy fallback covers FAT and exFAT.