Skip to content

fix: redirect cold translation misses#610

Merged
riderx merged 1 commit into
mainfrom
codex/use-kimi-translation-model
May 1, 2026
Merged

fix: redirect cold translation misses#610
riderx merged 1 commit into
mainfrom
codex/use-kimi-translation-model

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 1, 2026

What changed

  • Switch the translation worker default model and Wrangler config from Llama to Cloudflare Workers AI Kimi K2.6: @cf/moonshotai/kimi-k2.6.
  • Parse OpenAI-style choices[].message.content responses so Kimi output is accepted.
  • Change cold-cache localized requests to immediately issue a temporary redirect to the English path while translation generation continues in the background.
  • Keep cached localized pages fast: existing cache is served, stale cache is served while refreshing, and only empty cache redirects.
  • Bump the worker cache version for the model/runtime behavior change.

Validation

  • bun run ci:verify:translation

Summary by CodeRabbit

  • New Features

    • Unavailable translations now automatically redirect to the default language version instead of showing error messages, enabling a more seamless user experience across different language preferences and regions.
  • Improvements

    • Translation request response times significantly enhanced through asynchronous background cache refresh operations without blocking.
    • AI translation model and cache versioning updated for improved performance.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The translation worker updates its AI model from Llama-3.1-8b to Kimi-K2.6 and replaces synchronous 503 error responses with asynchronous cache refresh behavior. On cache misses, the worker returns a 302 redirect to the default locale while scheduling background translation generation, and expands AI response parsing to handle OpenAI-style choice structures.

Changes

Cohort / File(s) Summary
Model & Configuration
apps/translation-worker/wrangler.jsonc
Updated TRANSLATION_MODEL from @cf/meta/llama-3.1-8b-instruct to @cf/moonshotai/kimi-k2.6.
Worker Logic & Response Handling
apps/translation-worker/src/index.ts
Updated DEFAULT_MODEL constant and TRANSLATION_CACHE_VERSION to 2026-05-01-kimi-k2.6-v1. Replaced synchronous 503 error responses with 302 temporary redirects on cache misses. Changed cache refresh to execute asynchronously in background via ctx.waitUntil() instead of awaiting completion. Enhanced extractAiText() to parse OpenAI-style choices array structures. Added null body handling for HEAD requests.

Sequence Diagram

sequenceDiagram
    actor Client
    participant Worker as Translation Worker
    participant Cache
    participant AI as AI Model

    Client->>Worker: Request translation
    Worker->>Cache: Check cache
    alt Cache Hit
        Cache-->>Worker: Translation found
        Worker-->>Client: 200 + Translation
    else Cache Miss
        Cache-->>Worker: Not found
        Worker->>AI: Schedule background refresh
        activate AI
        Worker-->>Client: 302 redirect to default locale
        Note over Worker: Response sent immediately
        AI->>Cache: Generate & store translation
        AI-->>Worker: Done (background)
        deactivate AI
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through translation streams,
Swapping models—oh, such dreams!
Cache misses dance, redirects flow,
Background refreshes steal the show,
Async magic makes things bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 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%. 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 'fix: redirect cold translation misses' directly reflects the main change: handling cold cache translation requests with redirects instead of 503 errors.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/use-kimi-translation-model

Review rate limit: 0/5 reviews remaining, refill in 51 minutes and 59 seconds.

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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@riderx riderx merged commit 0cb26b5 into main May 1, 2026
8 of 10 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a492c5fb1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1058 to +1062
refreshCache(request, env, requestUrl, locale, cacheKey).catch((error) => {
console.error('Failed to create translated page', { pathname: requestUrl.pathname, locale, error })
}),
)
return temporaryEnglishRedirectResponse(requestUrl, isHead)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Return origin status on cold misses for non-cacheable pages

On a cache miss this branch always returns a 302 to the English URL, but refreshCache only stores responses when response.ok && isHtmlResponse(response). That means localized requests whose English origin returns a redirect, 404, or any non-HTML response will never populate cache and will be permanently redirected to English on every request (e.g. /fr/... pages that should be 301/404). This is a behavior regression from the previous flow, which returned the actual origin status on first request.

Useful? React with 👍 / 👎.

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