fix: advance turn in before_message_write to prevent race condition #10

Merged
hzhang merged 2 commits from fix/turn-advance-race-condition into main 2026-03-03 03:47:35 +00:00
Collaborator

Problem

When a speaker finishes with an end symbol, the turn was only advanced in message_sent hook. By that time, the message had already been broadcast to other agents whose before_model_resolve ran with stale turn state, causing them to be blocked.

Fix

Move turn advance to before_message_write for both end-symbol and NO_REPLY cases. Use sessionTurnHandled to prevent double-advancing in message_sent.

## Problem When a speaker finishes with an end symbol, the turn was only advanced in message_sent hook. By that time, the message had already been broadcast to other agents whose before_model_resolve ran with stale turn state, causing them to be blocked. ## Fix Move turn advance to before_message_write for both end-symbol and NO_REPLY cases. Use sessionTurnHandled to prevent double-advancing in message_sent.
zhi added 1 commit 2026-03-02 11:05:06 +00:00
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.
Use sessionTurnHandled set to prevent double-advancing in message_sent.
zhi added 1 commit 2026-03-02 11:20:42 +00:00
before_message_write fires for both user (incoming) and assistant
(outgoing) messages. Without a role check, end symbols from other
agents' incoming messages incorrectly trigger turn advances.

Add role check to skip non-assistant messages early.
zhi force-pushed fix/turn-advance-race-condition from fb2cbaa5b3 to 39b758f13a 2026-03-02 11:29:11 +00:00 Compare
zhi force-pushed fix/turn-advance-race-condition from 39b758f13a to cf9be60145 2026-03-02 11:34:42 +00:00 Compare
hzhang merged commit 329f6ed490 into main 2026-03-03 03:47:35 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nav/Dirigent#10