I've gone through all your review comments and understood all of them except this one:
You really cannot modify the buffer like this and then decide, oops, never mind, I think I won't mark it dirty or write WAL for the changes. If you do that, the buffer is still in memory, but it's now been modified. A subsequent operation that modifies it will start with the altered state you created here, quite possibly leading to WAL that cannot be correctly replayed on the standby. In other words, you've got to decide for certain whether you want to proceed with the operation *before* you enter the critical section.
Could you please explain this point once more in detail? I am not quite able to understand under what circumstances a buffer would be modified, but won't be marked as dirty or a WAL won't be written for it.