Skip to content

fix(i18n): reuse saved translations during refresh#2108

Merged
riderx merged 20 commits into
mainfrom
codex/translation-cache-queue
May 11, 2026
Merged

fix(i18n): reuse saved translations during refresh#2108
riderx merged 20 commits into
mainfrom
codex/translation-cache-queue

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 10, 2026

Summary (AI generated)

  • Keep ready message translations reusable beyond the 5 minute freshness window.
  • Serve the last saved translation while queueing a refresh when the English checksum changes.
  • Keep first-time languages on the pending response so the frontend shows the retry-later toast.

Motivation (AI generated)

The console translation worker was returning pending whenever the English catalog checksum changed, even when a saved translation existed. This matches the landing behavior by serving the saved translation immediately and refreshing in the background.

Business Impact (AI generated)

Users can switch to a previously translated language without being blocked by the refresh queue after each English message update.

Test Plan (AI generated)

  • bun test tests/translation-queue.unit.test.ts
  • bunx eslint cloudflare_workers/translation/index.ts tests/translation-queue.unit.test.ts
  • bun lint
  • Commit hook: bun run cli:build && vue-tsc --noEmit

Generated with AI

Summary by CodeRabbit

  • New Features

    • Enhanced translation caching: separate freshness windows for ready vs pending translations, serving the latest ready payload when checksums differ and adding headers to indicate refreshing/stale state.
  • Chores

    • Renamed translation service across all deployment environments.
  • Tests

    • Expanded unit coverage for caching, freshness checks, and translation request/queueing behavior.

Review Change Stack

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 38 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5b12e581-1ff8-41be-9b33-35314d38f7dc

📥 Commits

Reviewing files that changed from the base of the PR and between 79df627 and 0314f32.

📒 Files selected for processing (3)
  • cloudflare_workers/translation/index.ts
  • cloudflare_workers/translation/wrangler.jsonc
  • tests/translation-queue.unit.test.ts
📝 Walkthrough

Walkthrough

The translation worker now enforces a dedicated 7-day freshness window for "ready" translations, with new store-reader and response helpers to serve fresh or stale cached payloads. The handler refactors to prefer fresh ready entries, serve stale entries when checksums differ, and queue refresh when entries are too old. The worker is renamed from capgo_translation_console to capgo_translation across environments. Tests validate freshness logic and fetch behavior.

Changes

Translation Worker Ready-Entry TTL

Layer / File(s) Summary
TTL Constants and Freshness Helper
cloudflare_workers/translation/index.ts, tests/translation-queue.unit.test.ts
Introduces READY_TRANSLATION_STORE_TTL_SECONDS constant (7 days) and adds isReadyTranslationFresh(entry) helper to compute whether a ready entry is still within the freshness window. Exported for testing and validated with unit coverage at 5-minute freshness boundaries.
Store Reader for Latest Ready Entry
cloudflare_workers/translation/index.ts
Adds readLatestReadyTranslationStoreEntry(env, targetLanguage) to query the translation store for the most recently-updated entry with ready status.
TTL Application for Ready Entries
cloudflare_workers/translation/index.ts, tests/translation-queue.unit.test.ts
Updates translationStoreTtlSeconds to use READY_TRANSLATION_STORE_TTL_SECONDS when entry status is ready, ensuring ready translations are retained longer than pending ones. Test assertion validates the longer retention window.
Response Helpers for Ready Translations
cloudflare_workers/translation/index.ts
Adds latestReadyTranslationResponse to serve latest ready payload with stale/refresh headers, plus readyOrLatestTranslationResponse, currentReadyTranslationResponse, and queueCurrentTranslationResponse to centralize checksum/freshness decision paths.
Handler Orchestration for Ready-Entry Logic
cloudflare_workers/translation/index.ts, tests/translation-queue.unit.test.ts
Refactors handleTranslationMessages to query latest ready entry, prefer fresh ready translations within the freshness window, serve stale ready translations when checksum differs, and queue when no ready entry exists or entry is too stale. Includes cache and store mocks and three tests verifying fresh-ready return (HTTP 200, no queue), stale-ready refresh-queue (HTTP 200 with refresh enqueue), and initial-miss behavior (HTTP 202, pending status).
Worker Configuration Rename
cloudflare_workers/translation/wrangler.jsonc
Renames worker and environment identifiers from capgo_translation_console* to capgo_translation* across all environments (prod, preprod, alpha, local) and adjusts D1 database_name bindings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Cap-go/capgo#2046: Both PRs modify the Cloudflare translation worker and its queue/store/ready-vs-pending caching logic, including exported test utilities and unit tests.

Poem

🐰 A rabbit hops through caches bright,
Seven days to keep translations right,
Fresh or stale, we serve with care,
Latest ready, always there!
Queue the rest with gentle cheer. 🌿

🚥 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
Title check ✅ Passed The title clearly summarizes the main change: enabling reuse of saved translations during refresh operations, which aligns with the primary objective of serving cached translations instead of pending responses.
Description check ✅ Passed The description includes a summary, motivation, business impact, and test plan with completed checkmarks, but lacks screenshots section and detailed reproduction steps typically expected for completeness.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/translation-cache-queue

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

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 10, 2026

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing codex/translation-cache-queue (0314f32) with main (1ef9d26)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@riderx
Copy link
Copy Markdown
Member Author

riderx commented May 10, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 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
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cloudflare_workers/translation/index.ts`:
- Around line 943-946: The current early return uses
isReadyTranslationFresh(latestReadyEntry) to short-circuit to
readyOrLatestTranslationResponse even when latestReadyEntry.checksum !=
checksum, causing fresh-but-stale data to be served without queuing a background
refresh; change the logic so you only return immediately if the saved entry is
fresh AND its checksum matches the requested checksum, otherwise before
returning the live response ensure a refresh is queued (i.e. call the existing
pending-job creation helper used elsewhere in this file — locate and invoke the
function that creates a pending translation entry for
targetLanguage/readyRequest, or otherwise enqueue a refresh) and then return
readyOrLatestTranslationResponse; keep the same arguments (requestId,
readyRequest, latestReadyEntry, targetLanguage, checksum) when returning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 795c60bf-63d0-411b-8734-1c8983ab5d8b

📥 Commits

Reviewing files that changed from the base of the PR and between 1ac55c4 and efd2596.

📒 Files selected for processing (3)
  • cloudflare_workers/translation/index.ts
  • cloudflare_workers/translation/wrangler.jsonc
  • tests/translation-queue.unit.test.ts

Comment thread cloudflare_workers/translation/index.ts Outdated
@sonarqubecloud
Copy link
Copy Markdown

@riderx riderx merged commit 1a8ede4 into main May 11, 2026
52 of 53 checks passed
@riderx riderx deleted the codex/translation-cache-queue branch May 11, 2026 00:03
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