mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 08:45:50 +00:00
fix: 修复部分溢出的问题
This commit is contained in:
12
src/query.ts
12
src/query.ts
@@ -330,6 +330,11 @@ async function* queryLoop(
|
|||||||
// sites.
|
// sites.
|
||||||
let taskBudgetRemaining: number | undefined = undefined
|
let taskBudgetRemaining: number | undefined = undefined
|
||||||
|
|
||||||
|
// Guard against stop_hook_blocking infinite loops (see ~line 1326).
|
||||||
|
// Loop-local to avoid touching the 7 continue sites on State.
|
||||||
|
const MAX_STOP_HOOK_BLOCKING_RETRIES = 3
|
||||||
|
let stopHookBlockingCount = 0
|
||||||
|
|
||||||
// Snapshot immutable env/statsig/session state once at entry. See QueryConfig
|
// Snapshot immutable env/statsig/session state once at entry. See QueryConfig
|
||||||
// for what's included and why feature() gates are intentionally excluded.
|
// for what's included and why feature() gates are intentionally excluded.
|
||||||
const config = buildQueryConfig()
|
const config = buildQueryConfig()
|
||||||
@@ -1324,6 +1329,13 @@ async function* queryLoop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stopHookResult.blockingErrors.length > 0) {
|
if (stopHookResult.blockingErrors.length > 0) {
|
||||||
|
stopHookBlockingCount++
|
||||||
|
if (stopHookBlockingCount > MAX_STOP_HOOK_BLOCKING_RETRIES) {
|
||||||
|
yield createAssistantAPIErrorMessage({
|
||||||
|
content: `Stop hook blocked ${stopHookBlockingCount} times — stopping to prevent infinite loop.`,
|
||||||
|
})
|
||||||
|
return { reason: 'completed' }
|
||||||
|
}
|
||||||
const next: State = {
|
const next: State = {
|
||||||
messages: [
|
messages: [
|
||||||
...messagesForQuery,
|
...messagesForQuery,
|
||||||
|
|||||||
@@ -505,6 +505,7 @@ export class AcpAgent implements Agent {
|
|||||||
includePartialMessages: true,
|
includePartialMessages: true,
|
||||||
replayUserMessages: true,
|
replayUserMessages: true,
|
||||||
initialMessages: opts.initialMessages,
|
initialMessages: opts.initialMessages,
|
||||||
|
maxTurns: 200,
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryEngine = new QueryEngine(engineConfig)
|
const queryEngine = new QueryEngine(engineConfig)
|
||||||
|
|||||||
@@ -573,6 +573,7 @@ export async function forwardSessionUpdates(
|
|||||||
// Race the next message against the abort signal so we unblock
|
// Race the next message against the abort signal so we unblock
|
||||||
// immediately when cancelled, even if the generator is waiting for
|
// immediately when cancelled, even if the generator is waiting for
|
||||||
// a slow API response.
|
// a slow API response.
|
||||||
|
let abortHandler: (() => void) | undefined
|
||||||
const nextResult = await Promise.race([
|
const nextResult = await Promise.race([
|
||||||
sdkMessages.next(),
|
sdkMessages.next(),
|
||||||
new Promise<IteratorResult<SDKMessage, void>>((resolve) => {
|
new Promise<IteratorResult<SDKMessage, void>>((resolve) => {
|
||||||
@@ -580,10 +581,14 @@ export async function forwardSessionUpdates(
|
|||||||
resolve({ done: true, value: undefined })
|
resolve({ done: true, value: undefined })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const handler = () => resolve({ done: true, value: undefined })
|
abortHandler = () => resolve({ done: true, value: undefined })
|
||||||
abortSignal.addEventListener('abort', handler, { once: true })
|
abortSignal.addEventListener('abort', abortHandler, { once: true })
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
|
// Clean up: remove un-fired listener when generator completes first
|
||||||
|
if (abortHandler) {
|
||||||
|
abortSignal.removeEventListener('abort', abortHandler)
|
||||||
|
}
|
||||||
if (nextResult.done || abortSignal.aborted) break
|
if (nextResult.done || abortSignal.aborted) break
|
||||||
const msg = nextResult.value
|
const msg = nextResult.value
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user