Skip to content

fix(voice): don't re-issue in-flight tool calls#1890

Open
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
urinated-ration-unseal
Open

fix(voice): don't re-issue in-flight tool calls#1890
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
urinated-ration-unseal

Conversation

@rosetta-livekit-bot

@rosetta-livekit-bot rosetta-livekit-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • inject in-progress placeholders for background tool calls before LLM inference so a new turn does not re-issue the same tool call
  • strip injected placeholders before forwarding a tool-response context
  • track currently running calls from background speech handles without adding new tests

Port of livekit/agents#6227.

Testing

  • pnpm build:agents

Ported from livekit/agents#6227

Original PR description

When a new generation fires while a tool from a previous turn is still running, the in-flight call has no entry in the turn's chat context, so the model re-issues it and duplicates side effects (e.g. booking a flight twice).

This injects an ephemeral in-progress function_call/function_call_output pair for the running tool calls (from the session-wide _RunningTasks registry, covering both activity- and session-scoped executors) into the copy of the chat context fed to the LLM only. It is recomputed every turn and never persisted or forwarded, so it is superseded as soon as the real output lands and a placeholder can never go stale.

It also stops spawning a tool-response generation for an interrupted turn: that reply would be dropped by the interrupted check anyway and waste an LLM call. The completed tool outputs are committed to the chat context directly instead, so an interrupted tool's result is preserved rather than lost.

@rosetta-livekit-bot rosetta-livekit-bot Bot requested a review from longcw June 26, 2026 11:57
@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 76dbd61

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review

name: fncCall.name,
args: fncCall.args,
createdAt: fncCall.createdAt,
extra: { ...fncCall.extra, [RUNNING_PLACEHOLDER_KEY]: true },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Placeholder marker key leaks into LLM provider serialization

The __lk_running_placeholder__ key added to FunctionCall.extra (agents/src/voice/generation.ts:110) will be included when the chat context is serialized for the LLM provider, because FunctionCall.toJSON() at agents/src/llm/chat_context.ts:508-509 emits the full extra object whenever it is non-empty. Most providers ignore unrecognized fields, so this is unlikely to cause failures, but it does mean an internal framework marker is exposed in the wire payload. Consider stripping it during serialization or using a Symbol key instead if any provider is strict about extra fields.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants