mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-10 18:10:43 -07:00
fix(agent): implement AgentProtocol disposal to prevent memory leaks
This commit is contained in:
@@ -34,6 +34,10 @@ export class AgentSession implements AgentProtocol {
|
||||
return this._protocol.abort();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._protocol.dispose?.();
|
||||
}
|
||||
|
||||
get events(): readonly AgentEvent[] {
|
||||
return this._protocol.events;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ export class LegacyAgentProtocol implements AgentProtocol {
|
||||
private _agentEndEmitted = false;
|
||||
private _activeStreamId?: string;
|
||||
private _abortController = new AbortController();
|
||||
private _disposalController = new AbortController();
|
||||
private _nextStreamIdOverride?: string;
|
||||
private _lastToolStatuses = new Map<string, ToolEventStatus>();
|
||||
|
||||
@@ -106,10 +107,16 @@ export class LegacyAgentProtocol implements AgentProtocol {
|
||||
this._config.messageBus.subscribe(
|
||||
MessageBusType.TOOL_CALLS_UPDATE,
|
||||
this._handleToolCallsUpdate.bind(this),
|
||||
{ signal: this._disposalController.signal },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._disposalController.abort();
|
||||
void this.abort();
|
||||
}
|
||||
|
||||
get events(): readonly AgentEvent[] {
|
||||
return this._events;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ export interface AgentProtocol extends Trajectory {
|
||||
*/
|
||||
abort(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Disposes of the protocol, cleaning up any long-lived resources.
|
||||
*/
|
||||
dispose?(): void;
|
||||
|
||||
/**
|
||||
* AgentProtocol implements the Trajectory interface and can retrieve existing events.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user