fix: 中断对话时添加 is_interrupted 标记并优化 abort 响应速度
- QueryEngine: result 消息新增 is_interrupted 字段,标识用户中断 - sessionHandle: abort() 不再等待子进程退出,改为等待 result 事件(2s 超时兜底)
This commit is contained in:
parent
6274c0e2be
commit
265ff7d864
|
|
@ -1116,6 +1116,7 @@ export class QueryEngine {
|
||||||
duration_ms: Date.now() - startTime,
|
duration_ms: Date.now() - startTime,
|
||||||
duration_api_ms: getTotalAPIDuration(),
|
duration_api_ms: getTotalAPIDuration(),
|
||||||
is_error: true,
|
is_error: true,
|
||||||
|
is_interrupted: this.abortController.signal.aborted,
|
||||||
num_turns: turnCount,
|
num_turns: turnCount,
|
||||||
stop_reason: lastStopReason,
|
stop_reason: lastStopReason,
|
||||||
session_id: getSessionId(),
|
session_id: getSessionId(),
|
||||||
|
|
@ -1128,11 +1129,6 @@ export class QueryEngine {
|
||||||
initialAppState.fastMode,
|
initialAppState.fastMode,
|
||||||
),
|
),
|
||||||
uuid: randomUUID(),
|
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: (() => {
|
errors: (() => {
|
||||||
const all = getInMemoryErrors()
|
const all = getInMemoryErrors()
|
||||||
const start = errorLogWatermark
|
const start = errorLogWatermark
|
||||||
|
|
|
||||||
|
|
@ -684,18 +684,19 @@ export class SessionHandle {
|
||||||
})
|
})
|
||||||
this.writeStdin(interrupt)
|
this.writeStdin(interrupt)
|
||||||
|
|
||||||
|
if (!this.promptResolve) return
|
||||||
|
|
||||||
await new Promise<void>(resolve => {
|
await new Promise<void>(resolve => {
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
this.kill()
|
this.kill()
|
||||||
resolve()
|
resolve()
|
||||||
}, 5000)
|
}, 2000)
|
||||||
const check = setInterval(() => {
|
const originalResolve = this.promptResolve
|
||||||
if (!this.child || this.child.killed) {
|
this.promptResolve = (value) => {
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
clearInterval(check)
|
originalResolve?.(value)
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
}, 200)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user