Skip to content

feat(translation): streaming segmentation with call-site gating and language-scoped pieces - #2

Open
yunsheng111 wants to merge 3 commits into
feat/translation-endpoint-poolfrom
feat/translation-streaming
Open

feat(translation): streaming segmentation with call-site gating and language-scoped pieces#2
yunsheng111 wants to merge 3 commits into
feat/translation-endpoint-poolfrom
feat/translation-streaming

Conversation

@yunsheng111

Copy link
Copy Markdown
Owner

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:

  • I14 — translation hooks are gated at the call site: TextPart/ReasoningPart conditionally 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".
  • I15 — reasoning translation is owned by a single hook that handles both streaming and settled text; the dual-hook arrangement where one hook could never issue a request is gone by construction.
  • I13 — pieces and pending gaps carry the target language they were produced for, restoration validates against the current one, primeTranslationSettings clears 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: skipped results land as identity pieces past every gate, retry escalation bumps the variant so 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 --noEmit and eslint on touched files: clean; pnpm test: 438 files / 6470 tests passing
  • New coverage: old-language pieces don't survive a language switch, gaps are isolated per target language, disabled hooks do no scanning, skipped identity lands in one pass
  • src-tauri/ untouched by this PR (identical to the pool PR's green run: 3638 lib tests + integration binaries, server lib 3597)

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.
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