Skip to content

fix(translation): don't terminate stream on per-batch JSON parse failures#44

Merged
sirily11 merged 1 commit into
mainfrom
copilot/fix-translation-response-parsing
Apr 24, 2026
Merged

fix(translation): don't terminate stream on per-batch JSON parse failures#44
sirily11 merged 1 commit into
mainfrom
copilot/fix-translation-response-parsing

Conversation

Copilot AI commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

A failed JSON parse in any batch (e.g. "Failed to parse translation response for batch 9") emitted a terminal error event, closing the SSE stream. The worker kept running, but every client reconnect replayed the cached events and re-closed at the same error — surfacing as the same error replaying forever with the run never completing.

Changes

  • lib/translation/xcloc/events.ts: Add non-terminal batch-error event ({ batchIndex, message }), parallel to the existing save-error.
  • lib/translation/xcloc/agent.ts: translateBatch yields batch-error instead of error on parse failure, and falls through to the existing batch-complete so the worker saves progress and continues to subsequent batches / final complete.
  • lib/translation/components/use-translation-stream.ts: Handle batch-error like save-error — append to the errors list, keep the stream open.
  • __tests__/translation/xcloc/agent.test.ts: Update the invalid-JSON test to assert batch-error (the run still ends with complete).

error remains terminal and reserved for actual run-fatal failures (raised by the worker's outer retry loop).

@vercel

vercel Bot commented Apr 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
universal-translation Ready Ready Preview, Comment Apr 24, 2026 11:01am

Request Review

@sirily11 sirily11 marked this pull request as ready for review April 24, 2026 11:01
Copilot AI review requested due to automatic review settings April 24, 2026 11:01
@autopilot-project-manager autopilot-project-manager Bot added the bug Something isn't working label Apr 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-error event type for non-fatal, per-batch failures.
  • Updated translateBatch to emit batch-error (and still emit batch-complete) when parsing fails, instead of emitting terminal error.
  • 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.

@sirily11 sirily11 merged commit 13d142c into main Apr 24, 2026
10 checks passed
@sirily11 sirily11 deleted the copilot/fix-translation-response-parsing branch April 24, 2026 11:34
@sirily11

sirily11 commented May 2, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.2.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants