Skip to content

Fix uncaught NetworkX exceptions in TrackletStitcher.stitch() fallback - #3418

Open
deruyter92 wants to merge 1 commit into
mainfrom
jaap/fix_tracklet_stitcher_exception_guard
Open

Fix uncaught NetworkX exceptions in TrackletStitcher.stitch() fallback#3418
deruyter92 wants to merge 1 commit into
mainfrom
jaap/fix_tracklet_stitcher_exception_guard

Conversation

@deruyter92

Copy link
Copy Markdown
Collaborator

Summary

  • TrackletStitcher.stitch() crashes with ValueError: Could not reconstruct N tracks when the fallback ("black magic") path encounters infeasible flow problems, discarding all stitching work and leaving users with no .h5/.csv output after a completed detection run.
  • The root cause is two uncaught networkx exceptions inside the except NetworkXUnfeasible handler, which prevent self.paths from ever being set.

Reported by: image.sc forum — user analyzing 4 visually similar mice in 1-hour videos at 60fps.

Fix

Wrap both exception sources in try/except (matching the existing design intent):

  • node_disjoint_paths → catch NetworkXNoPath, warn, continue with any paths already found.
  • Second capacity_scaling → catch NetworkXUnfeasible, warn, keep existing paths.

When the minimum-cost flow problem is infeasible, the "black magic"
fallback path in stitch() calls `node_disjoint_paths` and a second
`capacity_scaling`, both of which could raise uncaught exceptions
(`NetworkXNoPath` and `NetworkXUnfeasible`), preventing `self.paths`
from being set and causing the finally block to re-raise as a fatal
ValueError.

This left users with only the raw pickle file and no .h5/.csv output
after a multi-hour detection run, with no actionable error message.

Fix: wrap both calls in try/except, warn, and continue with any
partial paths already found — matching the existing design intent
where line 731 already warned when `len(paths) != n_tracks`.
@deruyter92
deruyter92 requested review from AlexEMG and MMathisLab July 28, 2026 18:08
@deruyter92 deruyter92 added the bug fix! fix for a real buggy one... label Jul 28, 2026
@deruyter92
deruyter92 requested a review from C-Achard August 10, 2026 06:29

@C-Achard C-Achard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, thanks!

@C-Achard C-Achard added this to the v3.0.2 milestone Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix! fix for a real buggy one...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants