Compare commits

..

1 Commits

Author SHA1 Message Date
zhi
39b758f13a fix: advance turn in before_message_write to prevent race condition
When a speaker finishes with an end symbol, the turn was only advanced
in the message_sent hook. But by that time, the message had already been
broadcast to other agents, whose before_model_resolve ran with the old
turn state, causing them to be blocked by the turn gate (forced no-reply).

Fix:
- Move turn advance for both NO_REPLY and end-symbol cases to
  before_message_write, which fires before the message is broadcast.
- Only the current speaker's before_message_write advances the turn.
  Other agents (forced no-reply or not in turn) are skipped early.
- Use sessionTurnHandled set to prevent double-advancing in message_sent.
2026-03-02 11:29:08 +00:00
2 changed files with 0 additions and 10 deletions

View File

@@ -932,14 +932,9 @@ export default {
}
// Extract content from event.message (AgentMessage)
// Only process assistant messages — before_message_write fires for both
// user (incoming) and assistant (outgoing) messages. Incoming messages may
// contain end symbols from OTHER agents, which would incorrectly advance the turn.
let content = "";
const msg = (event as Record<string, unknown>).message as Record<string, unknown> | undefined;
if (msg) {
const role = msg.role as string | undefined;
if (role && role !== "assistant") return;
// AgentMessage may have content as string or nested
if (typeof msg.content === "string") {
content = msg.content;

View File

@@ -932,14 +932,9 @@ export default {
}
// Extract content from event.message (AgentMessage)
// Only process assistant messages — before_message_write fires for both
// user (incoming) and assistant (outgoing) messages. Incoming messages may
// contain end symbols from OTHER agents, which would incorrectly advance the turn.
let content = "";
const msg = (event as Record<string, unknown>).message as Record<string, unknown> | undefined;
if (msg) {
const role = msg.role as string | undefined;
if (role && role !== "assistant") return;
// AgentMessage may have content as string or nested
if (typeof msg.content === "string") {
content = msg.content;