Conversation
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/provider/provider.py" line_range="43-45" />
<code_context>
provider_config.get("custom_headers")
)
+ def _retry_log_metadata(self, model: str | None = None) -> dict[str, str]:
+ """Build identifying context for provider request retry logs."""
+ provider_config = getattr(self, "provider_config", None) or {}
+ metadata = {"provider_id": str(provider_config.get("id", "default"))}
+ resolved_model = (
+ model if model is not None else getattr(self, "model_name", None)
+ )
+ if resolved_model:
+ metadata["model"] = str(resolved_model)
+ return metadata
+
def set_model(self, model_name: str) -> None:
</code_context>
<issue_to_address>
**nitpick (bug_risk):** The helper falls back to `self.model_name` whenever no request model is supplied, and all `get_models()` calls invoke it without a model. When a provider has a configured model, a retry from `client.models.list()` is therefore logged as if it were a request for that model, even though the model-list request does not target it.
**Triggers:** When the model catalog request fails for a provider whose `model_name` is configured, which is the normal provider configuration.
**Suggested fix:** Pass `model=None` without falling back to `self.model_name` for model-catalog requests, or add a separate metadata helper that includes only the provider ID for `get_models()`.
```suggestion
resolved_model = model
```
</issue_to_address>Sourcery assessment
Approved.
| resolved_model = ( | ||
| model if model is not None else getattr(self, "model_name", None) | ||
| ) |
There was a problem hiding this comment.
nitpick (bug_risk): The helper falls back to self.model_name whenever no request model is supplied, and all get_models() calls invoke it without a model. When a provider has a configured model, a retry from client.models.list() is therefore logged as if it were a request for that model, even though the model-list request does not target it.
Triggers: When the model catalog request fails for a provider whose model_name is configured, which is the normal provider configuration.
Suggested fix: Pass model=None without falling back to self.model_name for model-catalog requests, or add a separate metadata helper that includes only the provider ID for get_models().
| resolved_model = ( | |
| model if model is not None else getattr(self, "model_name", None) | |
| ) | |
| resolved_model = model |
Motivation
Fixes #9453
Retryable provider request failures currently identify the adapter label, such as OpenAI or Gemini, but not the configured provider instance or model. This makes it hard to decide which model to switch when several providers use the same adapter.
Modifications / 改动点
Added optional
provider_idandmodelcontext to provider retry logging.Added a reusable provider metadata helper without changing provider behavior.
Passed request-specific model and configured provider IDs through OpenAI Chat Completions, OpenAI Responses, Gemini, Anthropic, and SSYCloud retry calls.
Preserved the existing log format when no metadata is supplied.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
uv run pytest -q tests/test_request_retry.py tests/test_openai_source.py tests/test_gemini_source.py tests/test_anthropic_kimi_code_provider.py: 114 passed.uv run pytest -q: 3527 passed, 82 skipped.uv run ruff format --check .: passed.uv run ruff check .: passed.git diff --check: passed.Checklist / 检查清单
Summary by Sourcery
Identify the configured provider instance and model in retry logs to make provider request failures easier to diagnose.
New Features:
Enhancements:
Tests: