Skip to content

fix: validate bool config values and add reasoning field schema - #9689

Open
Rain-0x01-39 wants to merge 2 commits into
AstrBotDevs:masterfrom
Rain-0x01-39:fix/provider-reasoning-validation
Open

fix: validate bool config values and add reasoning field schema#9689
Rain-0x01-39 wants to merge 2 commits into
AstrBotDevs:masterfrom
Rain-0x01-39:fix/provider-reasoning-validation

Conversation

@Rain-0x01-39

@Rain-0x01-39 Rain-0x01-39 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor
image Fixes bool config validation and adds missing reasoning field schema.

reasoning 字段缺少 schema 定义,Dashboard 无法正确展示而是降级为文本框。Provider config 中 bool 类型字段在 WebUI 保存时可能以字符串形式传入("true"/"false"),当前 validate() 会直接报类型错误而不是尝试转换。

Modifications / 改动点

  • default.py: 添加 reasoning 字段 schema(bool 类型)

  • config_service.py: try_cast() 新增 bool 转换,validate() bool 校验改为先尝试转换再报错

  • Dashboard i18n: 添加 reasoning 字段翻译(en/zh/ru)

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Validate boolean provider config values more robustly and expose the model reasoning capability flag in configuration metadata and dashboard UI.

New Features:

  • Add a boolean reasoning field to the default model configuration metadata to indicate reasoning capability and surface it in the dashboard with localized labels.

Bug Fixes:

  • Allow boolean config fields passed as string values (e.g., "true"/"false" or "1"/"0") to be cast and validated correctly instead of raising type errors in the dashboard config service.

Enhancements:

  • Extend dashboard localization files to include translations for the new reasoning configuration field in English, Chinese, and Russian.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Aug 14, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In validate() the bool branch assigns data[key] = casted even when casted is None, which both masks the original value and may introduce None into the config; consider only updating data[key] when casting succeeds.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `validate()` the bool branch assigns `data[key] = casted` even when `casted is None`, which both masks the original value and may introduce `None` into the config; consider only updating `data[key]` when casting succeeds.

## Individual Comments

### Comment 1
<location path="astrbot/dashboard/services/config_service.py" line_range="285-284" />
<code_context>
                     )
                 data[key] = casted
             elif meta["type"] == "bool" and not isinstance(value, bool):
-                errors.append(
-                    f"错误的类型 {path}{key}: 期望是 bool, 得到了 {type(value).__name__}",
-                )
+                casted = try_cast(value, "bool")
+                if casted is None:
+                    errors.append(
+                        f"错误的类型 {path}{key}: 期望是 bool, 得到了 {type(value).__name__}",
+                    )
+                data[key] = casted
             elif meta["type"] in ["string", "text"] and not isinstance(value, str):
                 errors.append(
</code_context>
<issue_to_address>
**issue (bug_risk):** Avoid assigning `data[key] = casted` when casting fails and returns `None`.

In the `bool` branch, `data[key]` is updated even when `casted` is `None`, so invalid values are both logged as errors and overwritten with `None`. This differs from other types, where the original value is kept on failure. Please only update `data[key]` when casting succeeds, e.g.:

```python
data[key] = casted if casted is not None else value
```

or skip assignment when `casted` is `None`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -276,9 +283,12 @@ def validate(data: dict, metadata: dict = schema, path="") -> None:
)
data[key] = casted

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Avoid assigning data[key] = casted when casting fails and returns None.

In the bool branch, data[key] is updated even when casted is None, so invalid values are both logged as errors and overwritten with None. This differs from other types, where the original value is kept on failure. Please only update data[key] when casting succeeds, e.g.:

data[key] = casted if casted is not None else value

or skip assignment when casted is None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant