Review fixes for the staged LoRA import (#221):
- The metadata files are listed and fingerprinted again right before the
replace transaction, so a file changed, removed or added while the
downloads ran aborts the import with nothing deleted (System job:
plan-changed, Review again; legacy scan: an error frame in its own
words). The tests now change real files behind a held download.
- A legacy scan whose page closes stops staging before its next LoRA and
keeps its records hold until staging has stopped; CivitAI images are
written to a temp file beside the cache entry and moved in place, so a
half-written image is never seen as cached.
- Start refuses with plan-changed when the integration was turned off or
moved to another install since the review.
- A failed job keeps the skipped count and the names of the LoRAs that
could not be prepared.
- The replace binds the category instead of one parameter per prompt
(SQLite's variable limit), /lora/status says whether a detected install
can be used, and the legacy scan logs expected refusals as warnings.
The LoRA import deleted the whole lora-manager category first and then
saved each record in its own transaction, so a discovery, download or
database failure left the previous collection gone or partial.
The import now runs in three stages: discover and fingerprint the
metadata files, stage every record (CivitAI downloads go into the image
cache first, counted), then replace the category in one BEGIN IMMEDIATE
transaction (replace_category_prompts). Any failure leaves the previous
prompts, tags and image links exactly as they were. Prompts a saved pair
uses block the replacement; an empty replacement of a non-empty
collection needs a reviewed import.
POST /prompt_manager/lora/import/preview reviews an import without
writing or requesting anything; POST /lora/import/apply {token} runs it
as the Activity job "LoRA reference import" (records admission,
cancellable while it downloads, the safety backup policy before the
replace, refused with plan-changed when the files changed since the
review). The legacy POST /lora/scan runs the same stages with its SSE
event shape.