fix: compaction safeguard falls through when ctx.model is unavailable

When extensionRunner.initialize() is not called (e.g. in embedded runner
mode), ctx.model resolves to undefined because the default getModel
returns undefined. Previously this caused the safeguard to return a
fallback summary with no actual content, effectively discarding all
conversation history on every compaction.

Instead of returning an empty fallback, return undefined so the built-in
compaction code in AgentSession handles summarization. The built-in path
correctly accesses the model via this.model (AgentSession.agent.state.model)
and produces a proper summary.

Same fix applied to the apiKey null case -- falling through is safer than
producing an empty summary that causes cascading re-compactions.
This commit is contained in:
Han Xiao 2026-01-29 14:17:06 -08:00
parent 4583f88626
commit a1a268c222

View File

@ -148,26 +148,16 @@ export default function compactionSafeguardExtension(api: ExtensionAPI): void {
const model = ctx.model; const model = ctx.model;
if (!model) { if (!model) {
return { // ctx.model may be undefined when extensionRunner.initialize() was not called
compaction: { // (e.g. embedded runner mode). Fall through to built-in compaction which has
summary: fallbackSummary, // correct model access via AgentSession.model.
firstKeptEntryId: preparation.firstKeptEntryId, return undefined;
tokensBefore: preparation.tokensBefore,
details: { readFiles, modifiedFiles },
},
};
} }
const apiKey = await ctx.modelRegistry.getApiKey(model); const apiKey = await ctx.modelRegistry.getApiKey(model);
if (!apiKey) { if (!apiKey) {
return { // Fall through to built-in compaction rather than producing an empty summary.
compaction: { return undefined;
summary: fallbackSummary,
firstKeptEntryId: preparation.firstKeptEntryId,
tokensBefore: preparation.tokensBefore,
details: { readFiles, modifiedFiles },
},
};
} }
try { try {