Skip to content

fix: fall back when Grok returns no usable translation - #2585

Merged
dangeredwolf merged 2 commits into
FxEmbed:mainfrom
JTropy:fix/grok-empty-translation-fallback
Oct 28, 2026
Merged

dangeredwolf merged 2 commits into
FxEmbed:mainfrom
JTropy:fix/grok-empty-translation-fallback

Conversation

@JTropy

@JTropy JTropy commented Oct 12, 2026 •

Copy link
Copy Markdown

Grok can return a non-null response without usable result.text. The processor then publishes an empty translation, sets didTranslate = true, and skips the configured Polyglot/AI fallback. This also affects quoted posts.

Validate the response at the Grok helper boundary and return null for missing, non-string, empty, or whitespace-only text. Valid Grok responses are preserved. Existing fallback selection continues to handle rejected responses, and the helper logs a warning for the unusable result.

Observed on 2026-10-12: /status/2109439315570999598/zh returned a valid Grok body translation but an embedded quote translation with provider: "grok" and text: "". This patch fixes the false-success handling; it does not claim to fix the underlying X/Grok service failure or translate poll choices.

Validation:

  • Added 12 regression cases covering invalid responses, valid Grok translation, unavailable fallback, and a quote falling back while the outer Grok translation is retained.
  • Before the fix: 9 failed, 3 passed. After the fix: all 12 passed.
  • Full suite: 67 files, 430 tests passed.
  • npm run build:atmosphere and npm run build-local passed.
  • Changed helper ESLint, changed-file Prettier, and git diff --check passed.
  • Full ESLint is blocked by existing Prettier errors in unchanged src/embed/status.ts:8 and packages/atmosphere/src/providers/twitter/processor.ts:986.

Summary by CodeRabbit

  • Bug Fixes

    • Empty or invalid translation results now trigger the available fallback instead of being returned as translations.
    • Quote translations can fall back independently while retaining a valid translation of the main post.
  • Tests

    • Added coverage for successful translations, fallback behavior, and cases where no fallback is available.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b23efc70-b723-46b4-905f-85430ce6647f
Commits

Reviewing files that changed from the base of the PR and between f23cb1d and cdec7f0.

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.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 25b4573f-2781-4e77-85cf-a90404d5a2eb
📥 Commits

Reviewing files that changed from the base of the PR and between fbcd37b and f23cb1d.

📒 Files selected for processing (2)
  • packages/atmosphere/src/helpers/translate-grok.ts
  • test/twitter.translation.test.ts

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

Walkthrough

The Grok translation helper now returns null when its response text is not a string or is blank. Twitter translation tests cover Polyglot fallback, valid Grok text, unavailable fallback, and quote translation fallback.

Changes: Twitter Translation

Layer / File(s) Summary
Grok result validation and fallback
packages/atmosphere/src/helpers/translate-grok.ts, test/twitter.translation.test.ts
The helper warns and returns null for non-string or blank Grok text. Tests cover fallback to Polyglot, retention of valid Grok text, and behavior when fallback is unavailable or only the quote translation is empty.

Priority: Low

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

Change: Bug fix

Merge Risk: Minimal · previous review f23cb

Grok responses with empty or unusable translation text now fall back to the existing provider instead of being published as empty translations. No merge-blocking risk is apparent.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: enabling fallback when Grok returns an unusable translation.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ 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

A rabbit checks the words that came,
Blank text gets sent back all the same.
Polyglot steps in when needed,
Good Grok lines pass through unimpeded.
A quote finds words; the body stays,
The rabbit hops through translated days.

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The PR rejects Grok responses that lack usable translation text.

  • Twitter translations fall back when Grok returns no usable text.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Grok response] --> B{Text is a nonblank string?}
  B -->|Yes| C[Keep Grok translation]
  B -->|No| D[Return null]
  D --> E[Try configured Polyglot or AI fallback]
  E --> F{Translation available?}
  F -->|Yes| G[Use fallback translation]
  F -->|No| H[Leave translation unset]
Loading

Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix/grok-empty-..." · Reviewed by Greptile

@dangeredwolf
dangeredwolf merged commit 9e8cfbb into FxEmbed:main Oct 28, 2026
6 checks passed
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.

2 participants