fix: resolve 4 bugs found via code audit - #1753
Open
sjhddh wants to merge 1 commit into
Open
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes four audited bugs in the face swapper and UI modules: corrects the face swapper model path and a wrong-arity face selection call, and ensures proper logging import and video capture cleanup in the UI preview flow. Sequence diagram for face swapper model pre_check and pre_start flowsequenceDiagram
participant App
participant FaceSwapper as face_swapper_module
participant FileSystem
App->>FaceSwapper: pre_check()
FaceSwapper->>FileSystem: ensure models_dir exists
alt models_dir creation fails
FileSystem-->>FaceSwapper: OSError
FaceSwapper->>FaceSwapper: logging.error(error)
FaceSwapper-->>App: False
else models_dir ok
FileSystem-->>FaceSwapper: ok
FaceSwapper-->>App: True
end
App->>FaceSwapper: pre_start()
FaceSwapper->>FaceSwapper: model_path = join(models_dir, inswapper_128.onnx)
FaceSwapper->>FileSystem: exists(model_path)
alt model file exists
FileSystem-->>FaceSwapper: True
FaceSwapper-->>App: True
else model file missing
FileSystem-->>FaceSwapper: False
FaceSwapper->>FaceSwapper: update_status(Model not found: inswapper_128.onnx)
FaceSwapper-->>App: False
end
Sequence diagram for render_video_preview VideoCapture lifecyclesequenceDiagram
actor User
participant UI as ui_module
participant CV2 as cv2_VideoCapture
User->>UI: render_video_preview(video_path, size)
UI->>CV2: VideoCapture(video_path)
UI->>CV2: read()
alt frame read successful
CV2-->>UI: ret=True, frame
UI->>UI: gpu_cvt_color(frame)
UI->>UI: Image.fromarray(...)
alt size provided
UI->>UI: ImageOps.fit(image, size, LANCZOS)
end
UI->>CV2: release()
UI-->>User: CTkImage
else frame read failed
CV2-->>UI: ret=False, None
UI->>CV2: release()
UI->>UI: cv2.destroyAllWindows()
UI-->>User: None or error image
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
render_video_preview, consider wrappingcv2.VideoCaptureusage in a context manager or a try/finally block so the capture is reliably released even if an exception occurs between opening the stream and returning the image. - The fallback face selection now uses
min(detected_faces, key=lambda x: x.bbox[0]); ifget_one_faceencodes the canonical selection heuristic, it may be better to reuse or refactor that logic so face-selection behavior stays consistent in one place and does not rely on assumptions aboutbbox.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `render_video_preview`, consider wrapping `cv2.VideoCapture` usage in a context manager or a try/finally block so the capture is reliably released even if an exception occurs between opening the stream and returning the image.
- The fallback face selection now uses `min(detected_faces, key=lambda x: x.bbox[0])`; if `get_one_face` encodes the canonical selection heuristic, it may be better to reuse or refactor that logic so face-selection behavior stays consistent in one place and does not rely on assumptions about `bbox`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
1. Add missing `import logging` in face_swapper.py (NameError on dir creation failure) 2. Fix model filename mismatch: pre_start() checked for inswapper_128_fp16.onnx but pre_check() downloads inswapper_128.onnx 3. Fix VideoCapture resource leak in ui.py render_video_preview() — release on success path 4. Fix get_one_face() wrong arity in map_faces fallback — use already-detected faces directly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sjhddh
force-pushed
the
fix/multiple-bug-fixes
branch
from
June 3, 2026 16:37
1c49cff to
2a80029
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes four bugs discovered during a code audit of the face swapper and UI modules:
1. Missing
loggingimport (face_swapper.py)logging.error()is called inpre_check()butloggingwas never importedNameErrorwhen model directory creation fails2. Model filename mismatch (
face_swapper.py)pre_check()downloadsinswapper_128.onnx(FP32)get_face_swapper()loadsinswapper_128.onnx(FP32)pre_start()checks forinswapper_128_fp16.onnx— a file that is never downloadedpre_start()to always fail with "Model not found"3. VideoCapture resource leak (
ui.py)render_video_preview()only callscapture.release()on the failure path4.
get_one_face()called with wrong arity (face_swapper.py)(processed_frame, detected_faces)butget_one_face()only accepts oneTypeErrorat runtime in the map_faces fallback pathTest plan
pre_check()handles directory creation errors without NameErrorpre_start()finds the correct model file afterpre_check()downloads itlsofduring preview)🤖 Generated with Claude Code
Summary by Sourcery
Fix bugs in the face swapper model handling and face selection logic, and ensure video preview resources are correctly released.
Bug Fixes: