fix(translation): don't terminate stream on per-batch JSON parse failures#44
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/rxtech-lab/universal-translation/sessions/6df7fbf0-b402-4336-951c-eb19b1049f8c Co-authored-by: sirily11 <32106111+sirily11@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
sirily11
April 24, 2026 11:01
View session
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR prevents per-batch JSON parse failures during Xcloc translation runs from terminating the SSE stream by introducing a non-terminal batch-error event, allowing the worker to continue processing subsequent batches and reach complete.
Changes:
- Added a new
batch-errorevent type for non-fatal, per-batch failures. - Updated
translateBatchto emitbatch-error(and still emitbatch-complete) when parsing fails, instead of emitting terminalerror. - Updated the stream consumer hook and the corresponding agent test to handle/assert
batch-error.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/translation/xcloc/events.ts | Extends the Xcloc event union with non-terminal batch-error. |
| lib/translation/xcloc/agent.ts | Emits batch-error on per-batch parse failures and proceeds to batch-complete. |
| lib/translation/components/use-translation-stream.ts | Treats batch-error as non-terminal by appending to errors without closing the stream. |
| tests/translation/xcloc/agent.test.ts | Updates invalid-JSON coverage to assert batch-error while still completing. |
Contributor
|
🎉 This PR is included in version 1.2.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A failed JSON parse in any batch (e.g. "Failed to parse translation response for batch 9") emitted a terminal
errorevent, closing the SSE stream. The worker kept running, but every client reconnect replayed the cached events and re-closed at the sameerror— surfacing as the same error replaying forever with the run never completing.Changes
lib/translation/xcloc/events.ts: Add non-terminalbatch-errorevent ({ batchIndex, message }), parallel to the existingsave-error.lib/translation/xcloc/agent.ts:translateBatchyieldsbatch-errorinstead oferroron parse failure, and falls through to the existingbatch-completeso the worker saves progress and continues to subsequent batches / finalcomplete.lib/translation/components/use-translation-stream.ts: Handlebatch-errorlikesave-error— append to the errors list, keep the stream open.__tests__/translation/xcloc/agent.test.ts: Update the invalid-JSON test to assertbatch-error(the run still ends withcomplete).errorremains terminal and reserved for actual run-fatal failures (raised by the worker's outer retry loop).