fix(aibox): v2.6 - 修复Ctrl+C中断无法停止服务器的问题
问题根因: 1. WebSocketHandler.handle_message 完全没有处理 interrupt 消息类型(前端Ctrl+C发送的消息被丢弃) 2. DeepSeekChat 缺少取消机制,阻塞的 API 请求(iter_lines)和子进程无法被中断 修复方案 - 三层取消机制: 1. threading.Event 取消标志:流式响应循环每轮检查 _is_cancelled(),工具调用前检查 2. HTTP连接关闭:保存 _current_response 引用,cancel() 时调用 response.close() 中断 iter_lines() 3. 子进程终止:SubprocessCommandExecutor 添加 cancel() 方法,保存 _current_process,cancel时kill 修改内容: - DeepSeekChat: 添加 _cancel_event/_current_response/_command_executor 字段,cancel()/_is_cancelled()/_check_cancelled() 方法 - SubprocessCommandExecutor: 添加 __init__/_process_lock/cancel(),execute()/execute_streaming() 中设置和清除进程引用 - WebSocketHandler: 添加 handle_interrupt() 处理 interrupt 消息,回复 interrupt_ack 后调用 ai_manager.cancel() - EnhancedAIManager: 添加 cancel() 统一入口,同时取消AI和命令执行器 - think_and_respond: 首轮清除cancel标志,流式循环检查取消,API/JSON/未知异常中均检查取消标志 - _handle_tool_calls: 每个工具调用前检查取消信号 - 更新README v2.6日志和API文档
This commit is contained in:
1 parent
b935fefb82
commit
9d737897df
2 files changed
+162
-1
No files matched your search
@@ -21,6 +21,7 @@
|
||||
- 📦 **对话压缩**:消息数或 Token 数达到阈值时自动压缩,保持上下文质量
|
||||
- 🛡️ **内存安全防护**:文件读取按需加载不全载、命令输出 1MB 限制、单行超长截断、工具结果多层防护防止 OOM
|
||||
- 🔒 **错误自动恢复**:API 请求失败自动回滚消息,工具结果安全清洗(控制字符过滤、非字符串转换)
|
||||
- 🛑 **可靠中断机制**:支持 Ctrl+C 实时中断,通过 `threading.Event` + HTTP 连接关闭 + 子进程 kill 三层取消,流式响应和长时间运行命令均可立即终止
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
@@ -192,6 +193,15 @@ const ws = new WebSocket('ws://localhost:8765');
|
||||
}
|
||||
```
|
||||
|
||||
#### 5. 中断(Ctrl+C)
|
||||
```json
|
||||
{
|
||||
"type": "interrupt",
|
||||
"content": "用户按下了 Ctrl+C 中断当前操作"
|
||||
}
|
||||
```
|
||||
服务端收到后立即回复 `interrupt_ack`,并通过三层取消机制(Event标志 + HTTP连接关闭 + 子进程kill)终止正在进行的AI思考和工具执行。
|
||||
|
||||
### 支持的命令
|
||||
|
||||
> 注意:记忆搜索通过 `memory` 工具(在对话中由 AI 调用)完成,本系统**不存在** `/search` 斜杠命令。
|
||||
@@ -706,6 +716,19 @@ elif command == "/mycommand":
|
||||
|
||||
## 📄 更新日志
|
||||
|
||||
### v2.6
|
||||
- ✅ **修复 Ctrl+C 中断无法停止服务器的问题**:
|
||||
- 新增 `interrupt` WebSocket 消息类型处理(BotOps 前端 Ctrl+C 发送此消息),立即回复 `interrupt_ack` 确认
|
||||
- `DeepSeekChat` 新增 `cancel()` 方法和 `_cancel_event`(threading.Event),线程安全可跨线程调用
|
||||
- **三层取消机制**:
|
||||
1. 设置取消标志,流式响应循环每轮检查,发现取消立即 break
|
||||
2. 关闭当前 HTTP response 对象,中断 `iter_lines()` 阻塞读取
|
||||
3. 终止正在运行的子进程(`SubprocessCommandExecutor.cancel()` → `process.kill()`)
|
||||
- 工具调用循环中每个工具执行前检查取消信号,中断后不再继续后续工具
|
||||
- API 请求异常/JSON解析异常/未知异常中均检查取消标志,若因取消导致异常则按中断处理而非报错
|
||||
- 中断后自动回滚本轮消息,防止污染对话历史
|
||||
- 新增 `EnhancedAIManager.cancel()` 统一入口,同时终止 AI 和命令执行器
|
||||
|
||||
### v2.5
|
||||
- ✅ **新增 DeepSeek 思考模式支持**(Reasoning Mode):
|
||||
- 新增 `api.reasoning_enabled` 配置项(默认 `false`),启用后在请求中添加 `thinking: {type: "enabled"}` 参数
|
||||
|
||||
Reference in new issue
Block a user