B_setval/2 with findall/3 has unexpected behaviors

Two things surprised me about using b_setval/2 inside findall/3:

  1. The value of the key is not preserved after the findall/3 predicate. I guess I didn’t think that findall/3 “backtracked” after finishing, but then it appears that findall is not as straightforward as I imagined.
  2. The value of the setval key is [] after calling findall(b_setval). I expected it to be missing or the value I set it to. Not something that it was never set to.

Can anyone explain this behavior? Is there a workaround that retains b_setval after findall (or a similiar bag predicate)?

% Works as I expect
?- Key = zzz, b_setval(Key, true), b_getval(Key, X).
Key = zzz,
X = true.

% Ends with a value that is not what I set...why?
?- Key = yyy, findall(_, b_setval(Key, true), _), b_getval(Key, X).
Key = yyy,
X = [].