feat: 尝试改进 Error 处理以提升内存管理效率

This commit is contained in:
claude-code-best
2026-05-05 18:18:13 +08:00
parent d0915fc880
commit 18d6656a6a
4 changed files with 81 additions and 15 deletions

View File

@@ -340,6 +340,15 @@ export async function* query(
terminal?.reason === 'aborted_tools'
endTrace(langfuseTrace, undefined, isAborted ? 'interrupted' : undefined)
}
// Break the closure chain: toolUseContext captures langfuseTrace which
// holds SpanImpl → otperformance (the 571MB Performance object). Nulling
// these after endTrace allows GC to reclaim the span tree.
if (paramsWithTrace !== params) {
paramsWithTrace.toolUseContext.langfuseTrace = null
paramsWithTrace.toolUseContext.langfuseRootTrace = null
paramsWithTrace.toolUseContext.langfuseBatchSpan = null
}
}
// Only reached if queryLoop returned normally. Skipped on throw (error