Skip to content

Fix default target face handling for empty clusters#1767

Open
duyua9 wants to merge 1 commit intohacksider:mainfrom
duyua9:fix-default-target-face-empty-clusters
Open

Fix default target face handling for empty clusters#1767
duyua9 wants to merge 1 commit intohacksider:mainfrom
duyua9:fix-default-target-face-empty-clusters

Conversation

@duyua9
Copy link
Copy Markdown

@duyua9 duyua9 commented Apr 16, 2026

Summary

  • Skip target-face clusters that contain no detected faces instead of dereferencing None.
  • Add focused regression coverage for empty clusters and continued processing of later clusters.

Validation

  • python3 -m unittest tests/test_face_analyser_default_target.py
  • python3 -m py_compile modules/face_analyser.py tests/test_face_analyser_default_target.py
  • git diff --check
  • bash /Users/ming/.openclaw/skills/code-change-delivery-contract/scripts/scan_delivery_blockers.sh

Summary by Sourcery

Handle clusters without detected faces when selecting a default target face and add regression coverage for these scenarios.

Bug Fixes:

  • Avoid dereferencing missing face or frame data when a target-face cluster contains no detected faces.

Tests:

  • Add unit tests covering empty target-face clusters and continued processing of subsequent clusters when computing the default target face.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 16, 2026

Reviewer's Guide

Handles clusters with no detected faces in default_target_face without crashing and adds regression tests to verify skipping empty clusters while still processing subsequent ones.

Flow diagram for updated default_target_face empty-cluster handling

flowchart TD
    A[start_default_target_face] --> B["Initialize best_face and best_frame to None"]
    B --> C["For each cluster in clusters"]
    C --> D["For each frame in cluster"]
    D --> E["For each face in frame"]
    E --> F["Update best_face and best_frame if this face is better"]
    F --> G["Finished iterating faces in this cluster"]

    G --> H{best_face is None or best_frame is None?}
    H -->|Yes| I["continue to next cluster (skip empty cluster)"]
    I --> C
    H -->|No| J["Read target_frame from best_frame location with cv2.imread"]
    J --> K["Extract x_min, y_min, x_max, y_max from best_face bbox"]
    K --> L["Return chosen target frame and bounding box"]
Loading

File-Level Changes

Change Details Files
Avoid crashing when a target-face cluster has no detected faces by skipping clusters without a selected best face/frame.
  • After computing best_face and best_frame in the cluster loop, add a guard that continues to the next cluster if either best_face or best_frame is None
  • Leave the subsequent bounding-box extraction and cv2.imread logic unchanged so it only runs when a valid best_face/best_frame pair exists
modules/face_analyser.py
Add regression tests that exercise empty target-face clusters and ensure later clusters are still processed and assigned targets.
  • Introduce a dedicated test module that builds a fully stubbed environment for modules.face_analyser, including fake cv2, numpy, insightface, globals, cluster_analysis, utilities, typing, and tqdm
  • Test that default_target_face leaves clusters with no detected faces without adding a target entry
  • Test that clusters following an empty cluster still get their target selected based on highest det_score and that the returned cv2 crop indexes match the expected bbox-derived slices
tests/test_face_analyser_default_target.py

Possibly linked issues

  • #fix: default_target_face crashes with TypeError when no faces detected in any frame: PR adds a best_face/best_frame None-guard in default_target_face and tests, exactly fixing the reported crash.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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