Skip to content

Improve async translation trigger after transcription#16

Open
mandira15 wants to merge 2 commits intosusiai:masterfrom
mandira15:improve-translation-trigger
Open

Improve async translation trigger after transcription#16
mandira15 wants to merge 2 commits intosusiai:masterfrom
mandira15:improve-translation-trigger

Conversation

@mandira15
Copy link
Copy Markdown

This pull request improves the translation workflow by triggering translation asynchronously immediately after a transcript is generated. Previously, translation was triggered indirectly and could be delayed depending on transcript queue processing. With this change, translation is started in a separate background thread right after transcription, ensuring faster and more reliable translation handling.

The update ensures that translation is only triggered when a valid translate_to language is provided and avoids duplicate translation by checking the existing translation status. The use of a daemon thread ensures non-blocking execution and maintains the responsiveness of the transcription pipeline.

Motivation and Context

The existing implementation delayed translation until older transcript chunks were processed or relied on indirect triggers. This caused inconsistent translation timing and affected real-time interpretation performance.

This change improves real-time responsiveness by:

• Triggering translation immediately after transcription
• Ensuring non-blocking execution using asynchronous threading
• Preventing duplicate translation using proper checks

This is especially important for live interpretation use cases where low latency is critical.

How Has This Been Tested?

This change was tested locally using the SUSI Translator Django development server.

Testing steps performed:

• Started Django server using python manage.py runserver
• Sent POST request to /api/transcribe endpoint via Swagger UI
• Verified transcription pipeline execution
• Confirmed translation trigger occurs asynchronously
• Ensured no crashes, blocking, or duplicate translations

The system continues to process transcription and translation without affecting existing functionality.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactor or cleanup (changes to existing code for improved readability or performance)

Checklist:

  • I adapted the version number under py/visdom/VERSION according to Semantic Versioning
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@mandira15
Copy link
Copy Markdown
Author

I am a first time contributor , please give me feedbacks for further improvement and learning.

@mariobehling mariobehling requested a review from Copilot April 21, 2026 22:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Triggers translation asynchronously immediately after transcription to reduce latency for live interpretation and avoid delayed/indirect translation starts.

Changes:

  • Start a background thread to run process_translation() right after a transcript is produced.
  • Gate translation trigger on translate_to being present and transcript_event["translated"] not being set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +220 to +226
# Trigger translation asynchronously after transcription
if translate_to and not transcript_event.get("translated", False):
threading.Thread(
target=process_translation,
args=(transcript_event,),
daemon=True
).start()
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Starting a brand-new threading.Thread per transcript can lead to unbounded thread creation under load (e.g., many chunks/users), increasing context switching and memory usage. Prefer a bounded concurrency mechanism such as a shared ThreadPoolExecutor (or the project’s existing background job system, e.g., Celery/RQ) to cap parallelism and improve operational stability.

Copilot uses AI. Check for mistakes.
Comment on lines +221 to +226
if translate_to and not transcript_event.get("translated", False):
threading.Thread(
target=process_translation,
args=(transcript_event,),
daemon=True
).start()
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

The background thread receives transcript_event by reference. If the main thread continues to mutate transcript_event (or reuses it) after starting the thread, process_translation() may observe inconsistent state or race with updates like translated. Consider passing an immutable payload (or a shallow/deep copy of the needed fields) and using a synchronization/atomic mechanism for the translated status to prevent duplicate or inconsistent translations.

Copilot uses AI. Check for mistakes.
threading.Thread(
target=process_translation,
args=(transcript_event,),
daemon=True
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Daemon threads can be terminated abruptly during worker shutdown/reload (e.g., Django dev server autoreload, gunicorn worker restart), which may leave translations incomplete without retries. If translation completion is important, use non-daemon execution with a graceful shutdown strategy, or (preferably) a durable background job queue so work survives process restarts.

Copilot uses AI. Check for mistakes.
@mandira15
Copy link
Copy Markdown
Author

Thanks for the detailed feedback!

You're right about the potential issues with unbounded thread creation and shared mutable state. I initially chose threading for simplicity and low-latency triggering, but I see how this can impact scalability under load.

I'll refactor this to use a bounded ThreadPoolExecutor and pass an immutable copy of transcript_event to avoid race conditions. Also exploring integration with a more robust background job system if needed.

I'll surely improve this at the earliest.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants