You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
history 接口 500:工具输出 JSON 的 type 为对象时 enrich_media_block_preview 抛 TypeError: unhashable type: 'dict' #1869
File "src/octop/api/routers/chat/history.py", line 372, in get_thread_history
messages, has_more = _load_projected_thread_messages(
File "src/octop/api/routers/chat/serialize.py", line 479, in _load_projected_thread_messages
return _enrich_history_tool_media(out, agent_id=agent_id), has_more
File "src/octop/api/routers/chat/serialize.py", line 575, in _enrich_history_tool_media
new_output = enrich_tool_output_string_sync(output, agent_id=media_agent)
File "src/octop/infra/gateway/media/tool_media.py", line 534, in enrich_tool_output_string_sync
enriched = enrich_tool_message_content(output, agent_id=agent_id)
File "src/octop/infra/gateway/media/tool_media.py", line 367, in enrich_tool_message_content
return _map_content_blocks(
File "src/octop/infra/gateway/media/tool_media.py", line 313, in _map_content_blocks
return json.dumps(transform(parsed), ensure_ascii=False)
File "src/octop/infra/gateway/media/tool_media.py", line 369, in <lambda>
lambda block: enrich_media_block_preview(block, agent_id=agent_id),
File "src/octop/infra/gateway/media/tool_media.py", line 346, in enrich_media_block_preview
if not isinstance(block, dict) or block.get("type") not in _MEDIA_BLOCK_TYPES:
TypeError: unhashable type: 'dict'
(行号对应当前 main 分支的 tool_media.py。)
根因
_MEDIA_BLOCK_TYPES 是 frozenset。某些工具返回的 JSON 里,块的 type 字段不是字符串而是对象,例如:
Activity
JasonBuildAI commentedon Oct 10, 2026
复现并修好了,说明一下我理解的范围:issue 里的报错是
_MEDIA_BLOCK_TYPES(frozenset)的裸成员判断遇到非字符串type时抛TypeError: unhashable type: 'dict',这类块本应被当作非媒体块跳过。develop 上共 4 处同样的判断,除了 history 增强(enrich_media_block_preview、iter_media_blocks),_enrich_block_with_backend和block_to_content_part分别在实时工具结果增强和 IM 媒体投递路径上,所以同一份脏数据也可能打断流式回复而不是只影响历史页。改动是加一个只接受字符串类型的辅助函数并替换这 4 处,另补了 history 请求路径(_load_projected_thread_messages)的回归测试。PR 见 #1871;我没有加 issue 里建议的try/except兜底,理由放在 PR 描述里,如果更希望有兜底我再补。fix(gateway): ignore tool-output blocks whose media type is not a string
fix(gateway): ignore tool-output blocks whose media type is not a string
fix(gateway): ignore tool-output blocks whose media type is not a string
fix(gateway): ignore tool-output blocks whose media type is not a string