Repository navigation
fix: warn when a configured provider is silently substituted - #10846
JosephTian876 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/unit/test_provider_fallback_warning.py" line_range="50" />
<code_context>
+ mgr.tts_provider_insts = []
+ mgr.decision_provider_insts = []
+ mgr.curr_decision_provider_inst = None
+ mgr._fallback_warned = set()
+ mgr.acm = MagicMock()
+ return mgr
</code_context>
<issue_to_address>
**Constructor failure is masked**
When `ProviderManager.__init__` omits initialization of `_fallback_warned`, when `ProviderManager.__init__` stops initializing `_fallback_warned`, the warning tests still pass because the `manager` fixture assigns it directly; a real manager then raises `AttributeError` on fallback lookup instead of warning.
Exercise the real constructor in at least one warning test instead of supplying `_fallback_warned` in the fixture.
</issue_to_address>
### Comment 2
<location path="astrbot/core/provider/manager.py" line_range="398-406" />
<code_context>
+ if key in self._fallback_warned:
+ return
+ self._fallback_warned.add(key)
+ logger.warning(
+ "Configured %s provider `%s` is not available; falling back to `%s`. "
+ "This can happen while providers are still loading at startup, or "
+ "when the configured provider was renamed, disabled or removed. "
+ "The fallback may behave differently from the provider you selected.",
+ provider_type.value,
+ configured_id,
+ fallback_id,
+ )
+
async def initialize(self) -> None:
</code_context>
<issue_to_address>
**Fallback logging is offloaded**
When a configured provider is substituted, the configured-provider fallback warning and its deduplication are handled in `_warn_provider_fallback` rather than directly in `_resolve_using_provider`, contrary to the repository rule for logging and edge-case handling.
Handle the fallback warning and deduplication directly in `_resolve_using_provider`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: tests/unit/test_provider_fallback_warning.py:50
|
Since the last review:
Tests: Known limitation: the warning is emitted when a provider is resolved, so a configured substitution that nothing ever asks for produces no log line. |
506af21 to
a53c736
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
a53c736 to
00b6bd5
Compare
|
Rebased onto latest Local Verification
|
Modifications / 改动点
ProviderManager._resolve_using_provider()substitutes the first loaded provider whenever the configured provider ID cannot be resolved — and reports nothing. The warning written for this case sits after the substitution, so it can only fire when no provider exists at all:The one situation the user can do nothing about is reported; the situation that actually needs reporting ("the provider you configured is unavailable, so a different one answered") is silent. The substitute is picked by config array order, not capability, so a vision-only model can answer a plain-text request with nothing in the log to point at it. The same shape covered chat, STT and TTS.
This PR does not change which provider is returned. It adds the missing report, once per
(provider_type, configured_id, fallback_id)— so a persistent condition cannot flood the log — and clears that record onreload()so a recurrence is reported again.Rebased onto
abf683071, which moved the body into_resolve_using_provider()and added aProviderType.DECISIONbranch. Adaptations: the chat provider is now read fromagent_runner.config.model.provider_idinstead ofprovider_settings.default_provider_id; decision providers carry no configured ID, so they are correctly unaffected.Screenshots or Test Results / 运行截图或测试结果
Diff scope: 1 production file (
astrbot/core/provider/manager.py,+38/-0; no test files modified in this PR).Local verification (12 standalone cases covering chat/STT/TTS fallback warnings, deduplication,
reload()reset, and quiet/normal cases — 8 failed onmaster, 12 passed with this branch; test file omitted from this PR diff to keep the change focused on the 38-line fix, happy to add compact tests if preferred). Surrounding existing test suites (test_decision_provider.py,test_process_stage_images.py,unit/test_astr_main_agent.py,unit/test_core_lifecycle.py,unit/test_kb_manager_resilience.py,unit/test_knowledge_base_service_contract.py,unit/test_provider_stats.py,unit/test_conversation_restart.py,unit/test_group_chat_context_wiring.py,unit/test_star_context.py) andruff check/ruff format --checkall pass cleanly.Checklist / 检查清单
docs/zh/docs/enneed no update.Supersedes #9484
#9484 was closed on 2026-10-12 by the staleness sweep with an invitation to rebase and reopen, not on its merits. GitHub refuses to reopen it:
PATCH /pulls/9484 {"state": "open"}returns HTTP 422state cannot be changed. The fix/silent-provider-fallback branch was force-pushed or recreated.This PR is the same change rebased onto currentmaster, so it supersedes #9484; the original description and discussion stay there.Suggested merge order
Independent from
#10845and#10895, though all three touchastrbot/core/provider/manager.py. Suggested order: #10845 → #10895 → #10846 (any order works with a minor rebase if needed).Summary by Sourcery
Report silent provider substitutions while preserving the existing fallback behavior.
Bug Fixes:
Enhancements:
Tests: