You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(translate): read Workers AI chat completion content - #2785
The Workers AI translation fallback calls @cf/openai/gpt-oss-120b with messages. That request returns a Chat Completions response, with the translation in choices[0].message.content. I reproduced this with a direct Workers AI call. The current helper reads response.response, so it drops the translation and returns before trying M2M100.
For example, GET /2/status/20?lang=ja returned HTTP 200 with the original post text and no translation field. The parsing bug can cause this symptom when the earlier translation providers supply no usable result.
The legacy API endpoint /jack/status/20/ja also returned no translation with a query-free URL. The direct FixupX embed for the same post contained English both with and without ?s=20.
Changes
Read the Chat Completions message and retain support for the legacy response field.
Run M2M100 when the GPT-OSS response has no usable text.
Remove the Worker environment dump from the fallback path.
Add regression coverage for the chat and legacy formats and for missing, null, empty, and whitespace-only content.
Validation
npm run build passes on Ubuntu 24.04 LTS (WSL) with Node.js 26.13.1, matching the version used in CI.
The standard Cloudflare Vitest suite passes on Ubuntu. All 505 tests across 76 files passed, including the six new regression cases.
Five of the new cases failed before the fix in the focused Node test run. ESLint and Prettier checks on the changed code pass.
No actionable comments were generated in the recent review.
Walkthrough
translateTextLLM now handles chat-completion content and legacy response strings, returning null for missing or blank text. translateStatusAI uses M2M100 when the LLM result is null. Tests cover both response formats and fallback cases.
Changes: Translation response handling
Layer / File(s)
Summary
Normalize LLM output and verify fallback src/helpers/translateAI.ts, test/translateAI.test.ts
The helper selects chat-completion content or a legacy response string and returns null for missing or blank text. A null result continues to M2M100. Tests cover both response formats and missing, null, empty, or whitespace-only content. The fallback no longer logs the environment object.
FxEmbed/FxEmbed#2536: Both PRs change the translation fallback path and remove environment logging from it.
Suggested reviewers:dangeredwolf
Merge Risk: Minimal · up to 688d0
The change makes the translation fallback read Chat Completions responses and fall back to M2M100 when the LLM returns no usable text. It also stops logging the Worker environment. Regression tests cover the new and legacy formats. No merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(translate): read Workers AI chat completion content" matches the main change. The PR changes the Workers AI translation fallback so it reads choices[0].message.content from Chat Complet…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title "fix(translate): read Workers AI chat completion content" matches the main change. The PR changes the Workers AI translation fallback so it reads choices[0].message.content from Chat Completions responses while keeping support for the legacy response field. It also falls back to M2M100 when no usable text is returned, and adds regression tests for both response formats and for missing, null, empty, and whitespace-only content. The title names the core fix and the affected area. It does not mention the M2M100 fallback or the log removal, which is acceptable because the title does not need to cover every detail.
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.
A rabbit checks each phrase with care Chat words or legacy text appear When empty words fail to arrive M2M100 keeps the translation alive Then off hops Bunny, satisfied there
Recent review info
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: 83182cd9-9950-40fe-bf26-0d4e1450004d
Commits
Reviewing files that changed from the base of the PR and between e4d1139 and 688d04c.
Files selected for processing: 2
src/helpers/translateAI.ts
test/translateAI.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.
[Medium impact] The PR appears safe to merge; no actionable issues were found.
Summary
The PR reads Workers AI translations from choices[0].message.content while keeping support for response.
AI status translations use GPT-OSS chat text or fall back to M2M100.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Request GPT-OSS translation] --> B[Read chat content or legacy response]
B --> C{Nonblank text?}
C -- Yes --> D[Return translation]
C -- No --> E[Try M2M100]
A -- Error --> E
E --> F[Return result or null]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Workers AI translation fallback calls
@cf/openai/gpt-oss-120bwithmessages. That request returns a Chat Completions response, with the translation inchoices[0].message.content. I reproduced this with a direct Workers AI call. The current helper readsresponse.response, so it drops the translation and returns before trying M2M100.For example,
GET /2/status/20?lang=jareturned HTTP 200 with the original post text and notranslationfield. The parsing bug can cause this symptom when the earlier translation providers supply no usable result.The legacy API endpoint
/jack/status/20/jaalso returned no translation with a query-free URL. The direct FixupX embed for the same post contained English both with and without?s=20.Changes
responsefield.Validation
npm run buildpasses on Ubuntu 24.04 LTS (WSL) with Node.js 26.13.1, matching the version used in CI.Related embed report: #2698. Cloudflare Workers AI changelog
Closes #2786