fix: 中断对话时添加 is_interrupted 标记并优化 abort 响应速度

- QueryEngine: result 消息新增 is_interrupted 字段,标识用户中断
- sessionHandle: abort() 不再等待子进程退出,改为等待 result 事件(2s 超时兜底)
This commit is contained in:
DoSun 2026-05-09 16:37:03 +08:00
parent 6274c0e2be
commit 265ff7d864
2 changed files with 10 additions and 13 deletions

View File

@ -1116,6 +1116,7 @@ export class QueryEngine {
duration_ms: Date.now() - startTime,
duration_api_ms: getTotalAPIDuration(),
is_error: true,
is_interrupted: this.abortController.signal.aborted,
num_turns: turnCount,
stop_reason: lastStopReason,
session_id: getSessionId(),
@ -1128,11 +1129,6 @@ export class QueryEngine {
initialAppState.fastMode,
),
uuid: randomUUID(),
// Diagnostic prefix: these are what isResultSuccessful() checks — if
// the result type isn't assistant-with-text/thinking or user-with-
// tool_result, and stop_reason isn't end_turn, that's why this fired.
// errors[] is turn-scoped via the watermark; previously it dumped the
// entire process's logError buffer (ripgrep timeouts, ENOENT, etc).
errors: (() => {
const all = getInMemoryErrors()
const start = errorLogWatermark

View File

@ -684,18 +684,19 @@ export class SessionHandle {
})
this.writeStdin(interrupt)
if (!this.promptResolve) return
await new Promise<void>(resolve => {
const timeout = setTimeout(() => {
this.kill()
resolve()
}, 5000)
const check = setInterval(() => {
if (!this.child || this.child.killed) {
clearTimeout(timeout)
clearInterval(check)
resolve()
}
}, 200)
}, 2000)
const originalResolve = this.promptResolve
this.promptResolve = (value) => {
clearTimeout(timeout)
originalResolve?.(value)
resolve()
}
})
}