Skip to content

fix: enforce translated runtime responses#609

Merged
riderx merged 1 commit into
mainfrom
codex/fix-translation-worker-runtime-cache
May 1, 2026
Merged

fix: enforce translated runtime responses#609
riderx merged 1 commit into
mainfrom
codex/fix-translation-worker-runtime-cache

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 1, 2026

What changed

  • Stop sending translated HTML with public/browser/CDN cache headers. Localized responses now return no-store headers while the Worker Cache API remains the only cache layer.
  • Version the Worker Cache API key so old partially English cached translations are bypassed after deploy.
  • Remove the English HTML fallback for localized translation failures. A cold miss now waits for translation and serves the translated page; if translation fails, it returns a temporary 503 instead of English.
  • Make translation model failures explicit when JSON is malformed, lengths mismatch, or too much natural-language copy is returned unchanged.
  • Fix language-selector href rewriting server-side and remove the extra edge-injected selector script that could fight the app selector.

Why

Production /es/ could be served from public edge cache and the worker could cache or return partially English HTML when the model output was invalid or under-translated. Language-selector links were also being rewritten to the current locale before a client-side repair script ran.

Validation

  • bun run ci:verify:translation

Summary by CodeRabbit

Release Notes

  • New Features

    • Versioned translation cache entries for improved consistency
    • Server-side language selector rewriting with enhanced locale targeting
  • Bug Fixes

    • Explicit error responses for translation failures instead of fallback fetches
    • Stricter validation of translation batches and segment matching
    • Improved translation requirements for comprehensive UI coverage

@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 now implements query parameter-based cache versioning, enforces strict no-store cache controls on translated responses, adds 503 responses for translation failures, validates translation batch counts with error handling, and shifts language-selector handling from client-side script injection to server-side DOM rewriting with locale-aware href updates.

Changes

Cohort / File(s) Summary
Translation Worker Core Logic
apps/translation-worker/src/index.ts
Implements cache versioning via __capgo_translation_cache query parameter; enforces no-store cache directives and strips ETag/Last-Modified headers. Adds 503 responses for translation failures (oversized HTML and runtime errors). Tightens HTML translation by removing source text defaults, validating batch/segment counts, and detecting unchanged translations. Replaces client-side language-selector script injection with server-side DOM rewriting that computes locale targets, skips translation of selector UI text, rewrites href values to target locales, and updates dropdown content with flag entities. Updates system prompt to enforce translation of all UI labels while preserving identifiers, URLs, and structural meaning.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 A rabbit's verse on caching schemes...
✨ With versioned params and cache dreams,
The worker translates, validates with care,
Language selectors rewritten with flair! 🌍
No more client scripts, server rules the day—
Translations flow in the proper way! 🎀

🚥 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: enforce translated runtime responses' is clear and directly relates to the main change: enforcing that translated responses use no-store cache headers and preventing fallback to English HTML, which is the core objective of this PR.
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/fix-translation-worker-runtime-cache

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

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

@riderx riderx force-pushed the codex/fix-translation-worker-runtime-cache branch from 3697d17 to 1ee0d01 Compare May 1, 2026 15:55
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: 3697d173db

ℹ️ 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 thread apps/translation-worker/src/index.ts Outdated
Comment thread apps/translation-worker/src/index.ts
@riderx riderx force-pushed the codex/fix-translation-worker-runtime-cache branch from 1ee0d01 to 153be1c Compare May 1, 2026 15:59
@riderx
Copy link
Copy Markdown
Member Author

riderx commented May 1, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 153be1cf9a

ℹ️ 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 thread apps/translation-worker/src/index.ts
@riderx riderx force-pushed the codex/fix-translation-worker-runtime-cache branch from 153be1c to 8fe7065 Compare May 1, 2026 16:06
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

@riderx riderx merged commit feeff67 into main May 1, 2026
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: 8fe70655d3

ℹ️ 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".

const contentLength = Number.parseInt(originResponse.headers.get('Content-Length') || '0', 10)
if (Number.isFinite(contentLength) && contentLength > MAX_HTML_BYTES) {
return withResponseHeaders(originResponse, 'BYPASS')
throw new Error(`Source HTML is too large to translate: ${contentLength} bytes`)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle oversized pages without retryable 503s

Throwing on MAX_HTML_BYTES in buildTranslatedResponse now routes every oversized localized page through the top-level catch, which always returns 503 with Retry-After: 60; because page size is deterministic, those requests will never recover on retry and the locale path becomes permanently unavailable on cold misses. This is a regression from the previous bypass behavior and affects any page whose HTML exceeds the size cap.

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