Keeping incremental IDs static in repeats when editing (deleting) permitted

1. What is the issue? Please be detailed.
related: Default to previous value - #8 by LN

@LN re your comments in the linked thread and the "which I hesitate to mention" :dragon: :triangular_flag:, I think I solved my issue but am not sure why it's solved with a calculate with a default vs a calculate with a calculation that has a cycle error. Also, it doesn't work in Web Forms, so I figure it's possibly not the optimal solution.

I want to have unique repeat element IDs, before client_editable, it was easy to use position(..) to get an integer ID. And there was also the __id UUID value for each repeat element.

But now, if a repeat element in the middle, eg #3 of 5 is removed, all the latter shuffle up, so #4 becomes #3 etc, and the __id values stay with the repeat position, so the UUID that used to relate to old #4 now relates to old #5, (new #4).

The UUID fix is easy, add a once(uuid()) in the repeat and use this instead of __id

I tried a few ways to identify the maximum integer ID and increment on that, while also making it a one time calculation so it's fixed and hit a bunch of circular logic issues.

I thought this would work as a calculation for a calculate field but it also results in a cycle error:
once(if(position(..)=1,1,int(${my_repeat}[position() = position(current()/..) - 1]/my_repeat_ID) + 1))

I tried changing from a calculate to a text field and moved the expression to the default column and this worked as I expected in Enketo & Collect. (Does not work in Web Forms, even for position = 1. once() is marked as working, so unsure the cause)

Then I changed it back to a calculate and left the expression in the default column, and it still evaluated properly in Enketo / Collect but not Web Forms.

(side quest :woman_mage: is there a way to access edits value in the form? i.e. then I could only calculate IDs this way if it's an edit >=1, otherwise just assign as ID = position to prevent the first record having findings like 1, 2, 6, 7, 10)

Very basic form to show position vs static ID and UUID:
repeat element static ID.xlsx (578.8 KB)