Skip to content

Commit f11bd3d

Browse files
SH20RAJscidomino
andauthored
fix(core): thread AbortSignal to chat compression requests (#20405) (#20778)
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
1 parent c06794b commit f11bd3d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/core/src/agents/local-executor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
323323
): Promise<AgentTurnResult> {
324324
const promptId = `${this.agentId}#${turnCounter}`;
325325

326-
await this.tryCompressChat(chat, promptId);
326+
await this.tryCompressChat(chat, promptId, combinedSignal);
327327

328328
const { functionCalls } = await promptIdContext.run(promptId, async () =>
329329
this.callModel(chat, currentMessage, combinedSignal, promptId),
@@ -810,6 +810,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
810810
private async tryCompressChat(
811811
chat: GeminiChat,
812812
prompt_id: string,
813+
abortSignal?: AbortSignal,
813814
): Promise<void> {
814815
const model = this.definition.modelConfig.model ?? DEFAULT_GEMINI_MODEL;
815816

@@ -820,6 +821,7 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
820821
model,
821822
this.context.config,
822823
this.hasFailedCompressionAttempt,
824+
abortSignal,
823825
);
824826

825827
if (

packages/core/src/core/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ export class GeminiClient {
608608
// Check for context window overflow
609609
const modelForLimitCheck = this._getActiveModelForCurrentTurn();
610610

611-
const compressed = await this.tryCompressChat(prompt_id, false);
611+
const compressed = await this.tryCompressChat(prompt_id, false, signal);
612612

613613
if (compressed.compressionStatus === CompressionStatus.COMPRESSED) {
614614
yield { type: GeminiEventType.ChatCompressed, value: compressed };
@@ -1158,6 +1158,7 @@ export class GeminiClient {
11581158
async tryCompressChat(
11591159
prompt_id: string,
11601160
force: boolean = false,
1161+
abortSignal?: AbortSignal,
11611162
): Promise<ChatCompressionInfo> {
11621163
// If the model is 'auto', we will use a placeholder model to check.
11631164
// Compression occurs before we choose a model, so calling `count_tokens`
@@ -1171,6 +1172,7 @@ export class GeminiClient {
11711172
model,
11721173
this.config,
11731174
this.hasFailedCompressionAttempt,
1175+
abortSignal,
11741176
);
11751177

11761178
if (

0 commit comments

Comments
 (0)