Skip to content

fix(api_v1): keep positive subtitle cue duration after millisecond rounding (#1466) - #1467

Open
Koushik-Katkam wants to merge 2 commits into
fossasia:devfrom
Koushik-Katkam:fix/1466-subtitle-cue-duration
Open

Koushik-Katkam wants to merge 2 commits into
fossasia:devfrom
Koushik-Katkam:fix/1466-subtitle-cue-duration

Conversation

@Koushik-Katkam

@Koushik-Katkam Koushik-Katkam commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes a bug in GET /api/v1/events/{event_slug}/rooms/{room_id}/booths/{language_code}/transcripts/export where WebVTT and SRT exports could emit zero-duration subtitle cues (00:00:00.000 --> 00:00:00.000 / 00:00:00,000 --> 00:00:00,000) whenever consecutive transcript segments have elapsed offsets that round to the same millisecond.

Root Cause

  • Previously, _to_vtt() and _to_srt() in portal/routers/api_v1.py computed start_sec and end_sec = min(start_sec + 5.0, next_start_sec) as floats and passed them independently to _format_playback_time(seconds, sep).
  • When two consecutive timestamps rounded to the same integer millisecond (for example, 0 µs and 100 µs, or cross-boundary offsets like 600 µs and 1400 µs that are 800 µs apart yet both round to 1 ms), both cue endpoints formatted identically.

Related Issue

Closes #1466

Changes Made

  • portal/routers/api_v1.py:
    • Extract shared _subtitle_timestamps(created_at, next_created_at, origin_utc, sep) for _to_vtt() and _to_srt().
    • Round start_ms = round(start * 1000) and enforce end_ms = max(start_ms + 1, round(end * 1000)).
    • Update _format_playback_time(total_ms: int, sep: str) to format integer milliseconds directly (checked all repo callers: only _to_vtt and _to_srt call _format_playback_time).
  • tests/test_api_v1_transcription.py:
    • Add test_export_subtitle_cues_keep_positive_duration_after_rounding covering both vtt and srt (0 µs & 100 µs).
    • Add test_export_subtitle_cues_same_rounded_ms_and_hour_rollover covering segments 800 µs apart (600 µs & 1400 µs) that round to the same 1 ms, ordering, and hour-boundary rollover (3599.9999 s -> 01:00:00.000).

Testing

  • Tested locally
  • Existing tests pass
  • Added/updated tests

Checks run on Windows 11 (Python 3.13.15):

  • ruff check .: passed (All checks passed!)
  • ruff format --check portal/routers/api_v1.py tests/test_api_v1_transcription.py: passed (2 files already formatted)
  • Before fix (origin/dev @ 164f059): pytest -q tests/test_api_v1_transcription.py → 3 failed, 36 passed
  • After fix:
    • pytest -q tests/test_api_v1_transcription.py → 39 passed
    • pytest tests/test_api_v1_transcription.py tests/test_roles.py tests/test_booth_recovery.py tests/test_transcription_concurrency.py -q → 157 passed

Screenshots (if applicable)

voxbento-1466-before-after.mp4

Genuine terminal/HTTP API before-and-after screencast recorded locally at voxbento-1466-before-after.mp4 (uploading via GitHub web UI / PR comment).

Checklist

  • My code follows the project's coding standards
  • I have tested my changes
  • I have updated documentation where necessary
  • My changes do not introduce new warnings or errors

Additional Notes

  • Minimum-duration overlap trade-off: When consecutive cues round to the same millisecond, only the earlier cue's end_ms is clamped to start_ms + 1, so cue i (00:00:00.000 --> 00:00:00.001) overlaps cue i + 1 (00:00:00.000 --> 00:00:05.000) by 1 ms. Both W3C WebVTT (end > start required; overlapping cue intervals allowed) and SRT permit overlapping cues, and avoiding adjustments to cue i + 1's start time prevents cascading timestamp drift on later subtitles relative to audio playback. All segments separated by >= 1 ms after rounding remain non-overlapping.
  • Independent of PR fix(booth): restart transcription worker when rejoining live after portal restart (#1453) #1463 (fix/1453-restart-booth-transcription).

Created with ChatGPT and Gemini 4 Hydrogen in Antigravity.

Summary by Sourcery

Keep exported subtitle cues valid when adjacent transcript timestamps resolve to the same millisecond.

Bug Fixes:

  • Ensure WebVTT and SRT subtitle cues retain a positive duration when their timestamps round to the same millisecond.

Tests:

  • Add coverage for sub-millisecond cue spacing, timestamp ordering, and hour-boundary formatting in both subtitle export formats.

Summary by CodeRabbit

  • Bug Fixes
    • Improved subtitle exports so closely spaced cues retain a positive duration and appear in the correct order.
    • Improved timestamp formatting for VTT and SRT subtitles, including timestamps that cross an hour boundary.

…unding

Compute integer millisecond cue boundaries once in _subtitle_timestamps() for both _to_vtt() and _to_srt(), ensuring every cue retains at least 1 ms duration (end_ms = max(start_ms + 1, round(end * 1000))) while preserving text, ordering, hour rollovers, and >= 1 ms non-overlapping intervals.

Closes fossasia#1466
Copilot AI balanced review requested due to automatic review settings December 3, 2026 10:17

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@sourcery-ai

sourcery-ai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implementation

Format subtitle timestamps from integer milliseconds and share cue-boundary calculation across VTT and SRT, enforcing at least a 1 ms duration.

  • portal/routers/api_v1.py L1250-1264 (+3 small edits)

Tests

Cover positive cue durations when timestamps round to the same millisecond, including ordering and hour rollover.

  • tests/test_api_v1_transcription.py L488-531

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

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 60772efe-62ca-4144-aab5-9412a328b3e9
Commits

Reviewing files that changed from the base of the PR and between 08a0054 and 14ee086.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

VTT and SRT subtitle exports now calculate cue timestamps in integer milliseconds. Cue ends are kept at least one millisecond after cue starts. Tests cover close timestamps, cue ordering, and formatting at the hour boundary.

Changes: Subtitle Cue Timing

Layer / File(s) Summary
Shared cue timing and export validation
portal/routers/api_v1.py, tests/test_api_v1_transcription.py
A shared helper calculates cue timestamps and ensures each cue has a positive duration. VTT and SRT use the helper with their respective separators. Tests cover close timestamps and hour rollover.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • fossasia/voxbento#979: Adds stored-segment transcript export in WebVTT and SRT, which this change continues.

Suggested labels: ai-assisted

Suggested reviewers: vineetramshetty, arnavballincode

Merge Risk: Minimal · previous review 08a00

VTT and SRT exports now produce cues with a positive duration when timestamps round to the same millisecond. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (keeping positive subtitle cue duration after millisecond rounding) in the api_v1 router, which matches the PR objectives: enforcing end_ms = max(start_ms + 1, round(end * 1000…
Linked Issues check Passed [#1466] The linked issue requires every WebVTT and SRT cue to have end_ms >= start_ms + 1. It also requires keeping text, ordering, the existing <= 5 s timing for segments at least 1 ms apart, and cle…
Out of Scope Changes check Passed The PR changes two files: portal/routers/api_v1.py and tests/test_api_v1_transcription.py. Per the summary, the api_v1.py changes are limited to the subtitle timestamp path: the new _subtitle_timestam…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the fix (keeping positive subtitle cue duration after millisecond rounding) in the api_v1 router, which matches the PR objectives: enforcing end_ms = max(start_ms + 1, round(end * 1000)) for WebVTT and SRT exports. It also names the issue number #1466, which is consistent with the linked issue. The title is 83 characters, slightly long, but it is specific and accurate.

Full details: Linked Issues check

Explanation

[#1466] The linked issue requires every WebVTT and SRT cue to have end_ms >= start_ms + 1. It also requires keeping text, ordering, the existing <= 5 s timing for segments at least 1 ms apart, and clean hour rollovers. It also requires the earlier cue's end to move by 1 ms, while the next cue keeps its own start.

The whole-PR summary and PR description state these changes in portal/routers/api_v1.py:

  • A shared _subtitle_timestamps() helper serves _to_vtt() and _to_srt().
  • Cue boundaries are rounded to integer milliseconds once: start_ms = round(start * 1000), and end_ms = max(start_ms + 1, round(end * 1000)).
  • _format_playback_time() takes integer milliseconds. The PR states that only _to_vtt and _to_srt call it.

The end_ms rule enforces the minimum 1 ms duration. Only the earlier cue's end is clamped, so the next cue's start is unchanged. This matches the issue's expected behavior. The PR also adds tests in tests/test_api_v1_transcription.py for both formats, for same-rounded-millisecond segments (0 µs and 100 µs; 600 µs and 1400 µs), and for the 3599.9999 s hour rollover.

Limitation: the read tool truncated both files before the subtitle functions and the new tests. I confirmed the changed code only through the PR summary and description, not by reading the lines directly. The author also reports the test results (39 passed in the transcription test file).

Full details: Out of Scope Changes check

Explanation

The PR changes two files: portal/routers/api_v1.py and tests/test_api_v1_transcription.py. Per the summary, the api_v1.py changes are limited to the subtitle timestamp path: the new _subtitle_timestamps() helper, the rounding rule, and the _format_playback_time() signature. The test changes cover only the subtitle cue cases in #1466. The PR description also mentions a before-and-after video and a note about PR #1463. Neither adds code to this diff. The summary reports no unrelated edits. Changes in the summary do not show any change outside the issue's scope.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 32b11ddf-6bdc-406f-b1ed-59ab0dba6d7b
Commits

Reviewing files that changed from the base of the PR and between 164f059 and 08a0054.

Files selected for processing: 2

  • portal/routers/api_v1.py
  • tests/test_api_v1_transcription.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@sourcery-ai

sourcery-ai Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit 08a0054

#1466 bug(api_v1): VTT and SRT transcript export can emit zero-duration subtitle cues when consecutive timestamps round to the same millisecond · 3 of 3 met

# Requirement Status Notes
1 Every WebVTT and SRT cue has a positive duration of at least 1 ms when consecutive timestamps round to the same millisecond. ✅ Met The shared _subtitle_timestamps() helper clamps each end to at least start_ms + 1 and is used by both serializers.
2 Preserve transcript text and ordering, non-overlapping timing for segments at least 1 ms apart, and clean hour rollovers. ✅ Met The serializers retain their text and iteration order; the shared helper preserves the 5-second cap and integer-millisecond formatting handles hour rollovers.
3 For cues that round to the same millisecond, keep the next cue at its own rounded start and bump only the earlier cue's end. ✅ Met The helper adjusts only end_ms; each cue's start is independently rounded from its own timestamp.

@sourcery-ai sourcery-ai 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.

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

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Copilot AI balanced review requested due to automatic review settings December 4, 2026 04:54

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted PR created or assisted with an AI coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(api_v1): VTT and SRT transcript export can emit zero-duration subtitle cues when consecutive timestamps round to the same millisecond

3 participants