# Expected commit\_user\_turn() behaviour

**URL:** <https://community.livekit.io/t/expected-commit-user-turn-behaviour/2194>\
**Category:** Getting Started\
**Created:** [October 5, 2026, 12:14pm UTC](https://community.livekit.io/t/expected-commit-user-turn-behaviour/2194 "2026-10-05T12:14:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjamin\_Lowe](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/benjamin_lowe/32/314_2.png) [@Benjamin\_Lowe](https://community.livekit.io/u/Benjamin_Lowe)\
**Post date:** [October 5, 2026, 12:14pm UTC](https://community.livekit.io/t/expected-commit-user-turn-behaviour/2194/1 "2026-10-05T12:14:54Z")

</div>

Would be interested in livekit dev thoughts on [Return the `SpeechHandle` from `commit_user_turn` or ensure await session.commit\_user\_turn(...) commits to chat context on resolve · Issue #7585 · livekit/agents · GitHub](https://github.com/livekit/agents/issues/7585)

It is an observation I have that after await `commit_user_turn(skip_reply=True)`, the user message is added only after one or more of these waits:

- the end-of-turn task gets a turn on the event loop and finishes any endpointing delay;
- the previous turn’s task finishes;
- background speeches are interrupted.

A generate\_reply() called right after the await can therefore read the chat context before the message is in it - I am curious if it’s intended behaviour? As it means we need to work carefully around this with custom boilerplate.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Usman\_Bashir](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/muhammad_usman_bashir/32/1149_2.png) [@Muhammad\_Usman\_Bashir](https://community.livekit.io/u/Muhammad_Usman_Bashir)\
**Post date:** [October 5, 2026, 8:03pm UTC](https://community.livekit.io/t/expected-commit-user-turn-behaviour/2194/2 "2026-10-05T20:03:28Z")

</div>

@Benjamin_Lowe, Your read is accurate. `commit_user_turn()` returns an `asyncio.Future[str]` that resolves at `fut.set_result(transcript)`, which runs after end-of-turn detection is scheduled, not after the message lands ([audio\_recognition.py#L1107](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/voice/audio_recognition.py#L1107)). The user message is written later by `chat_ctx.add_message(role="user", ...)` inside the end-of-turn task, when the user\_turn span ends ([#L1525](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/voice/audio_recognition.py#L1525), noted at [#L1159](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/voice/audio_recognition.py#L1159)). So the future is not a commit barrier; a `generate_reply()` right after the await can race the write, exactly as you saw.

Whether that should be the contract is the open question in your #7585 (enhancement, no PR yet), so that intent call belongs to the team on the issue. The structural reason today is that the commit lives in the end-of-turn pipeline, not in the future resolution.

For now the reliable signal that the turn is in context is the `conversation_item_added` event ([events.py#L295](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/voice/events.py#L295)), not the returned future. Drive the reply from that instead of sequencing after the await:

```python
@session.on("conversation_item_added")
def _on_item(ev):
    if getattr(ev.item, "role", None) == "user":
        session.generate_reply() # chat context now holds the turn

```

---

<div class="post-metadata">

**Author:** ![Benjamin\_Lowe](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/benjamin_lowe/32/314_2.png) [@Benjamin\_Lowe](https://community.livekit.io/u/Benjamin_Lowe)\
**Post date:** [October 6, 2026, 7:40pm UTC](https://community.livekit.io/t/expected-commit-user-turn-behaviour/2194/3 "2026-10-06T19:40:47Z")

</div>

@Muhammad_Usman_Bashir thanks for your reply, and for the pointers.

We wait on `conversation_item_added` too but the part I cannot use as written is treating the first user item as “this commit”.

As far as I understand, LiveKit appends a turn’s user message only after the previous turn’s `on_user_turn_completed` task finishes. If I register the listener and then `await commit_user_turn(skip_reply=True)`, an earlier turn can still emit `conversation_item_added` _before_ “this commit’s message” exists. Calling `generate_reply()` from that event reads a chat context that does not yet contain the transcript the future just returned, which is is the stale reply bug we are trying to avoid.

Matching the event text against the returned transcript does not close it either. The future resolves with a snapshot taken before the endpointing delay, and a late STT final can extend the line that actually gets appended, so the chat text can be longer than the string the future returned. A prefix check covers that, and then fails in another way in that a short opening speech can very well be a prefix of an earlier turn’s line, so the wait ends on the wrong message.

The future only returns `str`. The `ChatMessage`, including its id, is created later in `_user_turn_completed_impl`, so there is nothing on the event that ties it to this `commit_user_turn` call. The `chat_ctx.add_message` in `_run_eou_detection` is a copy for turn detection. The session append, and the event, happen in that later task, which awaits the previous turn’s task first. That wait is why the first user event is not necessarily this commit.

If the contract stays as it is, the missing piece is a public way to know that this call’s item has been added. Either the future resolving after the append, or the event carrying something that identifies this commit.

---

<div class="post-metadata">

**Author:** ![Muhammad\_Usman\_Bashir](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/muhammad_usman_bashir/32/1149_2.png) [@Muhammad\_Usman\_Bashir](https://community.livekit.io/u/Muhammad_Usman_Bashir)\
**Post date:** [October 7, 2026, 1:58pm UTC](https://community.livekit.io/t/expected-commit-user-turn-behaviour/2194/4 "2026-10-07T13:58:13Z")

</div>

@Benjamin_Lowe, Confirmed from the source: on the `skip_reply=True` path, `_user_turn_completed_impl` appends the message and emits `conversation_item_added`, then returns before `on_user_turn_completed` ([agent\_activity.py#L2762-L2774](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/voice/agent_activity.py#L2762)). So that hook never fires for a skipped-reply commit, and the append itself runs only after the previous turn’s task ([#L2730](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/voice/agent_activity.py#L2730)). The event carries the `ChatMessage` with its id, but nothing public ties that id to your specific `commit_user_turn()` call. Your reading holds, and #7585 is the right place for the fix: the future resolving after the append, or a correlation id.

The one correlated handle today is on the non-skip path. With `skip_reply=False`, `on_user_turn_completed(turn_ctx, new_message)` fires with this turn’s committed `ChatMessage`, in order, before the reply ([#L2816](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/voice/agent_activity.py#L2816)). If your between-commit-and-reply logic can live there, you get the message with no text matching and no cross-turn ambiguity. Raise `StopResponse` to suppress the reply, or shape it:

```python
class MyAgent(Agent):
    async def on_user_turn_completed(self, turn_ctx, new_message):
        # new_message is THIS turn's committed message, id included
        if not ready_to_reply(new_message):
            raise StopResponse() # no reply this turn
        # else fall through: the normal reply runs against the committed turn

```

If you genuinely need the external commit-then-reply split rather than gating inside the hook, there is no public correlation today, and #7585 is the gap to close.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/system/32/26_2.png) [@system](https://community.livekit.io/u/system)\
**Post date:** [October 22, 2026, 1:59pm UTC](https://community.livekit.io/t/expected-commit-user-turn-behaviour/2194/5 "2026-10-22T13:59:06Z")

</div>

Closed on October 22, 2026, 1:59pm UTC

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
