Skip to content

Revert PR #5272: translate API optimization - #5383

Merged
beastoin merged 1 commit into
mainfrom
revert-pr-5272
Mar 5, 2026
Merged

beastoin merged 1 commit into
mainfrom
revert-pr-5272

Conversation

@beastoin

@beastoin beastoin commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

What's reverted

  • Translate API cost optimization (detect_language elimination, debounce, Redis cache, batch calls)
  • 66 unit tests in test_translation_optimization.py

Code is preserved on the original branch for re-merge when approved.

by AI for @beastoin

…he, batch + debounce (#5272)"

This reverts commit 8a0c075, reversing
changes made to c972ba6.
@beastoin
beastoin merged commit 96da1b0 into main Mar 5, 2026
2 checks passed
@beastoin
beastoin deleted the revert-pr-5272 branch March 5, 2026 13:44
@greptile-apps

greptile-apps Bot commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR reverts merge commit 8a0c075e7 (PR #5272) which introduced translate API cost optimizations (debounce, Redis cache, batch calls, detect_language elimination) because it was merged without explicit manager approval. The revert restores the simpler synchronous translate() closure in _stream_handler, the original TranslationService / TranscriptSegmentLanguageCache utilities, and removes the 66-test test_translation_optimization.py suite.

Key findings:

  • Logic bug re-introduced (line 1275, transcribe.py): The restored translate() function searches for an existing translation entry using t.lang == language (the STT input/speech language) instead of t.lang == translation_language (the translation target language). These diverge whenever user_language_preference is set (line 214), causing the update path to be silently skipped and duplicate translation objects to accumulate on a segment with every call.
  • The 66 optimization-focused unit tests are intentionally removed along with the feature; the test runner (test.sh) is updated accordingly.
  • translation.py and translation_cache.py are correctly restored to their pre-PR perf(translate): eliminate redundant API calls, add Redis cache, batch + debounce #5272 state with no new concerns.

Confidence Score: 3/5

  • Safe to merge as a process-driven revert, but re-introduces a pre-existing logic bug in translation deduplication that should be fixed before or shortly after merge.
  • The revert itself is mechanically correct and achieves its stated goal. However, it re-introduces a bug (line 1275: t.lang == language instead of t.lang == translation_language) that causes duplicate translation entries to accumulate on segments for users with a language preference set. This bug was present before PR perf(translate): eliminate redundant API calls, add Redis cache, batch + debounce #5272, but since PR perf(translate): eliminate redundant API calls, add Redis cache, batch + debounce #5272 fixed it implicitly by rewriting that section, the revert brings it back. The rest of the restored code (translation.py, translation_cache.py) is clean.
  • backend/routers/transcribe.py — line 1275 has the language vs translation_language mismatch.

Sequence Diagram

sequenceDiagram
    participant WS as WebSocket Handler
    participant TR as translate()
    participant LC as TranscriptSegmentLanguageCache
    participant TS as TranslationService
    participant GC as Google Cloud Translate
    participant DB as conversations_db

    WS->>TR: translate(segments, conversation_id)
    loop for each segment
        TR->>LC: is_in_target_language(segment.id, text, translation_language)
        LC-->>TR: true (skip) / false (translate)
        alt needs translation
            TR->>TS: translate_text_by_sentence(translation_language, text)
            TS->>GC: translate_text(contents, target_language_code)
            GC-->>TS: translated_text
            TS-->>TR: translated_text
            TR->>TR: build Translation(lang=translation_language, text=...)
            TR->>TR: update segment.translations
        end
    end
    TR->>DB: get_conversation / update_conversation_segments
    TR->>WS: _send_message_event(TranslationEvent)
Loading

Last reviewed commit: b9425ce

translation = Translation(lang=translation_language, text=translated_text)
if segment.translations is not None:
existing_translation_index = next(
(i for i, t in enumerate(segment.translations) if t.lang == language), None

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.

Wrong variable used when matching existing translations

This line uses language (the STT input/speech language, e.g. "multi" or "en") to look for an existing translation entry, but translations are stored with lang=translation_language (the target/output language, e.g. "fr" from user preferences) on line 1272.

When translation_language != language — specifically when user_language_preference is set at line 214 — this lookup will never find an existing entry and will always fall through to segment.translations.append(translation). Over repeated calls, this causes duplicate translation entries to accumulate on the same segment for the same target language.

Suggested change
(i for i, t in enumerate(segment.translations) if t.lang == language), None
(i for i, t in enumerate(segment.translations) if t.lang == translation_language), None

Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
…re#5383)

## Summary
- Reverts merge commit 8a0c075 (PR BasedHardware#5272) per manager request
- PR was merged without explicit manager approval, violating team
process

## What's reverted
- Translate API cost optimization (detect_language elimination,
debounce, Redis cache, batch calls)
- 66 unit tests in `test_translation_optimization.py`

Code is preserved on the original branch for re-merge when approved.

_by AI for @beastoin_
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