Skip to content

fix(transcription): keep booth caption sequences across handovers so translations don't stop (#1365) - #1433

Merged
ArnavBallinCode merged 2 commits into
fossasia:devfrom
ArnavBallinCode:fix/booth-caption-seq-1365
Dec 1, 2026
Merged

ArnavBallinCode merged 2 commits into
fossasia:devfrom
ArnavBallinCode:fix/booth-caption-seq-1365

Conversation

@ArnavBallinCode

@ArnavBallinCode ArnavBallinCode commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Description

After an interpreter handover or reconnect, translated speech stopped for listeners on that booth. Each CaptionAggregator numbered booth captions from its own in-memory _seq_counter, so every new worker (handover, WHIP reconnect, provider retry, portal restart) started again at seq 1. The listener drops anything below the seq it expects next, so all later booth translations were discarded. Floor captions were already fixed in #1062 with the stored Room.floor_caption_seq; booths were not.

This PR uses the same approach for booths, as agreed in the issue thread. Each booth stores its own counter in a new booths.caption_seq column (migration 051). Final booth captions allocate the next value atomically with UPDATE ... RETURNING, which works on SQLite and Postgres. A per-booth lock keeps allocation and broadcast in order while an old and a new aggregator overlap during a handover. Failure handling matches the floor: if the database fails, the original text still goes out without a seq (and skips storage, translation and TTS), and pending finals for a deleted booth are dropped. Aggregators with no room (the home-page live demo) keep the in-memory counter. The listener's stale-sequence check is unchanged.

Related Issue

Closes #1365

Changes Made

  • portal/transcription/aggregator.py: booth finals allocate seq from DBBooth.caption_seq under booth_caption_lock(booth_id). The floor path (_allocate_floor_sequence, floor_caption_lock) is unchanged.
  • portal/models.py + alembic/versions/051_add_booth_caption_seq.py: add booths.caption_seq (Integer, not null, default 0).
  • tests/test_booth_caption_sequences.py: regression tests for handover, reconnect and restart continuity, resuming from a stored counter, booth and floor counters staying independent, concurrent aggregators, DB outage then recovery, deleted booths, and room-less streams.
  • Docs: TRANSCRIPTION_MAP.md, DATABASE_MAP.md, the agents.md migration count, and the seq field description in website/docs/api/websocket/captions.mdx.

Testing

  • uv run pytest tests/test_booth_caption_sequences.py -q on upstream/dev with only the model column added: 6 failed, 1 passed. The handover test gets [1, 2, 1, 1] instead of [1, 2, 3, 4].
  • Same command with the fix: 7 passed (run 3 times).
  • uv run pytest tests/test_booth_caption_sequences.py tests/test_floor_caption_sequences.py tests/test_caption_aggregator.py tests/test_aggregator_chunk.py tests/test_deepgram_pipeline.py tests/test_youtube_caption_hooks.py tests/test_program_ingest.py -q: 98 passed
  • uv run pytest tests/ -q: 3706 passed, 17 skipped
  • uv run ruff check .: All checks passed
  • DATABASE_URL=sqlite+aiosqlite:///$PWD/mig.db uv run alembic upgrade head && uv run alembic downgrade -1 && uv run alembic upgrade head: succeeded. The booths indexes and FKs are intact after the round trip.

Proof: a booth aggregator is recreated three times (handover, then a DB reconnect standing in for a restart), and seq keeps rising 1→4. Each caption gets its own transcript row and its own translation seq.

  • Tested locally
  • Existing tests pass
  • Added/updated tests (if applicable)

Screenshots (if applicable)

Not needed. This is a server-side change with no UI.

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

Created with GitHub Copilot (Copilot SDK) in VS Code.

Created with GitHub Copilot.

Summary by CodeRabbit

  • Improvements
    • Final captions now have sequence numbers that persist across interpreter handovers, reconnects, and portal restarts.
    • Interpreter booths maintain independent sequences, separate from floor captions.
    • If a sequence number cannot be allocated, the caption can still be delivered without a sequence; it won’t be translated.
  • Documentation
    • Clarified how caption sequence numbers work and when they may be unavailable.

…ssasia#1365)

Interpreter booth captions took seq from a counter inside each
CaptionAggregator, so every handover, WHIP reconnect or restart started
again at 1. Listeners drop seq below the one they expect, so translated
speech stopped after the first handover.

Store the counter on the booth (booths.caption_seq, migration 051) and
allocate it atomically with UPDATE ... RETURNING, like
Room.floor_caption_seq from fossasia#1062. A per-booth lock keeps allocation and
broadcast in order when an old and new aggregator overlap. Database
failures publish text without a seq, and deleted booths drop pending
finals, matching the floor. Room-less aggregators (home-page demo) keep
the in-memory counter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 18:48

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.

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 Nov 30, 2026

Copy link
Copy Markdown
Contributor

Sorry @ArnavBallinCode, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 20 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

Interpreter-booth captions now use a database-backed sequence counter that persists across stream connections. Finalization uses a per-booth lock, and tests cover allocation, failure, deletion, and roomless streams.

Changes: Booth caption sequence persistence

Layer / File(s) Summary
Persist the booth sequence counter
portal/models.py, alembic/versions/053_add_booth_caption_seq.py, .agents/context/DATABASE_MAP.md, agents.md
DBBooth gains a caption_seq integer field with a default of 0. Migration 053 adds the non-null database column and its downgrade removes it. The database map and migration inventory document the schema change.
Allocate sequences during caption finalization
portal/transcription/aggregator.py, tests/test_booth_caption_sequences.py, .agents/context/TRANSCRIPTION_MAP.md, website/docs/api/websocket/captions.mdx
Room-backed booth captions use a shared per-booth lock and database counter. Floor captions retain their room counter, while roomless streams use local numbering. Tests cover sequence persistence, independent counters, ordering, database errors, and deleted booths. The documentation describes sequence scope and when seq is omitted.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CaptionAggregator
  participant booth_caption_lock
  participant DBBooth
  participant FinalCallback
  CaptionAggregator->>booth_caption_lock: Get shared lock for booth_id
  CaptionAggregator->>DBBooth: Increment caption_seq for matching booth
  DBBooth-->>CaptionAggregator: Return allocated sequence
  CaptionAggregator->>FinalCallback: Publish final caption with sequence
Loading

Possibly related PRs

  • fossasia/voxbento#1434: This PR shares the Alembic revision chain with #1433; migration ordering and revision IDs are related.

Suggested reviewers: manojlamani, nirupon123

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix area (transcription) and the core change (keeping booth caption sequences across handovers), which matches the changeset: a persistent per-booth caption_seq column (migration 0…
Linked Issues check Passed [#1365] The core requirement is that booth caption seq keeps increasing across handovers, Stop/Go Live, and reconnects. The diff meets it. A new DBBooth.caption_seq column (migration 051, default 0)…
Out of Scope Changes check Passed All changed areas connect to #1365. aggregator.py changes add the booth allocation, booth lock, and stream selector that replaces the floor boolean. The floor allocation logic is unchanged. `portal/…
Full details: Title check

Explanation

The title names the fix area (transcription) and the core change (keeping booth caption sequences across handovers), which matches the changeset: a persistent per-booth caption_seq column (migration 051), a booth lock, and sequence allocation in the aggregator. It omits the database-backed counter and the failure handling, but it still identifies the primary change. The title also uses a conventional prefix and an issue reference. The stated goal of keeping translations flowing is what the linked objectives describe.

Full details: Linked Issues check

Explanation

[#1365] The core requirement is that booth caption seq keeps increasing across handovers, Stop/Go Live, and reconnects. The diff meets it. A new DBBooth.caption_seq column (migration 051, default 0) stores the counter. CaptionAggregator._allocate_booth_sequence allocates the next value with UPDATE ... RETURNING on the booth row. booth_caption_lock(booth_id) serializes allocation and publication across overlapping aggregators. The floor path (_allocate_floor_sequence, floor_caption_lock) is unchanged. On SQLAlchemyError, the original text is delivered without seq, matching the floor fallback. Regression tests in tests/test_booth_caption_sequences.py cover handover, reconnect, restart, concurrency, DB outage/recovery, deleted booths, and room-less streams. The PR author reports these tests fail without the fix and pass with it. The issue's proposed listener-side Node test (tests/test_listener_event.js) is not added. The listener code is unchanged, and the server-side sequence fix is the change that restores translation delivery, so this gap does not leave a server requirement unmet. The issue also asks for a seq jump-back guard on the listener; the issue poses this as an open question, not a requirement. Evidence is source diff and PR-reported test results. I did not run the tests.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #1365. aggregator.py changes add the booth allocation, booth lock, and stream selector that replaces the floor boolean. The floor allocation logic is unchanged. portal/models.py and migration 051 add the stored booth counter. The test file covers the booth requirements. Docs (TRANSCRIPTION_MAP.md, DATABASE_MAP.md, agents.md migration count, and captions.mdx seq description) describe the new behavior or the migration count. The room-less path keeps the in-memory counter, as the PR states. No unrelated change is evident in the reviewed diff. The #1358 and #1222/#1123 overlaps are noted in the PR description as related work and are not included in this diff.

  • 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: c43c2afc-c41b-4e34-87e4-ae8d5161d344
Commits

Reviewing files that changed from the base of the PR and between 595bf6d and 8c89774.

Files selected for processing: 8

  • .agents/context/DATABASE_MAP.md
  • .agents/context/TRANSCRIPTION_MAP.md
  • agents.md
  • alembic/versions/051_add_booth_caption_seq.py
  • portal/models.py
  • portal/transcription/aggregator.py
  • tests/test_booth_caption_sequences.py
  • website/docs/api/websocket/captions.mdx

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

@github-actions github-actions Bot added the ai-assisted PR created or assisted with an AI coding agent label Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @ArnavBallinCode, thanks for your contribution!

Before we can review this PR, please add a short screencast video showing the change working (before/after where relevant).

If no video is added within 72 hours, this PR will be closed automatically. You are welcome to reopen it or submit a new PR once you have the screencast.

@ArnavBallinCode

Copy link
Copy Markdown
Member Author

Note

🤖 Copilot SDK in VS Code responding on behalf of ArnavBallinCode

This PR has a migration-chain blocker: its 051_add_booth_caption_seq.py declares revision 051, which conflicts with #1434's 051_keep_transcripts_on_booth_delete.py (also carried by #1435). The current green migration check only validates against dev before the other migration lands. Merge #1434 first, then update this migration to a unique next revision chained from 051 and rerun CI; do not merge both unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 05:14

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.

@ArnavBallinCode

Copy link
Copy Markdown
Member Author

Note

🤖 Copilot SDK in VS Code responding on behalf of @ragini-angarkar

Merged current dev in 9314afb and resolved the conflicts. The caption-sequence migration is now 053, following 052 (the PR description above still refers to its original number 051). Verified the SQLite upgrade/downgrade/re-upgrade, 128 Python tests and 103 listener checks.

@ArnavBallinCode
ArnavBallinCode merged commit c1fb663 into fossasia:dev Dec 1, 2026
28 of 29 checks passed
@ArnavBallinCode
ArnavBallinCode deleted the fix/booth-caption-seq-1365 branch December 1, 2026 05:16
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 needs-screencast

Projects

None yet

2 participants