Repository navigation
修复 CLI 会话:客户端超时后取消在途任务,dispose 改为抢占式释放 - #1123
Merged
Merged
Conversation
…dispose preemptive
Contributor
|
@qcjySONG 我复测了
复测结果 macOS / Node 22.22.0 上 CJS、ESM 构建通过。8 个测试文件共 159 通过、1 失败、2 跳过。新版 CLI 断开后,本地模拟模型连接约 6 ms 关闭。原生 DuckDB 长查询可取消,两种情况下会话均能继续服务。GitHub 构建和预览为 |
yvonneyx
approved these changes
Nov 24, 2026
yvonneyx
added a commit
that referenced
this pull request
Nov 24, 2026
补齐 CLI 会话升级、释放与查询取消(基于 #1123)
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
前提
本次编码由AI(DeepSeek)完成,人工进行了相应的校验和测试
观察到的 BUG 现象
ava analyze超过 120 秒客户端超时后只放弃请求、服务端仍在继续执行并继续调用模型(客户端断开后还会多发一次模型请求),而ava dispose又排在这个运行中的任务之后才真正释放数据(实测 96 秒才返回),期间监听已先关闭,会话进入“端点已关、数据仍活”的半死状态且无法重试。复现方案
用仓库自带数据
data/companies.csv(company,region,revenue),并在模型前面放一个 OpenAI 兼容端点,把响应延迟到 120 秒以上;该端点的访问日志就是“服务端是否仍在调用模型”的证据:与 #1098(Windows 会话支持)的关系
#1098 引入的
transport.ts注释写明preserving Unix EOF framing,本次不改消息格式,只把 POSIX 的帧终止符由 EOF 改为\n(Windows 本来就是\n),理由是:socket.end(request)发完请求即半关闭;服务端allowHalfOpen: true,在工作期间收不到任何 socket 事件(埋点顺序为end→finish→close,finish/close只在服务端自己写完之后才出现),因此挂在close上的取消逻辑永远不会触发,客户端 120 秒后的destroy()也无法被感知;兼容性:
readMessage保留 EOF 兜底,旧客户端仍可连新守护进程;Windows 分支行为不变(未收到完整帧时的半关闭仍按原逻辑丢弃),cli-transport/cli-connection用例覆盖了分帧、UTF-8 跨块、EOF 兜底与断连取消。修复思路与改动文件
以可选
AbortSignal贯穿门面、分析策略、方言与引擎,使在途模型请求与查询真正可中断;会话层为每个连接建立AbortController,并把传输层的 EOF 分帧改为换行分帧(原有allowHalfOpen+ 客户端半关闭导致close永不触发),从而让“客户端断开”成为可观测事件并据此取消在途命令;dispose改为抢占式——先中止运行中与排队中的任务并置空数据集,再AVA.dispose(),最后才关闭监听、删除会话目录,响应写出后有界退出。改动文件:
src/util/abort.ts、src/types.ts、src/ava.ts、src/analysis/{direct,loop}.ts、src/query/*(7 个方言)、src/duckdb/engine.ts、src/remote/*/engine.ts、src/interpreter/*/engine.ts、src/visualization/{advisor,generator}.ts、src/cli/session/{transport,connection,server,datasets}.ts;测试:__tests__/{cli-transport,cli-connection,cancellation,cli-session}.test.ts。修复后测试方法和结果
方法:
tsc --noEmit与tsc构建通过;单元测试逐文件运行vitest(共 12 个文件,新增cli-transport、cli-connection、cancellation),这些用例用 mock 与本地引擎、不依赖真实模型,因此可在无密钥环境稳定重复;真实模型只用于对拍:data/companies.csv+ 延迟 130 秒的 OpenAI 兼容端点,跑修复前后同一时序对比。结果:12 个文件全部通过;对拍使用真实模型调用(
data/companies.csv,响应延迟 130 秒):dispose