fix(webui): retain system context graph after compaction (#6608)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-09 13:20:46 +08:00
1 parent d789e1bfc7
commit 4212ad726d
25 files changed
+748 -102

No files matched your search

+1
View File
@@ -385,6 +385,7 @@ function parseThreadProjectionEvent(value: unknown, validatedGraphs: ReadonlySet
if (value.text !== undefined && typeof value.text !== "string") break;
return value as unknown as ThreadProjectionEvent;
case "context_compaction":
if (value.context_graph !== undefined && !validatedGraphs.has(value.context_graph) && !isContextGraph(value.context_graph)) break;
if (value.context_snapshot !== undefined && !isContextInspection(value.context_snapshot, (graph): graph is ContextGraph => validatedGraphs.has(graph) || isContextGraph(graph))) break;
if (typeof value.compaction_id !== "string" || !value.compaction_id
|| !isCompactionPhase(value.phase)
+1 -1
View File
@@ -1050,7 +1050,7 @@ export function projectThreadEvent(
id, graph: event.context_snapshot.graph,
estimatedTokens: event.context_snapshot.estimated_tokens,
contextWindowTokens: event.context_snapshot.context_window_tokens,
} } : {}),
} } : event.context_graph ? { contextSnapshot: { id, graph: event.context_graph } } : {}),
...(!options.persisted ? { announce: true } : {}),
},
...positionedTurnFields(state.messages[existing], turnFieldsForProjection(state, event, "activity"), options),
+1 -1
View File
@@ -1588,7 +1588,7 @@ export type InboundEvent =
agent_ui?: AgentUIBlob;
} & InboundTurnMetadata)
| (Exclude<NotificationEvent, { event: "context_compaction" }> & InboundTurnMetadata)
| (Extract<NotificationEvent, { event: "context_compaction" }> & InboundTurnMetadata & { context_snapshot?: ContextInspection })
| (Extract<NotificationEvent, { event: "context_compaction" }> & InboundTurnMetadata & { context_snapshot?: ContextInspection; context_graph?: ContextGraph })
| ({
event: "file_edit";
chat_id: string;
+8 -3
View File
@@ -40,9 +40,14 @@ function reloadPayload(body: WebuiThreadPersistedPayload): unknown {
const { context_graph, ...rest } = event;
return { ...rest, context_graph_ref: reference(context_graph) };
}
if (event.event === "context_compaction" && event.context_snapshot) {
const { graph, ...snapshot } = event.context_snapshot;
return { ...event, context_snapshot: { ...snapshot, graph_ref: reference(graph) } };
if (event.event === "context_compaction" && (event.context_graph || event.context_snapshot)) {
const { context_graph, context_snapshot, ...rest } = event;
const snapshot = context_snapshot && (({ graph, ...fields }) => ({ ...fields, graph_ref: reference(graph) }))(context_snapshot);
return {
...rest,
...(context_graph ? { context_graph_ref: reference(context_graph) } : {}),
...(snapshot ? { context_snapshot: snapshot } : {}),
};
}
return event;
});