fix(agents): provide model fallback for compaction safeguard extension
When compaction is invoked directly via compactEmbeddedPiSessionDirect(), the ExtensionRunner is not initialized, leaving ctx.model undefined. This fix stores the model in the session-scoped runtime registry when building extension paths, then uses it as a fallback when ctx.model is unavailable during compaction summarization. Fixes #4121
This commit is contained in:
parent
d93f8ffc13
commit
fca8d481fd
@ -79,6 +79,9 @@ export function buildEmbeddedExtensionPaths(params: {
|
||||
const compactionCfg = params.cfg?.agents?.defaults?.compaction;
|
||||
setCompactionSafeguardRuntime(params.sessionManager, {
|
||||
maxHistoryShare: compactionCfg?.maxHistoryShare,
|
||||
// Provide model as fallback for when ctx.model is undefined
|
||||
// (ExtensionRunner not initialized during direct compaction calls)
|
||||
model: params.model,
|
||||
});
|
||||
paths.push(resolvePiExtensionPath("compaction-safeguard"));
|
||||
}
|
||||
|
||||
@ -1,5 +1,13 @@
|
||||
import type { Model } from "@mariozechner/pi-ai";
|
||||
|
||||
export type CompactionSafeguardRuntimeValue = {
|
||||
maxHistoryShare?: number;
|
||||
/**
|
||||
* Fallback model for compaction summarization.
|
||||
* Used when ctx.model is undefined (ExtensionRunner not initialized).
|
||||
*/
|
||||
// biome-ignore lint/suspicious/noExplicitAny: Model API type varies by provider
|
||||
model?: Model<any>;
|
||||
};
|
||||
|
||||
// Session-scoped runtime registry keyed by object identity.
|
||||
|
||||
@ -146,8 +146,15 @@ export default function compactionSafeguardExtension(api: ExtensionAPI): void {
|
||||
const toolFailureSection = formatToolFailuresSection(toolFailures);
|
||||
const fallbackSummary = `${FALLBACK_SUMMARY}${toolFailureSection}${fileOpsSummary}`;
|
||||
|
||||
const model = ctx.model;
|
||||
// Use ctx.model if available, otherwise fall back to runtime.model
|
||||
// (needed when ExtensionRunner is not initialized during direct compaction)
|
||||
const runtime = getCompactionSafeguardRuntime(ctx.sessionManager);
|
||||
const model = ctx.model ?? runtime?.model;
|
||||
if (!model) {
|
||||
console.warn(
|
||||
"Compaction safeguard: no model available (ctx.model and runtime.model both undefined). " +
|
||||
"Returning fallback summary.",
|
||||
);
|
||||
return {
|
||||
compaction: {
|
||||
summary: fallbackSummary,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user