Skip to content

DRAFT: fix(storage): fail-closed directory deletion and moves (#351 upstream) - #1

Draft
JayceeB1 wants to merge 25 commits into
mainfrom
fix/storage-destructive-operations
Draft

JayceeB1 wants to merge 25 commits into
mainfrom
fix/storage-destructive-operations

Conversation

@JayceeB1

@JayceeB1 JayceeB1 commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Safety hotfix (review/staging PR)

This is the same branch intended for a draft PR to lightningpixel/modly:dev. The linked GitHub integration does not currently have permission to create a PR in that upstream repository (403). Opening the draft here preserves a reviewable diff while waiting for a normal cross-fork submission.

Why

See upstream #351 (reported catastrophic data loss, not independently reproduced). Source inspection confirmed unguarded copy → recursive delete during moves and unsafe raw startsWith deletion allow-list.

Patch

  • Centralize both fs:moveDirectory and fs:deleteDirectory into fail-closed main-process guards.
  • Reject volume/filesystem roots, relative/shallow/unsupported paths, dangerous home/app/config ancestors, symlink/junction ancestry, and storage path overlap.
  • Require a separate empty move destination; refuse overwrite if a file appears during copy; recheck before source deletion.
  • Keep legitimate workspace tmp cleanup and enable workflow storage deletion.
  • Add 12 regression tests for Windows path semantics and isolated real filesystem fixtures.

Verification

  • Focused 12 tests passed locally under Node 22/Linux, with simulated Windows paths.
  • Full project CI, Windows runtime/junction tests, and security review.
  • Consider directory ownership markers/inventory: path guards cannot prove that all files in a user-selected directory belong to Modly.

No upstream code is changed by this PR. Please do not merge without the remaining validation.

Upstream lightningpixel#351: lightningpixel#351
Intended upstream PR comparison: lightningpixel/modly@dev...JayceeB1:modly:fix/storage-destructive-operations

JayceeB1 and others added 25 commits October 9, 2026 22:41
Confirmed by combined CI regression. Remove only an empty target with rmdir; never remove source on copy failure.
inspect_mesh diagnoses a mesh without modifying it: watertight, manifold,
winding, holes, degenerate and self-intersecting faces, parts, bounds,
area, volume, UVs/normals, and a printable verdict. suggest_fixes derives
registry op calls (repair, decimate) from that report, and lists the
problems no op can fix yet as notes.

Topology is checked on a position-merged copy, so UV seams do not read
as holes. Self-intersections go through pymeshlab; when they are not
checked, printable is null rather than a claim. Normals are read from
the file itself, since trimesh computes them on demand.

MeshOpResult.file_path is now optional so analysis ops return only
their report. Both ops are exposed to the agent and the MCP server.

Closes lightningpixel#296
…spect-mesh

feat(mesh-ops): read-only inspect_mesh and suggest_fixes ops (T-A2)
…point

Four registry ops derive their 4x4 matrix from the mesh itself:
recenter (centroid to origin), drop_to_ground (lowest point to y = 0),
auto_orient (smallest rotation that turns the thinnest PCA axis
vertical; meshes without a clear flat side are left alone) and
normalize_scale (size in m/cm/mm along the longest side or one axis).

apply_transforms composes requested steps in a fixed order (orient,
scale, recenter, ground) on one load and writes a single file, so
grounding is never undone by a later step. POST /optimize/arrange
exposes it, validating each step's params through the registry, and
the raw /transform endpoint now shares the same bake helper.

The agent and MCP server get an arrange_mesh tool that takes every
step at once and reports the new mesh path for chaining.

The world-space geometry helpers move to mesh_ops/geometry.py, shared
with inspect_mesh, and the registry exposes resolve_params.

Closes lightningpixel#297
…mantic-transforms

feat(mesh-ops): semantic transforms and one-call arrange (T-A3)
repair_mesh diagnoses the mesh, runs only the steps the diagnostic calls
for (degenerate faces, non-manifold edges, hole filling without a size
limit, face re-orientation), then re-checks, for up to three passes or
until a pass makes no progress. A mesh left inside-out is flipped at the
end. Each pass is judged on position-merged geometry, exactly as
inspect_mesh sees it, so UV seams are not mistaken for holes and a
reported success holds once the file is re-inspected.

A sound mesh is left alone and no file is written. With fill_holes off,
only face-preserving fixes run, since removing faces would open holes.
The result reports the before/after topology, the remaining issues, and
whether textures were dropped (the output is geometry only).

inspect_mesh now flags inside-out meshes, and suggest_fixes proposes
repair_mesh, which also makes inconsistent winding fixable. The legacy
repair op is unchanged for the mesh-repair workflow node.

The generic /optimize/op route now writes its output next to the input
under a unique name, like the dedicated edit routes.

The agent and MCP server get a repair_mesh tool.

Closes lightningpixel#298
The shipped venv installs only api/requirements.txt, which never pulls
scipy: trimesh treats it as optional. inspect_mesh, suggest_fixes and
repair_mesh need it for connected parts, hole loops and vertex merging,
so they failed outside a dev environment, where torch brings it in.

repair_mesh re-oriented faces with trimesh.repair.fix_winding, which
needs networkx, also undeclared; it now uses pymeshlab, and skips the
step for a pass while the mesh is still non-manifold.

A guard test runs every mesh-op family with networkx unimportable,
including the re-orientation path, and checks scipy stays declared.
…pair-mesh

feat(mesh-ops): diagnostic-driven repair_mesh composite op (T-A4)
agent_chat now returns a StreamingResponse emitting token, thinking,
tool_start, tool_done and done events. ChatPanel consumes the stream so
text appears progressively and tool calls show an in-progress state.

Closes lightningpixel#300
…ent-streaming

feat(agent): stream chat responses as typed SSE events
agent_chat now returns a StreamingResponse emitting token, thinking,
tool_start, tool_done and done events. ChatPanel consumes the stream so
text appears progressively and tool calls show an in-progress state.

Closes lightningpixel#300
…eaming-to-dev

feat(agent): stream chat responses as typed SSE events
…ine Repair

has_nvidia_gpu() only checked that nvidia-smi was on PATH. A leftover
nvidia-smi.exe with no NVIDIA driver/GPU behind it (e.g. an AMD machine) got
the CUDA llama.cpp build, and llama-server fell back to CPU. It now requires
`nvidia-smi -L` to succeed and list a GPU; the result is cached since
/llm/status calls it on every poll.

Machines that already received the wrong build had no way back: the UI only
offers "Install engine" while the engine is missing. Settings > Agent now has
an Engine > Repair action (GET /llm/binary/install?repair=true) that
re-detects the GPU, downloads and extracts the new build into a staging dir,
then swaps it in place of bin/. The working engine is only touched once the
new one is fully extracted, so a failed download keeps it intact.

Fixes lightningpixel#386
- test_auto_orient_does_not_flip_a_mesh_over: trimesh's update_faces keeps
  the cut-away vertices, so the exported bowl still carried the whole
  sphere's vertices and the "center" was measured on the orphan top cap.
  Drop unreferenced vertices; auto_orient itself was correct.
- test_mesh_ops_run_without_undeclared_networkx runs repair_mesh, which
  needs pymeshlab: skip it when pymeshlab is missing, like the other
  repair/inspection tests.
…dia-detection

fix(llm): pick CUDA only when an NVIDIA GPU actually answers, add engine Repair
switch_model unloads the previous model on every switch. When you run
TripoSG and then Trellis2 Texture Mesh on the same object, both models get
reloaded for every single asset, which cost me 20-27 s per switch on a
3090 Ti.

This keeps the two loaded side by side. Any other switch, and the LLM
eviction, works exactly as before.

Two assets (cart + soldier, 3000 faces, warm): 197 s -> 110 s.
`dev serve-api` / `dev ensure-server --start` ignored dependenciesDir from
settings.json. If the dependencies live on another drive (mine are on F:),
the venv isn't found and it falls back to whatever Python runs the CLI,
which doesn't have the backend deps.

It now checks dependenciesDir first, and passes the env vars the Electron
bridge sets: PYTHONIOENCODING=utf-8, MODLY_LLM_DIR (agentDir) and
MODLY_NODE_EXECUTABLE (Modly.exe) for the installed app.

Added two tests; the existing ones still pass.
… pair on VRAM

switch_model only unloaded the previous active model. After
TripoSG -> Trellis2 refine -> any other model, TripoSG was no longer
active but stayed loaded beside the new model until unload_all.
switch_model now unloads every loaded model except the target and its
resident partners.

Keeping both models resident also assumed a card with room for both
(~10-11 GB peak). Each pair now declares a minimum total VRAM; below it,
or when no NVIDIA GPU answers, switching behaves as before. The pair is
set to 19.5 GiB (24 GB cards), the configuration the speedup was
measured on. Manifests can't size this: TripoSG declares no vram_gb.
…texture-models-resident

Keep TripoSG and the texture model loaded together
… the desktop bridge

The started API inherited PYTHONHOME, PYTHONPATH, VIRTUAL_ENV, CONDA_PREFIX
and the PIP_* variables of whatever shell ran the CLI. From a conda env or
an activated venv, these point Modly's venv interpreter at foreign
site-packages, or keep it from starting at all. They are now removed, the
same list Electron's cleanPythonEnv() strips.

_default_python also tried the api's dev .venv before the app's venv,
the reverse of the PythonBridge. The app's venv (dependenciesDir, then the
default dependencies folder) now comes first, the dev .venv second.
…esktop-env

modly-cli: start the API with the same setup as the desktop app
…rors

- Copy into a unique sibling staging folder, then rename onto the verified-empty
  destination; a failed copy is discarded so the source stays intact and a
  retry does not hit "Destination must be empty".
- Drop the post-copy re-validation: it re-ran a pure check on the same inputs.
- Windows: accept a top-level folder on a data drive (D:\Models) and refuse the
  well-known system folders instead; POSIX keeps the two-level minimum.
- Path API follows options.platform everywhere, including the symlink check.
- Return the guard's message over IPC and show it in the move/delete modal.
- Tests: resolve tmpdir() through realpath (macOS /var symlink), run the
  junction test on Windows, cover empty existing destinations and failed copies.
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.

4 participants