extensions/ipynb/src/cellIdService.ts/onDidChangeNotebookCells
function onDidChangeNotebookCells(e: NotebookDocumentChangeEvent) {
	const nbMetadata = getNotebookMetadata(e.notebook);
	if (!isCellIdRequired(nbMetadata)) {
		return;
	}
	e.contentChanges.forEach(change => {
		change.addedCells.forEach(cell => {
			const cellMetadata = getCellMetadata(cell);
			if (cellMetadata?.id) {
				return;
			}
			const id = generateCellId(e.notebook);
			const edit = new WorkspaceEdit();
			// Don't edit the metadata directly, always get a clone (prevents accidental singletons and directly editing the objects).
			const updatedMetadata: CellMetadata = { ...JSON.parse(JSON.stringify(cellMetadata || {})) };
			updatedMetadata.id = id;
			edit.set(cell.notebook.uri, [NotebookEdit.updateCellMetadata(cell.index, { ...(cell.metadata), custom: updatedMetadata })]);
			workspace.applyEdit(edit);
		});
	});
}