fix: skip steps after finish:stop, no setTimeout
После finish:stop — все последующие step-события это дубликаты/ перепроекция. Пропускаем их через флаг done. Убран setTimeout cleanup — чистка синхронная.
This commit is contained in:
parent
b97c82910c
commit
650fa4a631
10
index.ts
10
index.ts
|
|
@ -126,6 +126,7 @@ async function runPlugin(ctx: any, options: any, dataDir: string) {
|
||||||
currentStepID: string | null
|
currentStepID: string | null
|
||||||
context: MatrixEventContext
|
context: MatrixEventContext
|
||||||
finalResponse?: string
|
finalResponse?: string
|
||||||
|
done: boolean // true после finish:stop
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionsBySessionID = new Map<string, SessionState>()
|
const sessionsBySessionID = new Map<string, SessionState>()
|
||||||
|
|
@ -253,6 +254,10 @@ async function runPlugin(ctx: any, options: any, dataDir: string) {
|
||||||
|
|
||||||
if (eventType === "session.step.ended" && sessionId && assistantMsgID) {
|
if (eventType === "session.step.ended" && sessionId && assistantMsgID) {
|
||||||
const state = sessionsBySessionID.get(sessionId)
|
const state = sessionsBySessionID.get(sessionId)
|
||||||
|
|
||||||
|
// Skip steps after final (finish:stop) — they are re-projections/duplicates
|
||||||
|
if (state?.done) continue
|
||||||
|
|
||||||
const step = state?.steps.get(assistantMsgID)
|
const step = state?.steps.get(assistantMsgID)
|
||||||
const finish = eventData?.data?.finish || ""
|
const finish = eventData?.data?.finish || ""
|
||||||
|
|
||||||
|
|
@ -262,13 +267,15 @@ async function runPlugin(ctx: any, options: any, dataDir: string) {
|
||||||
log(`Step ${step.tools.length} tool(s), ${step.text.length} chars text → sent to ${state.context.roomId}`)
|
log(`Step ${step.tools.length} tool(s), ${step.text.length} chars text → sent to ${state.context.roomId}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is the final step, resolve the pending promise
|
// If this is the final step, mark done and resolve the pending promise
|
||||||
if (finish === "stop" && state) {
|
if (finish === "stop" && state) {
|
||||||
|
state.done = true
|
||||||
const pending = pendingResponses.get(sessionId)
|
const pending = pendingResponses.get(sessionId)
|
||||||
if (pending && state.finalResponse) {
|
if (pending && state.finalResponse) {
|
||||||
pendingResponses.delete(sessionId)
|
pendingResponses.delete(sessionId)
|
||||||
pending.resolve(state.finalResponse)
|
pending.resolve(state.finalResponse)
|
||||||
}
|
}
|
||||||
|
sessionsBySessionID.delete(sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
@ -430,6 +437,7 @@ async function runPlugin(ctx: any, options: any, dataDir: string) {
|
||||||
currentStepID: null,
|
currentStepID: null,
|
||||||
context,
|
context,
|
||||||
finalResponse: undefined,
|
finalResponse: undefined,
|
||||||
|
done: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Wait for response text from event subscription
|
// Wait for response text from event subscription
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue