Skip to content

feat: configure bounded playback recovery and cooldown in the console - #26

Merged
yichen11818 merged 12 commits into
yichen11818:mainfrom
nitonitori:fix/automatic-playback-retry
Nov 13, 2026
Merged

yichen11818 merged 12 commits into
yichen11818:mainfrom
nitonitori:fix/automatic-playback-retry

Conversation

@nitonitori

@nitonitori nitonitori commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem and behavior

Transient source failures during natural continuation or explicit play/next/skip can leave a non-empty queue idle. Add a persisted Playback recovery console section with bounded exponential retry, temporary skip or wait-on-target exhaustion, and an outage cooldown.

  • Defaults: enabled; 3 additional retries at 15/30/60 seconds; SKIP retains failed entries for a later pass; cooldown 300 seconds after 3 exhausted targets. WAIT keeps the selected target through cooldown. Zero retries is supported. Counts, delays and combinations validate atomically.
  • New recovery runs snapshot applied settings. Saving stages changes; applying disable cancels pending work immediately without interrupting healthy playback. Existing first-start environment import and database persistence apply.
  • One generation-guarded worker covers natural completion, explicit play/next/skip, selected queue entries and first playback failure after enqueue. Stop/pause/clear/new intent/shutdown cancel stale work; old track events cannot replace a waiting manual target. Permanent-unavailability and paused-event boundaries have regression coverage.
  • Only classified transient network/timeout/429/502/503/504/known Netease risk failures retry. Initial HTTP errors remain errors. Queue entries, source quality and request attribution survive recovery. QQ transport exceptions remain typed for classification.
  • Player status shows the target, retry budget, retry/cooldown countdown and safe reason category. Stop and cancel retry and Next remain available while waiting. No signed URL, cookie or upstream response body is added to recovery status.

Closes #24.

Validation

  • Python 3.11 full backend suite: 183 tests, passed (2 skipped), using temporary databases, mocked provider/voice boundaries and a deterministic recovery clock; no platform accounts or TeamSpeak server required.

  • Node 22: npm ci, npm run typecheck, npm test -- --maxWorkers=1 (12 tests), npm run build, npm run build:demo passed.

  • Headless Chromium fixture check: open Settings → Playback recovery, inspect pending cooldown, click Stop and cancel retry, confirm POST /voice/stop and disappearance of the pending banner. Screenshot below.

  • Standards and specification reviews completed; reported permanent-failure traversal and paused-event race cases were reproduced and fixed.

  • Local containers were memory/CPU bounded. No production deployment or live audio/TeamSpeak validation in this PR.

  • Combined integration of feat: configure bounded playback recovery and cooldown in the console #26 and feat: configure Netease and QQ Music quality defaults per provider #27 merged without conflicts locally: 191 backend tests passed (2 skipped); Web typecheck, 15 Vitest tests, production build and demo build passed. The integration branch was used only for local validation.

  • Review follow-up: explicit selection keeps its initial permanent error without deleting the target or replacing current playback; Bilibili API/yt-dlp wrappers preserve failure classification. Regression cases also cover stale selection failures after stop/pause/new intent, unclassified errors, permissions, rate limits, timeouts and a successful transient retry through the download chain.

Screenshot

Playback recovery settings and pending controls

Configuration timing, ranges, environment names and status fields are documented in docs/PLAYBACK_RECOVERY.md.

@nitonitori nitonitori changed the title fix: retry automatic queue advancement after transient failures feat: configure bounded playback recovery and cooldown in the console Nov 13, 2026
@nitonitori nitonitori reopened this Nov 13, 2026
@nitonitori
nitonitori marked this pull request as ready for review November 13, 2026 11:48

@yichen11818 yichen11818 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢你为这个项目投入时间,也感谢把配置界面、文档和回归测试一并补齐。播放失败后队列停住确实值得解决,这次对重试次数、冷却、取消和状态展示的设计也比较完整。

我审查了当前提交 972d7914462ffa4f42e0dedb4d4cf941c18ce946,并在隔离环境运行了后端测试:177 项,跳过 1 项,其余通过。不过补充边界场景后,复现了两个建议在合并前修复的问题:

  1. [P2] 手动选曲失败后,接口返回成功并播放另一首。
    play_queue_item() 现在调用 _continue_auto_play(),但自动遍历逻辑会吞掉 402/403/404/410,删除目标并继续播放下一首。复现场景:A 正常播放,手动选择返回 403 的 B,实际结果是 B 被删除、切到 C,接口返回 {"ok": true}。原接口会向调用方返回失败。report_initial_error=True 没有覆盖这个分支。建议区分手动指定目标与自动续播,保留首次请求的错误语义,避免失败的选曲意外替换正常播放。
    位置:backend/main.py:5217–5218,以及 _auto_play_next_from_queue() 的不可播放错误分支。

  2. [P2] B 站永久性权限错误会被当成临时故障重试。
    _playback_recovery_reason() 将所有 502 归为 upstream_unavailable,但现有 B 站解析链路也会把权限错误和 yt-dlp 的永久不可用异常包装成 502。我模拟 B 站 API 返回 403、yt-dlp 同样报告视频不可用,通过实际入队调用链复现了失败条目被保留并安排重试。WAIT 策略下,这类错误会反复冷却重试,与文档中“认证、付费限制、歌曲不存在不作为临时故障重试”的约定不符。建议在来源适配层保留错误类别,再依据原始原因决定是否恢复,并增加覆盖错误包装链路的测试。
    位置:backend/main.py:4407–4412。

另外,#26 与 #27 在本地合并无冲突;组合后的后端 185 项测试(跳过 1 项,其余通过)、前端类型检查及 15 项前端测试均通过。上述两个场景是现有测试之外补充复现的。本次未进行真实平台账号或 TeamSpeak 音频验证。

整体方向认可,建议先修复这两处行为问题再合并。再次感谢你的贡献。

@nitonitori

Copy link
Copy Markdown
Contributor Author

已按这条评审修正,提交为 cd7ba65、c7cb0d6。

  1. 手动选曲的首次错误:具体目标的首次播放与自动遍历分开处理。402/403/404/410 会返回给调用方,保留所选条目和原来播放的歌曲,不误播下一首。临时故障仍返回首次错误并安排恢复;自动续播仍沿用永久不可用条目的跳过处理。另补了“选曲挂起 → stop/pause/另选 → 旧请求才失败”的竞态,过期请求返回 409,不重新安排恢复或覆盖新目标。
  2. B站错误分类:API 和 yt-dlp 适配层保留故障类别,解析 yt-dlp 的实际异常链,不再仅凭外层 502 重试。认证/权限、业务拒绝、无效数据和未分类异常不会进入恢复;两条路径都明确为临时故障时才恢复。备用解析成功的路径保留。

回归先复现了原问题再修复。新增用例通过实际入队链路和模拟 HTTP/yt-dlp 响应验证:API 403 + 永久不可用、元数据完整/缺失、业务拒绝、无效响应、协议错误、429、超时,以及首次 503 后下一次真实下载流程成功。

本地 Python 3.11 后端 183 项测试通过(2 项跳过);与 #27 再次合并无冲突,组合后 191 项后端测试通过(2 项跳过)、15 项前端测试通过。未使用真实平台账号或 TeamSpeak 音频环境,未改动生产服务器。已推送,请再看一下这两个边界是否符合预期。

@yichen11818 yichen11818 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢及时修复,也感谢补上实际错误包装链路和过期请求的回归用例。

已复核 cd7ba65、c7cb0d6,当前审查版本为 c7cb0d66ee4c5c59a8092b28037f6ba57eeebab9。上一轮提出的两个问题均已确认修复:

  1. 重跑上次的手动选曲复现场景:A 正常播放时选择返回 403 的 B,现在接口返回 403,A 继续保留,B 不被删除,也不会误播 C。
  2. 重跑 B 站 API 403 + yt-dlp 视频不可用的实际入队链路:现在返回 403,recovery.pending 为 false,队列没有新增失败条目。错误类别不再因外层包装成 502 而丢失。

同时检查了新增的过期请求保护,以及临时错误仍能恢复的回归覆盖。本地验证结果:

  • #26 后端共 183 项:182 项通过,1 项因环境条件跳过。
  • 独立复跑上一轮的两个复现场景:2 项全部通过。
  • 与当前 #27 合并无冲突;组合后共 191 项后端测试:190 项通过,1 项因环境条件跳过。
  • 当前 #26 提交的 GitHub 检查和三个 Docker 镜像构建均通过。

本轮增量审查未发现新的阻塞问题,之前的两条修改意见已解决,从本次代码审查和自动化验证结果看可以合并。本次仍未进行真实平台账号或 TeamSpeak 音频验证。

@yichen11818
yichen11818 merged commit 358aa50 into yichen11818:main Nov 13, 2026
7 checks passed
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.

Configure bounded playback recovery and exhausted-track policy in the console

2 participants