fix: add safety timeout to session.compact() to prevent lane deadlock (#16533)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 21e4045add
Co-authored-by: BinHPdev <219093083+BinHPdev@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Bin Deng
2026-02-15 06:54:12 +08:00
committed by GitHub
parent 542271e305
commit c0cd3c3c08
8 changed files with 417 additions and 2 deletions

View File

@@ -57,6 +57,7 @@ import {
type SkillSnapshot,
} from "../skills.js";
import { resolveTranscriptPolicy } from "../transcript-policy.js";
import { compactWithSafetyTimeout } from "./compaction-safety-timeout.js";
import { buildEmbeddedExtensionPaths } from "./extensions.js";
import {
logToolSchemasForGoogle,
@@ -107,7 +108,7 @@ export type CompactEmbeddedPiSessionParams = {
reasoningLevel?: ReasoningLevel;
bashElevated?: ExecElevatedDefaults;
customInstructions?: string;
trigger?: "overflow" | "manual" | "cache_ttl" | "safeguard";
trigger?: "overflow" | "manual";
diagId?: string;
attempt?: number;
maxAttempts?: number;
@@ -632,7 +633,9 @@ export async function compactEmbeddedPiSessionDirect(
}
const compactStartedAt = Date.now();
const result = await session.compact(params.customInstructions);
const result = await compactWithSafetyTimeout(() =>
session.compact(params.customInstructions),
);
// Estimate tokens after compaction by summing token estimates for remaining messages
let tokensAfter: number | undefined;
try {