mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-28 20:04:26 +00:00
fix(agent): unregister temporal cancellation listener on completion
This commit is contained in:
@@ -195,6 +195,7 @@ describe('Agent Activities', () => {
|
||||
} as unknown as AgentExecutionContext
|
||||
|
||||
const addEventListenerSpy = vi.spyOn(mockTemporalContext.cancellationSignal, 'addEventListener')
|
||||
const removeEventListenerSpy = vi.spyOn(mockTemporalContext.cancellationSignal, 'removeEventListener')
|
||||
|
||||
const executionPromise = agentChatActivity({
|
||||
teamId: 't1',
|
||||
@@ -223,7 +224,9 @@ describe('Agent Activities', () => {
|
||||
})
|
||||
|
||||
await executionPromise
|
||||
expect(removeEventListenerSpy).toHaveBeenCalledWith('abort', expect.any(Function))
|
||||
addEventListenerSpy.mockRestore()
|
||||
removeEventListenerSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should include error message in text when stopReason is error', async () => {
|
||||
|
||||
@@ -153,6 +153,10 @@ If you need to create files in the local filesystem (for example, a temporary fi
|
||||
|
||||
let heartbeatInterval: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const onAbort = () => {
|
||||
harness.abort()
|
||||
}
|
||||
|
||||
let temporalSignal: EventTarget | undefined
|
||||
try {
|
||||
temporalSignal = Context.current().cancellationSignal
|
||||
@@ -161,13 +165,7 @@ If you need to create files in the local filesystem (for example, a temporary fi
|
||||
}
|
||||
|
||||
if (temporalSignal) {
|
||||
temporalSignal.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
harness.abort()
|
||||
},
|
||||
{ once: true },
|
||||
)
|
||||
temporalSignal.addEventListener('abort', onAbort, { once: true })
|
||||
|
||||
heartbeatInterval = setInterval(() => {
|
||||
try {
|
||||
@@ -259,6 +257,9 @@ If you need to create files in the local filesystem (for example, a temporary fi
|
||||
if (heartbeatInterval) {
|
||||
clearInterval(heartbeatInterval)
|
||||
}
|
||||
if (temporalSignal) {
|
||||
temporalSignal.removeEventListener('abort', onAbort)
|
||||
}
|
||||
if (params.taskId) {
|
||||
unregisterLocalCancelHandler(params.taskId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user