Repository navigation
fix(channels): handle dict type for custom channels in manager.py 解决自定义频道中dict类型无法被正确读取问题 - #1991
Conversation
# Handle both Pydantic objects (built-in) and dicts (custom channels)
|
Thank you for your contribution. Please run |
|
已完成 pre-commit run --all-files 已提交 |
Welcome to CoPaw! 🎉Thank you @f3125472 for your first contribution! Your PR has been merged. 🚀 We'd love to give you a shout-out in our release notes! If you're comfortable sharing, please reply to this comment with your social media handles using the format below:
Thanks again for helping make CoPaw better! |
…gentscope-ai#1991) Co-authored-by: unknown <[email protected]>
Handle both Pydantic objects (built-in) and dicts (custom channels)
Description
[English]
Fix custom channels not starting due to
getattr()being used on dict type configurations inChannelManager.Custom channel configurations are stored as
dictin Pydantic's__pydantic_extra__, while built-in channel configurations are Pydantic objects. The code usesgetattr()to access configuration fields, which works for objects but returns the default value for dicts.This PR adds
isinstance()checks for all three affected fields:enabled(line 196)filter_tool_messages(line 200-204)filter_thinking(line 205-209)[中文]
修复
ChannelManager中因对 dict 类型配置使用getattr()导致自定义通道无法启动的问题。自定义通道配置作为
dict存储在 Pydantic 的__pydantic_extra__中,而内置通道配置是 Pydantic 对象。代码使用getattr()访问配置字段,这对对象有效,但对 dict 返回默认值。本 PR 为所有三个受影响字段添加
isinstance()检查:enabled(第 196 行)filter_tool_messages(第 200-204 行)filter_thinking(第 205-209 行)Related Issue: Fixes #(issue_number) or Relates to #(issue_number) Fixes #1987
Security Considerations: [If applicable, e.g. channel auth, env/config handling]
None - This is a type handling fix that does not affect authentication or expose sensitive configuration.
无 - 这是类型处理修复,不影响认证或暴露敏感配置。
Type of Change
Component(s) Affected
Checklist
pre-commit run --all-fileslocally and it passespytestor as relevant) and they passNote: Pre-commit and pytest not applicable for this minimal fix. Manual testing performed with custom WebSocket channel (CoCoPaw) and verified successful startup.
说明: 此修复为最小化改动,未运行 pre-commit 和 pytest。已手动测试自定义 WebSocket 通道(CoCoPaw),验证启动成功。
Testing
[English]
Manual Testing Steps:
Create custom channel in
~/.copaw/custom_channels/cocopaw/Enable channel in
~/.copaw/workspaces/default/agent.json:{ "channels": { "cocopaw": { "enabled": true, "filter_tool_messages": true, "filter_thinking": true } } }Run
copaw appObserve logs:
Before fix / 修复前:
After fix / 修复后 (Actual logs):
Verify port listening / 验证端口监听:
[中文]
手动测试步骤:
在
~/.copaw/custom_channels/cocopaw/中创建自定义通道在
~/.copaw/workspaces/default/agent.json中启用通道:{ "channels": { "cocopaw": { "enabled": true, "filter_tool_messages": true, "filter_thinking": true } } }运行
copaw app观察日志:
修复前:
修复后(实际日志):
验证端口监听:
Local Verification Evidence
Additional Notes
[English]
Bug Root Cause:
ChannelConfigclass with type annotations__pydantic_extra__asdictgetattr(ch_cfg, "enabled", False)returnsFalsefor dict types (ignores the actual value)isinstance()to check type before accessing fieldsCode Changes:
src/copaw/app/channels/manager.pyisinstance()check before usinggetattr()Impact:
[中文]
Bug 根本原因:
ChannelConfig类中定义,有类型注解dict存储在__pydantic_extra__中getattr(ch_cfg, "enabled", False)对 dict 类型返回False(忽略实际值)isinstance()在访问字段前检查类型代码变更:
src/copaw/app/channels/manager.pygetattr()前添加isinstance()检查影响范围:
Code Diff