New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
org-roam-extract-subtree results in data loss when extracting folded headings with properties under them #2425
Comments
@n-hebert I've been using
|
Great questions! At this point I'm totally confused as to what causes it so I'll take these suggestions and test on them. Please feel free to add more as they appear |
cannot replicate on my end - emacs 29.2 - works alright for me. Please provide the exact file if possible - will try to replicate the issue. |
About the Rarity
That's pretty reasonable to hear on my side; I don't expect anyone to replicate without significant & heavy daily usage of this function. It's what I would say is a real rare edge case, but tragically is also critically important to avoid, since it's a potential data loss. It is still happeningI did get it to happen again in One sign that it has happened is that there is no reference to the extracted subtree's title when you do a follow up It's not input or file-name dependentIf I undo, delete files, db sync, and re-run the extraction, everything is fine. It is not input related, so pasting my exact files won't help. That being understood... The output files do look interestingIt's always like this, with the title in the one, and the whole data in the backup file, with the ID still on the top heading.
|
Not an org-roam node, no. In general I only extract non-Roam nodes, as I'm converting all things to be more Roam-y
Directly under the org-roam directory, yes. I doubt this will change the response of the bug, but the times I've observed it have been directly under the org-roam directory. |
I studied the code a little - I dont know personally still why it would fail - but it seems to save multiple times -- I have put some debug towards the end of the function to catch any errors if may occur - maybe we can study the function itself - but we need a process to catch the error more concretely - I cannot reproduce the error; and I am out of ideas what can trigger it
basically afai understand -- it first creates an id if it doesn't exist - then asks user for file name - then pastes the content - then promotes until it is a top level node then runs org-roam-promote-entire-buffer to take the :ID: from it and paste it at the top of the buffer (more as in deletes the headline then pastes it as title after the metadata)- I feel if its bugging - its towards the end wherein it is promoting the node.
If I had to guess its related to this function and probably my intuition tells me its when its executing org-map-region. If #+title is present - then we are sure where we have reached in the process - keep this function on if you have fear about data loss - the debug messages will confirm that the final buffer is prepared. The function saves one last time after this.
But I still struggle to understand what can go wrong here - it is a very simple procedure, and may be an extreme edge case. But until we have a way to consistently reproduce the error - solving it is next to impossible- the underlying code is extremely simple and well laid out. |
Another wild guess - but we are going into the realm of conspiracy theory with this one - is sometimes character encoding can throw wrench in the cogs -- I have utf-8 encoding for all my files for this purpose
But then again - wild conspiratorial guess. |
All great input, thanks. Am I correct to say that second snippet is written such that I can just add it to an Guiding from your new information to me, my expectation that it is an autosave-mode interaction grows sharply. If it saves multiple times, it may get interrupted and fight with autosave-mode -- what happens in those cases? I would not call this extremely rare or impossible to fix at all. We simply need to collect more data. It's not been too long that this has been open 😉 -- we'll get a track on it, I'm sure. It is a recurring failure, even if a bit slippery. |
There's no one way of doing something -- but important to remember that execution and time are very intimately related, so depending on when and where a function is last read, results might be different - if org-roam functions are lazy loaded for efficiency not all definitions might be read before hand and subject to the original function is evaluated later for whatever reason your init.el definition might be discarded if you do not use a different name - so we should ideally use a different name and use one of the different approaches to override the original function - one safe way imo is to use an advice override
something like this would be more appropriate for your init.el in my understanding. also consider turning on Finally,
My intuition tells me autosave has nothing to do -- but I can be wrong. Please let know if you face the same error again, also look into your configuration for things -- for example you seem to introduce custom property metadata somehow,, check if they are valid and so on. |
Sounds good, thanks for those snippets. I'll plug them in. I meant this: My init.el has ;; Autosave. See more examples at http://xahlee.info/emacs/emacs/emacs_auto_save.html
(when (>= emacs-major-version 26)
(setq auto-save-visited-mode 1)
) Hopefully that seems incredibly related. It writes to the active file that's opened. Maybe the test here is to crank that up to every second and see how badly this function behaves while cutting a bunch of headings? |
I personally think this mode is incredibly dangerous, but not because it should conflict -- functions occur one after the other, there is no possibility that I know of in which when you execute two functions -- at the same time if it was possible -- somehow the result is a random linear combination of the two functions -- but ofcourse problems may arise if somehow these two activities were related by way a common yet to be determined function - but from studying the mode I couldn't spot any obvious common connexion -- but on an unrelated note: this mode undoes any benefit that Emacs tries to offer with its autosave files; The general condition is of chaos and disequilibrium - we wish to create a controlled environment in which inputs and outputs are predictable -- and one way to avoid chaos is not to execute any and all random modes and functions, more times than not you'd find things don't mutually work together very well, things are not as you predicted - etc, But subject to you having faith, and my ability to understand the problem - the autosaves are most probably not what's causing the problem -- your problems should be resolved in newer versions of org, consider subscribing to getting the latest org versions and live life without fear. If next time such a problem ever to occur, youd surely catch it in its root and it would be trivial to create condition cases to resolve it. Keep us updated, Best. |
I deleted an earlier message that might have popped a notification, as, during writing about how I couldn't quite get it entirely pinned down, I actually pinned it down. This took hours of dedicated testing work 😅 In brief:
In full, try this repo: https://github.com/n-hebert/roam-2425 Full steps and all details on how to get the bug with 100% reproducibility and totally input-dependent results. Startlingly, the emacs auto save files don't seem to be default, so in this repo's case, the data loss truly occurs and there is no Now we can probably start figuring out what's wrong in the code! |
Good work - #'org-roam-promote-entire-buffer fails in this case - we need to expand before killing entire line
this will fix it. |
I did some more testing - the bug seems to emanate from how The following operates the same way -- very untuitive behaviour. Just for example -- use the above which explicitly unfolds the region.
|
Also consider formatting the text better -- instead of one new line character after inserting #+title -- two new lines looks better it doesn't put the content smashed just next to the title. Change the |
Ah! I suspected this, but didn't quite pin it! This is why I wrote on my steps to just hit the down cursor twice. I noticed that doing so upped my hit rate to 100% and wanted to just capture it before asking why. 😅 It's quite a wacky behaviour that is not in any way obvious to a naive user just extracting the tree or killing a line, whatever the depth of your knowledge on the malfunction. Great find. Also thanks for pointing this out in specific, as you've restored a piece of my sanity. 😂 It sounds like we'll be able to commit a fix to org-roam to work around this, but it also sounds like there's an upstream, maybe emacs itself, where a more in depth discussion about kill-line semantics could take place. Could go either way upstream, so just expanding the content in this function makes so much sense. Costs basically nothing. |
Description
Steps to Reproduce
Backtrace
No error occurs
Expected Results
A file is created with the contents of the heading extracted.
Actual Results
The file is subtly pseudo-deleted. The contents are deleted from the Org buffer you're in, but they are not taken to the proper Roam file. This can result in a scare later where you believe the text has been utterly deleted when, in the extracted roam file, all you see is:
However, there is a saving grace: in the Emacs autosave file (e.g.
20240314-foo.org~
), the full file contents exist.Reproducibility
I'm not sure what's interacting here, but even the same snippet of text fails to repeat the same behaviour if I undo in my Org buffer and then run the extract again. Maybe it's extremely sensitive to the headline text (which I need to add
foo
to in order to get a new file to auto populate a distinct file name), but I doubt it.Environment
of 2024-03-03
Further Environment Details
This happens on every Emacs from 27 forward. I've been updating various things to see if that helps
Open to beta-test
I'm happy to begin digging in to any targets to test. I see that my 2.2.2 has the exact same org-roam-extract-subtree as
main
, should I try a different branch?The text was updated successfully, but these errors were encountered: