To clarify by correct gradient I meant the function 1/x as the gradient of log(x) is only defined in R^+  however its definition extends to the whole real line.  When passed negative values to grad  we obtain -1/|x| as the gradient and whilst formally that may be incorrect its an odd choice as it “feels” correct.
The specific example given by op considers d/dy (log(x) ){x=0,y=1} and  d/dy (log(x) ){x=-1,y=1}, I think it would feel expected that the first is 0 (log(x) does not depend on y) and the second should be a nan or a “wrong value” as you say however for the first we get nan and for the second we get 0 which is the result we expect for the first and seems plausible (yet incorrect) for the second.