From db3df0688bcafc1f850e67fa5658e7e220bba175 Mon Sep 17 00:00:00 2001 From: zhi Date: Sat, 28 Feb 2026 19:41:59 +0000 Subject: [PATCH] fix: add turn check debug logs + fallback to ctx.accountId - Add detailed debug log for turn check showing agentId, resolvedAccountId, ctxAccountId, turnOrderLen - Add fallback: if resolveAccountId fails, use ctx.accountId directly --- plugin/index.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/plugin/index.ts b/plugin/index.ts index 0abe30c..377b4b3 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -623,7 +623,28 @@ export default { // This ensures only the current speaker can respond even for human messages. if (derived.channelId) { ensureTurnOrder(api, derived.channelId); - const accountId = resolveAccountId(api, ctx.agentId || ""); + + // Try resolveAccountId first, fall back to ctx.accountId if not found + let accountId = resolveAccountId(api, ctx.agentId || ""); + + // Debug log for turn check - log all available identifiers + if (shouldDebugLog(live, derived.channelId)) { + const turnDebug = getTurnDebugInfo(derived.channelId); + api.logger.info( + `whispergate: turn check preflight ` + + `agentId=${ctx.agentId ?? "undefined"} ` + + `resolvedAccountId=${accountId ?? "undefined"} ` + + `ctxAccountId=${ctx.accountId ?? "undefined"} ` + + `turnOrderLen=${turnDebug.turnOrder?.length ?? 0} ` + + `currentSpeaker=${turnDebug.currentSpeaker ?? "null"}`, + ); + } + + // Fallback to ctx.accountId if resolveAccountId failed + if (!accountId && ctx.accountId) { + accountId = String(ctx.accountId); + } + if (accountId) { const turnCheck = checkTurn(derived.channelId, accountId); if (!turnCheck.allowed) {