Skip to content

refactor(tools): extraer worker de upscale - #133

Merged
IAnMove merged 3 commits into
mainfrom
feat/extract-tools-upscale
Sep 4, 2026
Merged

refactor(tools): extraer worker de upscale#133
IAnMove merged 3 commits into
mainfrom
feat/extract-tools-upscale

Conversation

@IAnMove

@IAnMove IAnMove commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Qué cambia

  • Extrae el procesamiento completo de Tools/Upscale (imagen y vídeo) a app/services/tools_upscale.py.
  • Mantiene una fachada compatible en _launch_runtime.py y conserva la resolución de fuentes, coordinación GPU, progreso, cancelación, sidecars y lifecycle.
  • Inyecta explícitamente las dependencias del runtime; el servicio no importa _launch_runtime, FastAPI ni inicializa WanGP.
  • Actualiza los contratos AST y el test de lifecycle para cubrir la nueva frontera.

Qué no cambia

  • No se modifican rutas HTTP, payloads, nombres de métodos ni destinos de salida.
  • No se toca wgp.py, modelos vendor, generación real ni configuración de Pinokio.
  • No se ejecutan generaciones reales en CI.

Validación local

  • PYTHON=app/env/bin/python bash scripts/validate_local.sh
  • 11 contratos Python, ratchet contra origin/main, 605 tests UI, lint, build y 7 E2E simulados.
  • Suite focal: 28 tests y py_compile OK.

Note

Medium Risk
Large refactor of GPU upscale job orchestration with behavior preserved mostly by copy-paste; any wiring mistake in the injected runtime map or error-path differences (e.g. missing source now raises FileNotFoundError) could affect production upscale jobs.

Overview
Moves the full Tools upscale implementation (image still path, FlashVSR chunked video, Lanczos, audio remux, sidecars, cancel/progress) out of _launch_runtime.py into new app/services/tools_upscale.py, with shared constants (TOOL_UPSCALE_METHODS, TOOL_SOURCE_EXTENSIONS) living in the service.

_launch_runtime.py keeps the HTTP contract: it re-exports those constants for validation, turns _upscale_tool_image and _run_tool_upscale into thin facades that call tools_upscale.upscale_image / run_tool_upscale, and passes a runtime map (jobs, wgp, GPU slot, lifecycle helpers, chunked FlashVSR, path resolution, sidecar writer). The service is meant to be testable without importing the launch bootstrap or FastAPI.

Tests now AST-check run_tool_upscale and helpers in the service module, assert the launch worker only delegates to run_tool_upscale, and extend job-lifecycle wiring to count lifecycle hooks via the injected runtime keys.

Reviewed by Cursor Bugbot for commit 82a71cb. Configure here.

@IAnMove

IAnMove commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

@cursor review

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

PR Review — Loreframe Studio

Risk: low
Scope: 4 file(s); +495/-349; backend services

Automated review from scripts/analyze_pr.py. This is a heuristic pass (no LLM) so humans still own the merge decision.

Findings

  • No heuristic issues. Still run the CI checklist below.

Changed files

  • added: app/services/tools_upscale.py
  • modified: app/_launch_runtime.py, tests/test_job_lifecycle_wiring.py, tests/test_tools_upscale_contract.py

CONTRIBUTING checklist

  • python scripts/verify_clean_repo.py
  • python -m compileall -q app/services app/launch.py scripts
  • cd ui && npm run build if the UI changed
  • No weights, CivitAI sidecars, or generated guides
  • Stays local-first (no required accounts / telemetry)

Posted by the repo PR review workflow. Re-runs on each push to the PR.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 27e5432. Configure here.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Code health

Quality score: 49.2/100

Higher is better. The score is a trend dashboard; the independent ratchet below remains the CI gate.

Component Weight Current Change
Cyclomatic health 45% 52.2 +0.0
File concentration 25% 54.1 +0.5
Oversized-file debt 20% 29.5 +0.2
Modularity 10% 62.5 +0.1

Change vs PR base: +0.2 points.

Metric Value
Production LOC 241,312
Production files 532
Test LOC 70,084
Functions measured 15,083
Functions complexity ≥ 15 784
Maximum complexity 667

Markdown, JSON catalogs and tests are out of this table. Only app/ runtime + ui/src TS/JS count.

Most complex functions

Complexity Where
667 app/wgp.py:7164 generate_video
374 ui/src/stores/useStore.ts:4021 Async method 'startGeneration'
355 app/_launch_runtime.py:23472 _run_generation
308 app/wgp.py:12281 generate_video_tab
271 ui/src/components/Sidebar/SceneAnimatorPanel.tsx:474 Function 'SceneAnimatorPanel'
266 ui/src/stores/useStore.ts:8563 Async method 'loadSettingsFromOutput'
258 app/services/director/planners/short_film.py:3433 ShortFilmPlanner._plan_story_driven
248 app/services/director_pipeline.py:13735 _run_video_generation
245 app/services/director_pipeline.py:7860 _run_pipeline
243 ui/src/features/agent/agentActions.ts:1109 Function 'parseAction'
226 app/services/director_pipeline.py:6689 update_comic_preview
225 ui/src/features/agent/agentActions.ts:2766 Async function 'executeAgentActions'

Trend vs baseline

Metric Δ
Production LOC +56
Test LOC +90
Functions ≥ 15 +0
Maximum complexity +0

Warnings

  • production LOC increased by +56

Ratchet passed.

@IAnMove

IAnMove commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

@cursor review after complexity split

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Image upscale fails on start
    • Removed the extra job=None argument so the image-path lambda no longer forwards job twice into update_job.

Create PR

Or push these changes by commenting:

@cursor push a1f397b3f8
Preview (a1f397b3f8)
diff --git a/app/services/tools_upscale.py b/app/services/tools_upscale.py
--- a/app/services/tools_upscale.py
+++ b/app/services/tools_upscale.py
@@ -98,7 +98,7 @@
 def _upscale_image_job(
     *, source_path, out_dir, source_filename, method, params, wgp, abort, progress, update_job
 ):
-    if not update_job(job=None, message="Upscaling image...", phase="Upscaling", progress=5):
+    if not update_job(message="Upscaling image...", phase="Upscaling", progress=5):
         return None, None
     final_path = wgp.get_available_filename(
         out_dir, source_filename, "_upscaled", force_extension=".png"

You can send follow-ups to the cloud agent here.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 82a71cb. Configure here.

Comment thread app/services/tools_upscale.py Outdated
def _upscale_image_job(
*, source_path, out_dir, source_filename, method, params, wgp, abort, progress, update_job
):
if not update_job(job=None, message="Upscaling image...", phase="Upscaling", progress=5):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image upscale fails on start

High Severity

_upscale_image_job calls update_job with job=None, but the image path already binds the real job in a lambda. That forwards job twice into the lifecycle helper, so still-image upscales raise TypeError immediately and never start processing.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 82a71cb. Configure here.

The image helper already receives a lambda that binds the live job. Passing
job=None forwarded the argument twice into update_job and raised TypeError
before any still-image processing started.

Co-authored-by: THEINAOG <IAnMove@users.noreply.github.com>
@IAnMove
IAnMove merged commit 08993d5 into main Sep 4, 2026
4 checks passed
@IAnMove
IAnMove deleted the feat/extract-tools-upscale branch September 5, 2026 11:52
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.

2 participants