I am not sure if this has been reported before, of if the behaviour is intended. But to reproduce this "bug": - Open an org file from the agenda. - Restrict to some headline - Execute the following command: (with-temp-buffer (org-agenda-prepare-buffers (org-agenda-files t))) - The restriction is removed. Note that executing `(org-agenda-prepare-buffers (org-agenda-files t))` in the buffer (without `with-temp-buffer`) restores the restriction upon completion. The reason is that `save-restriction` (and `save-excursion`) are called in `org-agenda-prepare-buffers` before switching to the buffer of the org file so the restriction is not saved (the point is manually restored but not the restriction). This has implications on running `org-map-entries` where all org buffers in the agenda (beside the current one) lose their restrictions. Attached is a possible patch to fix this. Emacs : GNU Emacs 28.1 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2022-04-08 Package: Org mode version 9.5.3 (9.5.3-g428076 @ /home/abdo/Work/Projects/dotfiles/emacs-radian/.emacs.d/.elocal/straight/build-28.1/org/)