Don't retain recorded events when recording is disabled#1750
Merged
Conversation
AgentSession.emit() pushed every event into _recordedEvents for the whole session, even when recording was off. Each AgentEvent pins a large object graph (SpeechHandle, OTel spans/contexts, streams), so the buffer grew unbounded and leaked memory over long sessions. _recordedEvents is only consumed by makeSessionReport() (uploaded only when recording is enabled), so gate the push on _enableRecording. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: 3265551 The changes in this PR will be included in the next version bump. This PR includes changesets to release 34 packages
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 |
chenghao-mou
approved these changes
Jun 10, 2026
tinalenguyen
added a commit
that referenced
this pull request
Jun 23, 2026
Squashed local branch work, reconciled with the latest remote state: - Refactor ToolContext to parity class taking a list of Tool | Toolset (#1517) - feat(agents): add Toolset support to ToolContext and AgentActivity (#1525) - feat(agents): add beta end call tool (#1474) - fix(agents): thread FlushSentinel through Agent.create llmNode types - fix(elevenlabs): end server vad turns (#1745) - Add Inworld delivery mode inference TTS option (#1749) - Don't retain recorded events when recording is disabled (#1750) - fix(deepgram): validate updated model with stored language on updateOptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AgentSession.emit()pushed every emitted event into_recordedEventsunconditionally:emitfires for every agent event for the whole session (state changes, transcripts,conversation_item_added, usage, etc.), and eachAgentEventpins a large object graph (SpeechHandle, OTel spans/contexts, streams, chat items). The buffer is only cleared at_onSessionEnd, so over a long-running session it grows unbounded and leaks memory — even when recording is disabled (the common default).Fix
Only push when
_enableRecordingis true._recordedEventsis consumed solely bymakeSessionReport(), and that report is only uploaded when recording is enabled, so this changes no observable behavior:Notes
Targeted at
1.5.0. Minimal, behavior-preserving change; no changeset added since this is a release-branch patch (happy to add one if required).