From 265ff7d8648d472f59d1b518059d6984eda13c96 Mon Sep 17 00:00:00 2001 From: DoSun Date: Sat, 9 May 2026 16:37:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=AD=E6=96=AD=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=97=B6=E6=B7=BB=E5=8A=A0=20is=5Finterrupted=20=E6=A0=87?= =?UTF-8?q?=E8=AE=B0=E5=B9=B6=E4=BC=98=E5=8C=96=20abort=20=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - QueryEngine: result 消息新增 is_interrupted 字段,标识用户中断 - sessionHandle: abort() 不再等待子进程退出,改为等待 result 事件(2s 超时兜底) --- src/QueryEngine.ts | 6 +----- src/server/sessionHandle.ts | 17 +++++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/QueryEngine.ts b/src/QueryEngine.ts index 6704dac68..030d93f0c 100644 --- a/src/QueryEngine.ts +++ b/src/QueryEngine.ts @@ -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 diff --git a/src/server/sessionHandle.ts b/src/server/sessionHandle.ts index 9482894b6..500627029 100644 --- a/src/server/sessionHandle.ts +++ b/src/server/sessionHandle.ts @@ -684,18 +684,19 @@ export class SessionHandle { }) this.writeStdin(interrupt) + if (!this.promptResolve) return + await new Promise(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() + } }) }