fix(core): Fix chat corruption bug in context manager. (#26534)

This commit is contained in:
joshualitt
2026-05-05 15:50:01 -07:00
committed by GitHub
parent e039fcdf2a
commit 80d2690540
8 changed files with 428 additions and 63 deletions
+8 -4
View File
@@ -23,9 +23,11 @@ export async function render(
env: ContextEnvironment,
protectionReasons: Map<string, string> = new Map(),
headerTokens: number = 0,
previewNodeIds: ReadonlySet<string> = new Set(),
): Promise<{ history: Content[]; didApplyManagement: boolean }> {
if (!sidecar.config.budget) {
const contents = env.graphMapper.fromGraph(nodes);
const visibleNodes = nodes.filter((n) => !previewNodeIds.has(n.id));
const contents = env.graphMapper.fromGraph(visibleNodes);
tracer.logEvent('Render', 'Render Context to LLM (No Budget)', {
renderedContext: contents,
});
@@ -61,13 +63,13 @@ export async function render(
'Render',
`View is within maxTokens (${currentTokens} <= ${maxTokens}). Returning view.`,
);
const contents = env.graphMapper.fromGraph(nodes);
const visibleNodes = nodes.filter((n) => !previewNodeIds.has(n.id));
const contents = env.graphMapper.fromGraph(visibleNodes);
tracer.logEvent('Render', 'Render Context for LLM', {
renderedContext: contents,
});
return { history: contents, didApplyManagement: false };
}
const targetDelta = currentTokens - sidecar.config.budget.retainedTokens;
tracer.logEvent(
'Render',
@@ -103,7 +105,9 @@ export async function render(
}
}
const visibleNodes = processedNodes.filter((n) => !skipList.has(n.id));
const visibleNodes = processedNodes.filter(
(n) => !skipList.has(n.id) && !previewNodeIds.has(n.id),
);
const contents = env.graphMapper.fromGraph(visibleNodes);
tracer.logEvent('Render', 'Render Sanitized Context for LLM', {