← Back to Pull requests

fix(datasource-test-mcp): 用专属 dispatcher 运行无窗口 probe_video, 修复远程 HLS 的主线程校验误报 #3628

Open
unknown opened this pull request with 210 lines diff across 2 files
View on GitHub
unknown unknown commented on Oct 18, 2026 06:30 UTC
Author

问题

probe_video(showWindow=false) 播放远程 HLS (m3u8) 时,mediamp 报:

IllegalStateException: MediampPlayer.play must be called on the player's main-dispatcher thread (mainDispatcher=Dispatchers.Main)

| 场景 | 结果 |
|---|---|
| 本地 mp4 + 无窗口 | ✅ 正常(官方 dist 自带 smoke-test 也过) |
| 远程 HLS + 无窗口 | ❌ 必现(一次评测里 11/11 条线路全部挂在 player.resume()) |
| 远程 HLS + 有窗口 | ✅ 正常 |

根因

给 mediamp 0.5.2 加上调试输出后复现,可以看到同一名字、同一线程组、但不是同一个 Thread 对象:

machineThread = Thread[#73, AWT-EventQueue-0, 6, main]
currentThread = Thread[#77, AWT-EventQueue-0, 6, main]
失败瞬间存活的 EDT 只有 #77,#73 已经死了

构造播放器之后、resume() 之前的无窗口路径(createHeadlessRenderContext → skiko/Compose 初始化)会替换 AWT 的 EventQueue,EDT 换成了新线程;机器协程也随之迁移(Dispatchers.Main 派发到新 EDT),但 mediamp 的 machineThread 里保存的是旧 Thread 对象,AbstractMediampPlayer.checkMainThread 用 == 比较 Thread 身份,于是永远不相等。

本地 mp4 打开极快,resume() 赶在 EDT 替换 / 机器线程捕获之前(machineThread == null 的 lenient 分支),所以看起来只有 HLS 会挂。

修复

MpvVideoAnalyzer:

  • 用专属单线程 dispatcher 运行 analyzer,并作为 MpvMediampPlayer 的 mainDispatcher(第三个构造参数)。既满足播放器“单线程调用”的要求,又保证机器与命令永远在同一个线程上,不再依赖 AWT EDT 是否被替换;

  • 窗口创建 / 销毁改回 AWT EDT(SwingUtilities.invokeAndWait / invokeLater)。
  • 验证

    用与官方 Windows 发行包一致的环境(本地构建 + 同版本依赖 + 自带 JCEF 的 JBR):

    | 场景 | 修复前 | 修复后 |
    |---|---|---|
    | 远程 HLS + showWindow=false | ❌ IllegalStateException | ✅ ok=true,实播 4258ms,1920x1080,截图 4 张 |
    | 远程 HLS + showWindow=true | ✅ | ✅ ok=true(无回归) |
    | 本地 mp4 + showWindow=false | ✅ | ✅ ok=true(无回归) |

    修复后 run_eval.py / deep_sample.py 的默认无窗口路径即可正常批量实播,不再需要外部把 showWindow 改成 true 绕过。

    相关

    mediamp 侧 checkMainThread 对“EDT 被重建”不健壮(比较已死的 Thread 对象),另开 issue:open-ani/mediamp#96

    Diff: 210 lines (+157 / -53) across 2 files Reviewer: Him188 Review duration: 62732m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.43) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 210 lines diff across 2 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.320
    Real PR Conversation Timeline
    1 comments
    "Review active on #3628"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.5% (MEDIUM) · Higher = larger blast radius
    43.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24% · Safe to merge
    24%