Repository navigation
Conversation
H-Chris233
approved these changes
Oct 24, 2026
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.
Closes #1256
问题
TextStream 的窗口重解码可能改写已经上报为 stable 的文字(实测:一段音译在窗口内切换书写系统,
Co→科蒂纳)。Snapshot.update()把这种情况当成致命错误raise,worker 的main()把它包成{"type":"error"}后exit 1→ 整条录音记为transcribeFailed,文本为空。录音文件是完好的,但“重新转录”走同一引擎、同一位置再次失败,等于这段录音永久不可恢复。本机 74 条 TextStream 记录里命中 1 条;随后一条 96.5 s 的录音又命中一次。命中即整段丢失。
为什么在 app 侧修
protocol.rs:Stream只校验sequence单调递增;Final只额外要求draft为空。没有前缀单调性校验。textstream.rs:消费finalized + draft时是整段替换(offset: 0),不是追加。stable_text是按字符/空白单位切分出来的启发式(而解码上下文是按 token id 回滚的,两者边界并不同),不能当硬契约用。也就是说协议本身允许 preview 被改写;把它当致命错误,是自己把可恢复的状况升级成了录音报废。
改动
worker.py—Snapshots.update():前缀不成立时回退到双方仍一致的公共前缀,不再抛异常。if terminal: finalized = full if not full.startswith(finalized): - raise ValueError("decoder snapshot does not contain its finalized prefix") + agreed = 0 + for previous, current in zip(finalized, full): + if previous != current: + break + agreed += 1 + finalized = finalized[:agreed] self.finalized, self.draft = finalized, full[len(finalized) :]test_worker.py— 原来那条assertRaises(ValueError)改成断言恢复行为,并补一条部分重合的用例(我们去了Co→我们去了科蒂纳。应得到("我们去了", "科蒂纳。"))。验证
python3 -m unittest test_worker -v→ 13 passed(macOS 27.0.1 / Python 3.14).runtime/worker.py+ 同一个模型:{"type":"error","message":"decoder snapshot does not contain its finalized prefix"},exit 1,无文本{"type":"final","sequence":25,"draft":""},exit 0,全文正常输出边界
terminal快照仍以库的终态为准(if terminal: finalized = full未动)。