Skip to content

fix(assets): move model asset on model_type: edit to stay loader-coherent#14561

Draft
synap5e wants to merge 2 commits into
synap5e/feat/assets_add_file_path-BE-932from
synap5e/be-1641-core-edit-type-must-move-reregister-on-model-type-change
Draft

fix(assets): move model asset on model_type: edit to stay loader-coherent#14561
synap5e wants to merge 2 commits into
synap5e/feat/assets_add_file_path-BE-932from
synap5e/be-1641-core-edit-type-must-move-reregister-on-model-type-change

Conversation

@synap5e

@synap5e synap5e commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Closes BE-1641. Stacks on #14511 (synap5e/assets-namespaced-tags); auto-retargets to master when that lands.

Core advertises supports_model_type_tags: true, and the FE edit-type flow writes model_type:<folder_name> under that flag. But Core tag mutation was label-only: relabeling a checkpoint as model_type:loras left the file in checkpoints/ while the FE grouped/node-created it as a LoRA — a load-incoherent asset. Core's upload write was already semantic (BE-1463); only the edit-type relabel was not.

This makes the edit coherent by moving/re-registering the file to match the new model_type:, matching the upload contract.

How it works

The FE edit-type flow diff-dispatches DELETE /tags (old model_type:) then POST /tags (new model_type:). The move is driven off the POST /tags add (apply_tags), so there is no FE change. When a model_type:<folder> is applied to a filesystem-backed model asset whose file isn't already under that folder:

  1. Resolve <folder> → its base path (same machinery the upload path uses).
  2. Move the file to new_base / <relative path>preserving subfolder structure and filename (no rehash), os.replace with a shutil.move cross-device fallback.
  3. Re-derive the path-based system tags (models + model_type:*) from the new location, dropping stale ones and refreshing filename metadata — all in one transaction, with file rollback if the DB step fails.

Edge behavior

  • Collision (destination occupied on disk or by another reference) → reject (409), never clobber. The FE re-adds the prior model_type: on a non-2xx, so the asset stays coherent.
  • Unregistered model_type: → kept as a permissive label (no move, no reject) — preserves Core's existing local/trusted labeling contract (spec-drift §3). A real edit-type action always targets a registered folder.
  • Shared on-disk folders (e.g. diffusion_models/unet_gguf) → no physical move; plural model_type: twins are preserved (spec-drift §1).
  • Hash-only / non-model / API-created references → label-only, untouched.

Tests

  • tests-unit/assets_test/services/test_model_type_move.py — 13 service-level tests (move happy-path, subfolder/label/filename preservation, same-type & shared-dir no-ops, hash-only/non-model label-only, unknown-folder→label, collision×2→409, DB-failure rollback).
  • tests-unit/assets_test/test_tags_api.py — 2 HTTP end-to-end tests (real DELETE-then-POST edit-type move verified on disk; unknown folder stays a label).
  • Full tests-unit/assets_test: 435 passed, 10 skipped.

Acceptance criteria

  • Under supports_model_type_tags, a model_type: edit moves/re-registers the file so location stays coherent with the label.
  • The flag's "accepts model_type: writes" guarantee now holds coherently for edit-type (move), matching the semantic upload path (BE-1463).
  • Tests cover the move + coherence.

synap5e added 2 commits June 20, 2026 14:40
…rent

Under supports_model_type_tags, a model_type: edit on a filesystem-backed
model asset now relocates and re-registers the file to the folder matching
the new model_type:<folder_name>, so the file location stays coherent with
the label instead of a label-only relabel that left the file loader-orphaned.

Triggered off the POST /tags add (apply_tags): on a registered folder change
the file moves (preserving subfolder + filename), path-derived system tags
are re-derived, and filename metadata refreshed, all in one transaction with
file rollback on failure. Collisions are rejected (never clobber); an
unregistered model_type: stays a permissive label; non-model and hash-only
references are untouched. Shared on-disk folders keep their plural twins.
Make the edit path symmetric with upload: model_type: is an operational
placement tag on a model asset, so an unregistered folder_name is an invalid
placement target and is rejected (400 UNKNOWN_MODEL_TYPE), not stored as a
label. A real edit-type action always targets a registered folder from
discovery, so only junk manual adds are affected.

Narrowly update the system-looking-labels test to drop the now-operational
bare model_type: case (other reserved-ish prefixes still store as labels) and
add a focused unknown-model_type:-on-model-asset rejection test.
@synap5e synap5e force-pushed the synap5e/be-1641-core-edit-type-must-move-reregister-on-model-type-change branch from 57d0efd to 5e267fa Compare June 20, 2026 02:41
@synap5e synap5e changed the base branch from synap5e/assets-namespaced-tags to synap5e/feat/assets_add_file_path-BE-932 June 20, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant