Skip to content

Resolve 4 Detail bugs (maxToolSteps, JWT caching, fallback concurrency, mergeFrames perf)#1213

Open
toubatbrian wants to merge 4 commits intomainfrom
brian/bug-fix-2
Open

Resolve 4 Detail bugs (maxToolSteps, JWT caching, fallback concurrency, mergeFrames perf)#1213
toubatbrian wants to merge 4 commits intomainfrom
brian/bug-fix-2

Conversation

@toubatbrian
Copy link
Copy Markdown
Contributor

@toubatbrian toubatbrian commented Apr 7, 2026

Summary

  • Fix SpeechHandle._numSteps initialization so maxToolSteps limit is actually enforced in realtime tool-call loops
  • Add JWT expiry tracking to telemetry exporters to prevent permanent log/trace export failure after 6 hours
  • Cap pendingLogs in PinoCloudExporter at 10k to prevent OOM on persistent export failure
  • Remove shared LLM error listener in FallbackLLMStream that caused concurrent request cross-contamination
  • Rewrite mergeFrames from O(N^2) array spread to O(N) pre-allocated TypedArray.set()
    A fifth bug (Queue dropping falsy values) was already fixed on the current branch.

Changes

  • agents/src/voice/speech_handle.ts
    _numSteps was hardcoded to 1, ignoring the _stepIndex constructor arg. Now initialized from _stepIndex so the maxToolSteps check in agent_activity.ts sees the correct accumulated step count.

  • agents/src/telemetry/otel_http_exporter.ts and agents/src/telemetry/pino_otel_transport.ts
    ensureJwt() cached the token forever (if (this.jwt) return). Now tracks jwtExpiresAt and refreshes 1 hour before the 6-hour server TTL. Also caps pendingLogs at 10k entries in the flush error handler to prevent unbounded memory growth.

  • agents/src/llm/fallback_adapter.ts
    FallbackLLMStream attached an error handler to the shared LLM instance, capturing errors from unrelated concurrent requests. Removed the llm.on('error') listener, streamError variable, and post-loop if (streamError) throw check. Errors are already caught via the try/catch around for await (const chunk of stream).

  • agents/src/utils.ts
    mergeFrames used new Int16Array([...data, ...frame.data]) in a loop (O(N^2)). Rewritten to pre-compute total size, allocate once, and copy with TypedArray.set() (O(N)). Also normalized Queue.get() check from typeof item === 'undefined' to item === undefined (no behavior change).

Test plan

  • pnpm build passes
  • pnpm vitest run agents/src/utils.test.ts — 31 tests pass (covers Queue and mergeFrames)
  • Verify restaurant_agent.ts works in Agent Playground (exercises speech handles + telemetry)

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 7, 2026

🦋 Changeset detected

Latest commit: 176671d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1cb8c6de65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 212 to 214
try {
let shouldSetCurrent = !checkRecovery;
for await (const chunk of stream) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Re-raise child LLM failures in fallback stream

tryGenerate now relies only on for await (const chunk of stream) to detect provider failures, but LLMStream reports many failures by emitting llm.on('error') and then closing the output queue (see LLMStream.emitError), so iteration can end normally without throwing. In that case this method returns as success (often with zero/partial chunks), the adapter never marks the provider unavailable, and fallback to the next LLM is skipped. This regresses the core fallback behavior whenever a child stream fails via emitted error events rather than iterator exceptions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

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.

1 participant