Skip to content

fix: handle pyannote legacy and pre-4.x diarization return types#191

Merged
NotYuSheng merged 5 commits into
mainfrom
fix/diarization-post-181
May 18, 2026
Merged

fix: handle pyannote legacy and pre-4.x diarization return types#191
NotYuSheng merged 5 commits into
mainfrom
fix/diarization-post-181

Conversation

@NotYuSheng

Copy link
Copy Markdown
Owner

Summary

  • diarization_service.py assumed pyannote 4.x always returns a DiarizeOutput object (accessing .speaker_diarization)
  • This breaks when legacy=True is set on the pipeline, or if someone runs with pyannote <4.0 (which returns an Annotation directly)
  • Added a hasattr guard to handle both return types gracefully

Root cause

pyannote 4.x SpeakerDiarization.apply() returns:

  • DiarizeOutput when legacy=False (default)
  • Annotation directly when legacy=True (backwards compat mode)

Test plan

  • Upload a file and confirm diarization completes with speaker labels
  • Confirm behaviour is unchanged from current pyannote 4.0.4 with legacy=False

🤖 Generated with Claude Code

NotYuSheng and others added 2 commits May 18, 2026 23:00
…urn types

pyannote 4.x returns DiarizeOutput (with .speaker_diarization) when legacy=False,
but returns Annotation directly when legacy=True or when using pyannote <4.0.
Guard with hasattr check so both paths work correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
pyannote>=4.0 is pinned in requirements.txt so legacy=True can never
occur in this codebase. The hasattr guard was dead code.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the diarization service to support both legacy and modern PyAnnote return types by conditionally accessing the speaker diarization attribute. The review feedback suggests improving the implementation's idiomaticity by using getattr and adding a safety check for None values to prevent potential runtime errors.

I am having trouble creating individual review comments. Click here to see my feedback.

backend/services/diarization_service.py (87-91)

medium

The current implementation uses a verbose ternary operator to handle the different return types from PyAnnote. Using getattr with a default value is more idiomatic in Python for this pattern. Additionally, adding an explicit check for None ensures the service handles cases where the pipeline might fail to return a result without raising a confusing AttributeError when itertracks is called later.

            if diarization is None:
                raise ValueError("Diarization pipeline returned no result")
            annotation = getattr(diarization, "speaker_diarization", diarization)

Badges now cap at 160px with text-overflow: ellipsis and a title
attribute for full name on hover. Container uses flex-wrap so multiple
badges wrap cleanly instead of overflowing the card.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@NotYuSheng

Copy link
Copy Markdown
Owner Author

/gemini review

Combine getSpeakerColor inline styles (from main) with the maxWidth
ellipsis truncation (from this branch).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates a comment in the backend diarization service and enhances the speaker badge UI in the frontend with flexbox layout and text truncation. Feedback highlights a missing logic implementation in the backend to handle different pyannote return types, which could cause an AttributeError. In the frontend, it is recommended to use the Bootstrap 'text-truncate' utility class instead of multiple inline styles for better maintainability.

Comment thread backend/services/diarization_service.py
Comment thread frontend/src/components/Transcript/MeetingInfoSidebar.jsx
Replace verbose inline overflow styles with Bootstrap text-truncate
utility class, keeping only maxWidth in the style prop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@NotYuSheng NotYuSheng merged commit c342271 into main May 18, 2026
1 check passed
@NotYuSheng NotYuSheng deleted the fix/diarization-post-181 branch May 18, 2026 15:11
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