Harden translation model retries#617
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughQueue message type now includes optional Changes
Sequence Diagram(s)sequenceDiagram
participant QueueConsumer as Queue Consumer
participant AI as AI Model
participant Parser as Payload Parser
participant RetryHook as message.retry
QueueConsumer->>AI: send translateBatch prompt (require JSON array)
AI-->>QueueConsumer: returns payload (string/array/object)
QueueConsumer->>Parser: extractAiPayload / parseTranslationArray
alt parse succeeds and length matches
Parser-->>QueueConsumer: translations[]
QueueConsumer->>QueueConsumer: proceed with success path
else parse fails or length mismatch
Parser-->>QueueConsumer: parse error
QueueConsumer->>AI: retry (up to 3 attempts)
alt after attempts exhausted
QueueConsumer->>RetryHook: retry({delaySeconds})
RetryHook-->>QueueConsumer: scheduled
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 2/5 reviews remaining, refill in 26 minutes and 33 seconds. Comment |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/translation-worker/src/index.ts`:
- Around line 862-888: The function translationArrayFromUnknown is incorrectly
treating the key 'texts' as a valid translation-wrapper; remove 'texts' from the
keys array so model-echoed input objects like { targetLanguage, texts: [...] }
are not accepted as successful translations. Edit translationArrayFromUnknown
(the for loop that iterates over
['translations','translated','translatedTexts','texts',...]) to drop 'texts'
from that list, leaving other keys intact; no changes needed to
parseTranslationArray beyond relying on the corrected
translationArrayFromUnknown.
- Around line 1706-1711: The console.error in the translated-page queue retry
path is logging the full user-controlled job payload (message.body) which can
include PII in query params; update the log in the error handler that currently
prints job: message.body to instead log only non-sensitive identifiers (e.g.,
message.id, message.attempts, TRANSLATION_QUEUE_RETRY_DELAY_SECONDS, and a
sanitized URL or URL origin/path with query params stripped) and include
errorMessage(error); you can add a small sanitizer helper (e.g., sanitizeJobUrl
or sanitizeMessageForLogging) and use it in the place where job: message.body is
passed to console.error in index.ts so no raw message.body is emitted.
- Around line 940-987: The loop currently calls env.AI.run(model, ...) without
catching exceptions, so transient throws abort retries; wrap the AI call in a
try/catch around env.AI.run(...) (inside the for loop) and on catch set
lastError to the thrown Error (or new Error(errorMessage(error))) and continue
to the next attempt so the existing retry logic runs; keep subsequent steps
using extractAiPayload(result) guarded (result may be undefined) and ensure the
same warning/log path uses aiPayloadPreview(payload) and other symbols
(TRANSLATION_MODEL_ATTEMPTS, parseTranslationArray, extractAiPayload,
assertTranslatedBatch, aiPayloadPreview) unchanged.
🪄 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: c3a28690-0a07-437d-94a0-faea77b3ff0d
📒 Files selected for processing (1)
apps/translation-worker/src/index.ts
|



Summary
Validation
Summary by CodeRabbit
New Features
Bug Fixes