fix: check done flag at top of event loop

state.done = true → все последующие события пропускаются
на уровне цикла, до любых handlers. Включая text.ended,
step.started, reasoning.*, tool.*.
This commit is contained in:
Бородин Роман 2026-09-26 10:27:37 +03:00
parent 650fa4a631
commit a91cac7131
1 changed files with 6 additions and 0 deletions

View File

@ -147,6 +147,10 @@ async function runPlugin(ctx: any, options: any, dataDir: string) {
const sessionId = eventData?.data?.sessionID || ""
const assistantMsgID = eventData?.data?.assistantMessageID || ""
// Skip all events after session is done
const state = sessionsBySessionID.get(sessionId)
if (state?.done) continue
// ── Step lifecycle ──────────────────────────────────────────────
if (eventType === "session.step.started") {
@ -242,6 +246,8 @@ async function runPlugin(ctx: any, options: any, dataDir: string) {
if (eventType === "session.text.ended" && assistantMsgID) {
const state = sessionsBySessionID.get(sessionId)
// Skip text events after final step
if (state?.done) continue
const step = state?.steps.get(assistantMsgID)
if (step) {
step.text = eventData?.data?.text || ""