-
-
Notifications
You must be signed in to change notification settings - Fork 9k
ACP terminal scrollback buffers never freed after tool call exits #57099
Copy link
Copy link
Open
Labels
area:ai/acpFeedback for Zed's Agent Client ProtocolFeedback for Zed's Agent Client Protocolarea:performance/memory leakFeedback for memory leaksFeedback for memory leaksfrequency:uncommonBugs that happen for a small subset of users, special configurations, rare circumstances, etcBugs that happen for a small subset of users, special configurations, rare circumstances, etcpriority:P2Average run-of-the-mill bugsAverage run-of-the-mill bugsstate:reproducibleVerified steps to reproduce included and someone on the team managed to reproduceVerified steps to reproduce included and someone on the team managed to reproduce
Metadata
Metadata
Assignees
Labels
area:ai/acpFeedback for Zed's Agent Client ProtocolFeedback for Zed's Agent Client Protocolarea:performance/memory leakFeedback for memory leaksFeedback for memory leaksfrequency:uncommonBugs that happen for a small subset of users, special configurations, rare circumstances, etcBugs that happen for a small subset of users, special configurations, rare circumstances, etcpriority:P2Average run-of-the-mill bugsAverage run-of-the-mill bugsstate:reproducibleVerified steps to reproduce included and someone on the team managed to reproduceVerified steps to reproduce included and someone on the team managed to reproduce
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
When an external ACP agent (Cursor, Claude Code, etc.) runs a bash/shell tool call,
AcpThreadcreates a display-onlyterminal::Terminalentity and stores it inself.terminals. When the tool call finishes,TerminalProviderEvent::Exitis fired — but the handler only callscx.notify()and never removes the terminal fromself.terminals. Every tool call that produces terminal output therefore leaks its scrollback buffer (~7 MB at the default 10 000-line cap) for the entire lifetime of the ACP session.Root cause
In
crates/acp_thread/src/acp_thread.rs,on_terminal_provider_event:The
Createdhandler inserts intoself.terminals; there is no matching removal anywhere.Impact
Measured via heaptrack on a 2-minute session with moderate bash tool call usage:
alacritty_terminal::grid::Grid::scroll_upvia the ACP terminal pathGrid::scroll_up ← on_terminal_provider_event ← handle_session_notificationEach
terminal::Terminalholds an alacrittyTerm<ZedListener>with aGridallocated up toscrolling_historyrows (default 10 000). That memory is never released until theAcpThreadentity itself is dropped.Reproducer
The following test fails against the current code and passes after the one-line fix:
Fix
Add one line to the
Exitbranch:Environment
main(confirmed identicalExithandler)mainas of 2026-05-18