Skip to content

fix(bailian): 修复 end_time fallback 将 interim 误判为 final 的 bug#537

Merged
H-Chris233 merged 2 commits into
Open-Less:betafrom
H-Chris233:fix/bailian-endtime-fallback
May 27, 2026
Merged

fix(bailian): 修复 end_time fallback 将 interim 误判为 final 的 bug#537
H-Chris233 merged 2 commits into
Open-Less:betafrom
H-Chris233:fix/bailian-endtime-fallback

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

@H-Chris233 H-Chris233 commented May 27, 2026

User description

背景

PR #535 合并后,@github-actions 的 review comment 指出两个 concern:

  1. ID collisionsentence_id == 0 覆盖 → 理论正确,实际 DashScope 始终提供递增 ID,低风险
  2. Finality fallbackend_time > 0 误判 interim → 真实 bug

这个 fix 解决的是 concern 2

问题

原代码 line 397:

let is_sentence_final = sentence_end || end_time > 0;

DashScope 的 interim result-generated 事件同时携带:

  • sentence_end: false
  • end_time: 1500正数,随音频推进增长)

因此 is_sentence_final = false || true = true,interim 结果被误判为 final
存入 final_segmentsreintroduce 了 #530 要修的累积文本重复

修复

sentence_end 字段存在时完全信任它;end_time > 0 仅在该字段不存在时 fallback:

let sentence_end_val = sentence.get("sentence_end");
let is_sentence_final = match sentence_end_val {
    Some(_) => sentence_end,
    None => end_time > 0,
};

测试修正

make_result_event 之前给 interim 设 end_time: 0不匹配真实 API 行为
导致测试没有覆盖这个路径。修复后 interim 也带正数 end_time
并新增 interim_with_positive_end_time_not_mistaken_for_final 测试。

测试结果

21 passed; 0 failed

PR Type

Bug fix, Tests


Description

  • Skip heartbeat ASR events

  • Trust sentence_end for finality

  • Cache partials by sentence_id

  • Merge overlaps and expand tests


Diagram Walkthrough

flowchart LR
  A["DashScope ASR events"] --> B["Filter heartbeat events"]
  B --> C["Detect finality via sentence_end"]
  C --> D["Track partials per sentence_id"]
  D --> E["Store finals in BTreeMap"]
  E --> F["Merge overlapping segments"]
  F --> G["Emit deduplicated transcript"]
Loading

File Walkthrough

Relevant files
Bug fix
bailian.rs
Harden DashScope ASR deduplication flow                                   

openless-all/app/src-tauri/src/asr/bailian.rs

  • Skips heartbeat events before transcript processing.
  • Uses sentence_end as the primary finality signal, with end_time as
    compatibility fallback.
  • Tracks interim text in partial_segments and clears it after final
    results arrive.
  • Adds merge_segments() to prevent overlapping duplicate text in the
    final transcript.
+324/-9 

- 跳过 heartbeat 事件(不含识别文本)
- 改用 API 文档标注的 sentence_end 判断 finality,end_time > 0 作为兼容 fallback
- 新增 partial_segments BTreeMap 追踪 interim 结果,final 时自动清理
- sentence_id == 0 的 final 结果不再丢弃,存入 final_segments
- 新增 merge_segments() 带 2 字符最小重叠检测的拼接守卫
- finish_with_partial_or_error 同时检查 partial_segments
- 测试从 3 个扩展到 20 个
end_time > 0 的 fallback 逻辑在 sentence_end 字段存在时不应该启用,
因为 DashScope 的 interim 结果也携带正数 end_time,导致累积文本重复重现。
改为仅当 sentence_end 字段完全不存在时才 fallback 到 end_time > 0。

同时修正测试 helper 的 end_time 值,使其匹配真实 API 行为(interim 也有正数 end_time),
并新增 interim_with_positive_end_time_not_mistaken_for_final 测试。
@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

535 - Fully compliant

Compliant requirements:

  • Skip heartbeat-only ASR events.
  • Use sentence_end as the primary finality signal, with end_time as a fallback only when sentence_end is missing.
  • Track interim results per sentence_id and clear them when the final result arrives.
  • Keep final results even when sentence_id == 0.
  • Merge overlapping final segments to avoid duplicated transcript text.
  • Add tests covering heartbeat filtering, interim updates, duplicate finals, zero sentence_id, and ordered multi-segment assembly.
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@H-Chris233 H-Chris233 merged commit 58b5684 into Open-Less:beta May 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant