If adding code into a current working document (i.e. with lots of content) doesn't work as expected, and having checked for obvious errors like typos or wrong literal path values, a sensible approach is to make test document.
If the code features being tried are new it is a good idea to make as simple a test as possible to give confidence. Don't overlook using methods available to show interim values. Use as little test data as possible to start with and validate the basic method works. Then, especially if agent queries or find() are involved, add extra content to test false positive/negatives.
Once confident the basic process works, code can be moved back into the min working document with confidence that it ought to work. If it still fails, this would suggest code/processes in the existing document may be interfering. The Tinderbox Inspector's tabs ca help get an overview as to how many active rules/edicts there are and as to running. It can help to turn off or disable some of these whilst looking for a cause of interference.
In a large mature document with a lot of code, a seeming failure may not be the code as such but the fact it runs less quickly/often than expected. In such a case the work shifts from de-bugging to tuning performance.
Tuning performance
This is not de-bugging as such but involves getting a clear view of how much code is running, where, and with what priority. consider that actions can be turned off (they retain their last used child aliases) and rules/edicts can be disabled. Rule code can move to edicts, that run less frequently, or even moved into a stamp.
Again, it may help to make a small test document of your general workflow just to look for possible optimisations.
Be ready to delete test documents
When done, it is often a good idea to delete the test document straight away or soon after the code works in the main document. In other words, make test documents with the intent of deleting them once the problem is resolved unless you have a clear need. If you do keep a test document it is worth adding a note explaining what it was for and what parts of the bigger context it did/did not test.