{{ message }}
Repository navigation
fix: degrade unresolvable voice attachments instead of failing the turn - #10337
Merged
Soulter merged 1 commit intoOct 3, 2026
Merged
Conversation
An empty Record (no file/url/path) or a failed audio conversion raised a bare Exception from convert_to_file_path() and aborted request assembly. In the local agent path the raw exception text was then sent to chat as the reply, and in the third-party agent path the whole turn failed silently. Degrade the same way images already do: log a warning and append a placeholder instead of propagating. The recoverability gate used by the image branches does not apply here because Record and the audio converter raise bare exceptions, not the OSError/ValueError family.
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/astr_main_agent.py" line_range="1529-1537" />
<code_context>
- audio_path = await comp.convert_to_file_path()
+ try:
+ audio_path = await comp.convert_to_file_path()
+ except Exception as exc: # noqa: BLE001
+ logger.warning(
+ "Voice attachment is unavailable (%s).",
+ type(exc).__name__,
+ )
+ req.extra_user_content_parts.append(
+ TextPart(text="[Voice unavailable]")
+ )
+ continue
req.audio_urls.append(audio_path)
_append_audio_attachment(req, audio_path)
</code_context>
<issue_to_address>
**issue (bug_risk):** The unconditional `except Exception` handlers also swallow non-recoverable failures from media resolution, such as `OSError` caused by resource exhaustion or unexpected programming errors, and silently continue without the attachment instead of propagating the failure. The existing image path explicitly rejects resource-exhaustion and programming errors through `is_recoverable_image_error()`, so the new voice and third-party image paths regress that safety boundary.
**Triggers:** When media conversion fails for a reason other than an invalid or unavailable attachment, such as an `OSError` from exhausted file descriptors or an unexpected implementation error.
**Suggested fix:** Classify recoverable media failures separately, or introduce a voice-specific recoverability predicate that preserves propagation for resource-exhaustion and programming errors while degrading ordinary resolution failures.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: astrbot/core/astr_main_agent.py:1537
Soulter
approved these changes
Oct 3, 2026
9 tasks done
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.

Modifications / 改动点
Closes #10336
An unresolvable voice attachment aborts request assembly, and the raw exception text is sent to chat as the reply:
Root cause (two layers).
Record.convert_to_file_path()raises a bareExceptionwhenfile,urlandpathare all empty (astrbot/core/message/components.py:241), whereasImage.convert_to_file_path()raisesValueError. As a resultis_recoverable_image_error()classifies theRecordfailure as non-recoverable (False), so the image branches' existing degrade pattern cannot be reused as-is — that shape would still re-raise and still kill the turn.Both
Recordbranches incollect_initial_request(astrbot/core/astr_main_agent.py) callconvert_to_file_path()without atry/except, while the siblingImagebranches do guard it and degrade toTextPart("[Image unavailable]"). The exception escapes request assembly, is caught inagent_sub_stages/internal.py, and the raw text becomes the user-visible reply.The trigger is broader than an empty voice.
_materialize_media_ref→ensure_wav→convert_audio_formatalso raises a bareExceptionon ffmpeg conversion failure and when ffmpeg is missing (astrbot/core/utils/media_utils.py:1552/:1560). Corrupt audio, a missing ffmpeg binary, or an unsupported codec therefore all reach the same turn-killing path.Changes.
astr_main_agent.py— degrade the twoRecordbranches (current message and quoted chain) the way the siblingImagebranches already do: log a warning and append a text placeholder instead of propagating. BecauseRecordand the audio converter raise bare exceptions, these branches must degrade unconditionally rather than going throughis_recoverable_image_error().asyncio.CancelledErroris aBaseExceptionand still propagates.agent_sub_stages/third_party.py— theRecordandImagebranches of the third-party request build have the same unguarded calls. That build sits upstream of the file's onlytryblock, andpipeline/scheduler.pyhas afinallybut noexcept(the event bus only logs), so a failure there loses the whole turn silently — strictly harder to diagnose than the local path's visible error. Guard both.This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Five new unit tests in
tests/unit/test_astr_main_agent.pyandtests/unit/test_third_party_agent_sub_stage.pycover:[Voice unavailable]instead of raising (both paths);RecordandImagebranches degrade;asyncio.CancelledErrorstill propagates — regression guard.Negative control (the two source files reverted to their unpatched state, all new tests kept): exactly the 3 degradation tests fail with
not a valid file:/ValueError, and all pass with the patch. The other 2 tests are regression guards and correctly pass in both states.Checklist / 检查清单
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
/ 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。/ 我的更改没有引入恶意代码。
Summary by Sourcery
Gracefully degrade unavailable image and voice attachments so media resolution failures no longer interrupt agent turns.
Bug Fixes:
[Voice unavailable]placeholder.Enhancements:
Tests: