Skip to content

fix(translate): read Workers AI chat completion content - #2785

Open
iuti wants to merge 1 commit into
FxEmbed:mainfrom
iuti:fix/workers-ai-translation-response
Open

iuti wants to merge 1 commit into
FxEmbed:mainfrom
iuti:fix/workers-ai-translation-response

Conversation

@iuti

@iuti iuti commented Nov 26, 2026 •

Copy link
Copy Markdown

Problem

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.

Related embed report: #2698. Cloudflare Workers AI changelog

Closes #2786

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

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

Change: Bug fix

Possibly related PRs

  • 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: Passed 4

Check name Status Explanation
Title check Passed 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 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.
Description Check Passed 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.

Share

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.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[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]
Loading

Reviews (2) · Last reviewed commit: "fix(translate): read Workers AI chat com..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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.

Production status API omits translation for English posts requested with lang=ja

1 participant