How do I create unique identifiers and access them immediately?

If I take the code at face value, the regular way to do this would be like this:

#let id = state("refsection-id", "ref")
#id.update(x => x + "_1")
#context {
  // <-- here
  let my-id = id.get()
}
  1. state.update does not need context
  2. context is acquired after the update so the get will see the update. Not in the first layout iteration, but the state value will be available there as soon as possible
    NOTE that in your example, at here, the get will never see the updated state value, because the context is acquired before the update happens, and this fact is not about layout iterations, just the rules of state.

If you must put the update into the same context block then I would do something like this:

#let id = state("refsection-id", "ref")

#context {
  let updater = x => x + "_1"
  id.update(updater)
  let my-id = updater(id.get())
}

As you know we can’t and should not store my-id into a state.update but we can do parallel mappings of the state value this way.

As a general note, I assume you want to use a counter, not state to count refsections. But the logic above is analogous when using counter.