"Selecting deleted buffer" error

I just updated Emacs to version 29.1, and I am now getting the “Selecting deleted buffer” error described here whenever I try to perform any sort of org-roam operation.

Having already been through the whole song-and-dance with native compilation and the assumptions Emacs makes about that when doing this update on another computer, I knew to set the following:

  (when (boundp 'native-comp-eln-load-path)
    (startup-redirect-eln-cache (expand-file-name "eln-cache/" user-emacs-directory)))

So, thankfully, all my packages are in a straight/build directory under my user-emacs-directory and every package except org-roam is working just fine. Trying to troubleshoot this, I have so far:

  • Deleted ~/org-roam.db and tried to regenerate it with org-roam-db-sync; this just spits the same “Selecting deleted buffer” error.
  • straight-rebuild-all, which didn’t have any effect itself, and deleting the db, doing it and then running org-roam-db-sync also had no effect beyond creating an empty ~/org-roam.db file.
  • straight-pull-all + straight-rebuild-all, which also didn’t have any effect, same with doing all this after deleting the db and then trying org-roam-db-sync after.
  • I checked straight/build/emacsql-sqlite/sqlite, this was already built and trying to run make just resulted in 'emacsql-sqlite' is up to date. I saw one poster describe deleting this and manually rebuilding, which didn’t seem likely to make a difference to me, given that in the rebuild, this one had been rebuilt already. Tried it anyway, did nothing.
  • I checked straight/build/emacsql/sqlite, this was NOT already built, so I ran make, which did end up building an emacsql-sqlite in that directory. Trying org-roam-db-sync after that . . . just gave me the same “Selecting deleted buffer” error.

Any attempt to perform any sort of org-roam function results in the same error. When I toggle-debug-on-error and try it, I get the following:

Debugger entered--Lisp error: (error "Selecting deleted buffer")
  #f(compiled-function (connection) "Return true if the end of the buffer has a properly-formatted prompt." #<bytecode 0x190c386fa67d1127>)(#<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230>)
  apply(#f(compiled-function (connection) "Return true if the end of the buffer has a properly-formatted prompt." #<bytecode 0x190c386fa67d1127>) #<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230> nil)
  emacsql-waiting-p(#<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230>)
  #f(compiled-function (connection &optional timeout) "Block until CONNECTION is waiting for further input." #<bytecode -0x1e50a56866d5f103>)(#<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230>)
  apply(#f(compiled-function (connection &optional timeout) "Block until CONNECTION is waiting for further input." #<bytecode -0x1e50a56866d5f103>) #<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230> nil)
  emacsql-wait(#<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230>)
  #f(compiled-function (connection sql &rest args) #<bytecode -0x98d4f8cd96763a4>)(#<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230> [:pragma (= foreign_keys ON)])
  apply(#f(compiled-function (connection sql &rest args) #<bytecode -0x98d4f8cd96763a4>) #<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230> [:pragma (= foreign_keys ON)])
  emacsql(#<emacsql-sqlite-connection emacsql-sqlite-connection-15873ddcb230> [:pragma (= foreign_keys ON)])
  funcall-interactively(org-roam-db-sync nil)
  call-interactively(org-roam-db-sync record nil)
  command-execute(org-roam-db-sync record)
  execute-extended-command(nil "org-roam-db-sync" nil)
  funcall-interactively(execute-extended-command nil "org-roam-db-sync" nil)
  call-interactively(execute-extended-command nil nil)

Below is my org-roam configuration as it stands; hopefully this helps somewhat.

(use-package org-roam
  (setq org-roam-directory "~/sync_data/zettelkasten/"
	org-roam-db-location "~/org-roam.db"
	org-roam-file-exclude-regexp "org-roam/data"
	(concat "${title} " (propertize "${tags:*}" 'face 'org-tag)))
  (("C-c n f" . org-roam-node-find)
   ("C-c n i" . org-roam-node-insert)
   ("C-c n b" . org-roam-buffer-toggle)
   ("C-c n a" . org-roam-tag-add)
   ("C-c n d" . org-roam-tag-remove)
   ("C-c n r" . org-roam-refile))
  (setq org-roam-capture-templates
	'(("d" "default" plain "%?"
	   :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
			      "#+TITLE: ${title}\n")
	   :unnarrowed t)
	  ("C" "contact" plain "%?"
	   :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
			      "#+TITLE: ${title}\n#+filetags: :contacts:\n\n- Born:\n- Location:\n- Phone:\n- Email:\n\n* Biographical Information\n"))

Other suggestions I have seen for how to address this issue are variations on the things I have tried already. Please let me know if there’s any other information I can provide that would be helpful.

I observed that org-roam is still working perfectly on the other machine I set up Emacs 29.1 on, for some reason. The only difference I can discern right now is that straight/build/ does NOT have an emacs-sqlite directory in it on that machine, just an emacsql directory. When I C-h v on emacsql-sqlite-executable on that machine, I get /home/username/.config/emacsProfile/straight/build/emacsql/sqlite/emacsql-sqlite. I compare that against the machine I’m having problems with, and it’s a similar path, but with the last segment being emacsql-sqlite/sqlite/emacsql-sqlite instead.

I deleted the higher-level emacsql-sqlite directory, which got me to a No EmacSQL SQLite binary available error.

Then I slipped (setq emacsql-sqlite-executable "/home/username/.config/emacsProfile/straight/build/emacsql/sqlite/emacsql-sqlite") before my org-roam config, but that just gets me right back to Selecting deleted buffer.

EDIT 2 (Problem Solved)

Despite having restarted Emacs a few times during this process to no avail, doing it one more time seemed to shake things up, because the issue has disappeared. Not clear to me what difference there was between this restart and any of the others.