Skip to content

fix(generate): read WORKSPACE_DIR dynamically so relocated output isn't lost - #287

Open
kevin9327 wants to merge 1 commit into
lightningpixel:devfrom
kevin9327:fix/generation-dynamic-workspace-dir
Open

fix(generate): read WORKSPACE_DIR dynamically so relocated output isn't lost#287
kevin9327 wants to merge 1 commit into
lightningpixel:devfrom
kevin9327:fix/generation-dynamic-workspace-dir

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What

After the workspace is relocated at runtime (POST /settings/paths), 3D generations kept writing their output into the previous workspace directory, while /workspace/{path} served files from the new one — so the finished mesh 404s and never appears in the app.

Why it triggers

api/routers/generation.py bound the workspace path with from services.generator_registry import WORKSPACE_DIR, capturing the Path at import time. POST /settings/pathsgenerator_registry.update_paths() rebinds the WORKSPACE_DIR module global (and repoints every loaded generator's outputs_dir):

# services/generator_registry.py
_self_module.WORKSPACE_DIR = workspace_dir
for gen in self._generators.values():
    gen.outputs_dir = workspace_dir

Because _run_generation used the stale imported name, it recomputed coll_dir = WORKSPACE_DIR / collection against the old directory and set gen.outputs_dir back to it — overriding the value update_paths had just written — then built output_url relative to the same stale path. /workspace/... reads the current WORKSPACE_DIR dynamically, so it can't find the file.

This affects both /generate/from-image and /workflow-runs/from-image (both funnel through _run_generation).

Fix

Reference the module attribute registry.WORKSPACE_DIR at call time instead of a name captured at import — the same way optimize.ply_to_splat (comment: "workspace dir may change at runtime") and the settings router already read it.

Verification

  • Added api/tests/test_generation_router.py: drives _run_generation with a fake generator after relocating the workspace, and asserts the output is filed under the current workspace (and that output_url matches). Fails before, passes after.
  • python -m unittest discover -s tests in api/ (venv with fastapi + python-multipart + httpx): all pass, 0 failures.

…'t lost

_run_generation bound WORKSPACE_DIR via `from services.generator_registry
import WORKSPACE_DIR`, capturing the path at import time. POST /settings/paths
-> generator_registry.update_paths() rebinds that module global (and repoints
every generator's outputs_dir), so after the user relocates the workspace the
generation path kept writing into the *old* directory while /workspace/ serves
files from the new one — the generated mesh 404s and never appears.

Reference the module (registry.WORKSPACE_DIR) at call time instead, matching
how ply_to_splat and the settings router already read it ("workspace dir may
change at runtime"). Covers both /generate/from-image and /workflow-runs
(both funnel through _run_generation).

Adds api/tests/test_generation_router.py: a run started after the workspace is
relocated must file output under the current workspace (fails before, passes
after).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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