mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
feat: ai 的随机修复
This commit is contained in:
21
src/query.ts
21
src/query.ts
@@ -124,6 +124,7 @@ import { count } from './utils/array.js'
|
||||
import {
|
||||
createTrace,
|
||||
endTrace,
|
||||
flushLangfuse,
|
||||
isLangfuseEnabled,
|
||||
} from './services/langfuse/index.js'
|
||||
import { getAPIProvider } from './utils/model/providers.js'
|
||||
@@ -339,6 +340,11 @@ export async function* query(
|
||||
terminal?.reason === 'aborted_streaming' ||
|
||||
terminal?.reason === 'aborted_tools'
|
||||
endTrace(langfuseTrace, undefined, isAborted ? 'interrupted' : undefined)
|
||||
// Flush the processor to release span data (including serialized
|
||||
// conversation history stored as langfuse.observation.input). Without
|
||||
// this, SpanImpl objects retain hundreds of KB of JSON until the
|
||||
// processor's batch timer fires (default 10s).
|
||||
await flushLangfuse()
|
||||
}
|
||||
|
||||
// Break the closure chain: toolUseContext captures langfuseTrace which
|
||||
@@ -349,6 +355,21 @@ export async function* query(
|
||||
paramsWithTrace.toolUseContext.langfuseRootTrace = null
|
||||
paramsWithTrace.toolUseContext.langfuseBatchSpan = null
|
||||
}
|
||||
|
||||
// Clear JSC's native Performance buffers. OTel (otperformance) references
|
||||
// globalThis.performance which stores marks/measures/resource timings in a
|
||||
// C++ Vector that never shrinks. Long-running sessions accumulate hundreds
|
||||
// of MB of dead capacity even after spans are flushed and nullified.
|
||||
const gPerf = globalThis.performance
|
||||
if (gPerf && typeof gPerf.clearMarks === 'function') {
|
||||
try {
|
||||
gPerf.clearMarks()
|
||||
gPerf.clearMeasures?.()
|
||||
gPerf.clearResourceTimings?.()
|
||||
} catch {
|
||||
// Non-critical — some environments may not support all methods
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only reached if queryLoop returned normally. Skipped on throw (error
|
||||
|
||||
Reference in New Issue
Block a user