multi_buffer: Use stable storage for buffer IDs (#46884)

Long story short:
1. Whenever we pick a buffer for mutation in

https://github.com/zed-industries/zed/blob/b8c5f672cdf8ed3c1f4c8016f2b8d6d84b7a7a9c/crates/multi_buffer/src/multi_buffer.rs#L3831,
we seed from a hashmap<BufferId, _>.
2. That HashMap is not RNG-seeded by
itself (good), but the BufferIds are: they are derived from entity ID in

https://github.com/zed-industries/zed/blob/b8c5f672cdf8ed3c1f4c8016f2b8d6d84b7a7a9c/crates/project/src/buffer_store.rs#L641

3.^ was introduced in https://github.com/zed-industries/zed/pull/10347
4.The HashMap is not randomized, but the order of it's values could
shift
when the keys (buffer ids) change.
5. Thus, we'll end up mutating a
different buffer in the multi-buffer when BufferIds shift around.

Our "fix" is that we're using a btreemap for buffer storage, which
should ensure that the order of iteration (and seeding) the candidates
matches up with the order of buffer creation.

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>

Closes #ISSUE

Release Notes:

- N/A

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
9b9f25ff39Piotr Osiewicz committed on 1/15/2026, 12:22:54 PM· committed by GitHubparent4a2d1e3
1 file changedLine totals unavailable