8 Commits

Author SHA1 Message Date
oudecheng
e037de88a2 fix(agent,gateway): 替换 unreachable!() 为防御性错误返回
将 run_final_summary 和 send_with_retry 中的 unreachable!() 替换为
错误返回,避免未来重构导致循环体未返回时 panic 终止所有会话。

- agent_loop.rs: run_final_summary 兜底构造错误 AgentProcessResult,
  含 emit_live_tool_call_message 推送,与 Err 不可重试路径一致
- outbound_dispatcher.rs: send_with_retry 兜底返回 ChannelError::SendError,
  覆盖 RETRY_DELAYS_SECS 为空数组的边界情况

同时 outbound_dispatcher.rs 包含优先级队列重构:高优消息使用独立
high 队列和扩展重试策略,保证最终响应不被中间过程挤占丢弃。
2026-08-06 10:01:02 +08:00
oudecheng
6fc6d5628f perf(gateway): send_with_retry 对 ChannelFull 不重试,加速队列消费
ws 连接队列满时,sender task 原本重试 3 次浪费 1+2+4=7s,期间 channel 队列堆积。新增 ChannelError::ChannelFull 变体区分队列满错误,CliChannel::send 在 try_send Full 时返回该变体;send_with_retry 遇到 ChannelFull 立即返回不重试,sender task 记 warn(预期背压丢弃)而非 error。

- base.rs: 新增 ChannelFull 变体及 Display 实现
- cli.rs: try_send 错误区分 Full(ChannelFull,不可重试)与 Closed(SendError,可重试)
- outbound_dispatcher.rs: send_with_retry 短路返回 ChannelFull;run_sender_task 区分日志级别;新增 TestChannel.with_channel_full 及单测验证不重试(500ms 阈值内返回 + send 仅调用一次)
2026-08-05 11:14:53 +08:00
oudecheng
2e4b1931a6 feat(tokens): 添加 topic 维度 token 消耗与上下文窗口占用统计
后端:
- openai provider 流式响应启用 stream_options.include_usage,从 SSE 末帧捕获 usage
- ChatMessage 新增 MessageUsage(prompt/completion/total/context_window_tokens)
- agent_loop 三处 LLM 调用点持久化 usage,含 context_window_tokens
- storage 新增 context_window_tokens 列及 migration,batch_session_token_stats 聚合查询
- last_prompt_tokens 查询过滤 prompt_tokens IS NOT NULL,跳过 error/cancel 消息
- build_topic_summaries 简化签名,context_window_tokens 从消息记录读取
- protocol 扩展 TopicTokenStats,按 session_id 聚合天然隔离子代理

前端:
- protocol.ts 新增 TopicTokenStats 类型
- useTopics 映射 token_stats 到 Topic
- TopicList 展示总 token 消耗与上下文占用百分比(绿/黄/红三色)

测试:outbound_dispatcher 4 个测试修复(drop(bus) 不关闭 bus,改用 abort)
2026-08-04 17:01:54 +08:00
988e77123c feat: 精简日志记录,移除冗余信息,优化调试输出 2026-06-06 10:41:52 +08:00
fb90641774 feat: 增强日志记录,添加消息处理和工具执行的详细信息 2026-06-06 09:26:50 +08:00
oudecheng
eebfe0faa5 feat: 增强错误处理和日志记录,优雅处理通道关闭情况 2026-06-02 15:23:50 +08:00
oudecheng
83b525e442 feat: 添加虚拟调度器聊天 ID 前缀,跳过不应发送到外部通道的消息 2026-05-09 17:20:02 +08:00
6756a3d0ae feat: 添加 OutboundDispatcher 模块,重构消息分发逻辑,优化渠道消息处理
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 14:52:33 +08:00