feat(translation): streaming segmentation with call-site gating and language-scoped pieces - #2
Open
yunsheng111 wants to merge 3 commits into
Open
Conversation
Replies are segmented while still streaming; the display chain (stored pieces + raw tail) stays contiguous. Pieces and pending gaps carry the target language they were produced for and are only restored for the current one, and a change of target language resets mounted instances instead of letting the previous language's translations keep rendering. Requests ride the PR1 contract — skipped results land as identity pieces, retry escalation bumps the variant — and an disabled hook does no segmentation work at all.
Switching target language or provider now drops stored pieces and pending gaps together with the request cache, so stale-language output cannot resurface after a settings change.
Text and reasoning parts choose between a streaming-translated part and a plain part at the component level, so users who never enable translation mount zero translation hooks and pay no per-token segmentation scan. Reasoning translation is owned by one hook that handles both streaming and settled text — the dual-hook arrangement that could never issue a request is gone.
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.
Summary
Stacked on the pool PR (which is stacked on xintaofei#700) — streaming segmentation, ported from xintaofei#696 with the two structural complaints from the review fixed:
TextPart/ReasoningPartconditionally render a streaming-translated part or a plain part, so users who never enable translation mount zero translation hooks and pay no per-token segmentation scan (the hook also early-outs internally). The review's "cheap version, done properly".primeTranslationSettingsclears the streaming stores together with the cache, and mounted instances reset on a language change instead of letting the previous language's translations keep rendering.What it does
Replies are segmented in ~600-char tail windows while still streaming; the display chain (stored pieces + raw tail) stays contiguous, including across retried/given-up gaps. Requests ride the PR1 contract end to end:
skippedresults land as identity pieces past every gate, retry escalation bumps thevariantso the backend cache can't serve the reply a gate just refused, and priority/background requests map onto the pool's two lanes.Testing
tsc --noEmitand eslint on touched files: clean;pnpm test: 438 files / 6470 tests passingsrc-tauri/untouched by this PR (identical to the pool PR's green run: 3638 lib tests + integration binaries, server lib 3597)