Skip to content

fix(ui): replace placeholder state on import instead of merging#196

Merged
sanity merged 2 commits intomainfrom
fix-195
Mar 25, 2026
Merged

fix(ui): replace placeholder state on import instead of merging#196
sanity merged 2 commits intomainfrom
fix-195

Conversation

@sanity
Copy link
Copy Markdown
Contributor

@sanity sanity commented Mar 25, 2026

Problem

When importing an identity (export → leave room → import), the local room state is initialized with ChatRoomStateV1::default() which has owner_member_id: MemberId(FastHash(0)) — a placeholder value. When the real state arrives from the network via GET, the merge fails with "Cannot change the owner_member_id" because apply_delta rejects any change to the owner member ID.

This leaves the imported room in a broken state: the user sees "Syncing room state" forever, members show as "Unknown", and messages never load. If they can get past the sync, they can never send messages because the local state's configuration is corrupted.

Previous PRs (#189, #190) fixed the export flow and added GET-first logic for imports, but the merge-vs-replace issue remained.

Root Cause

Configuration::default() sets owner_member_id: MemberId(FastHash(0)). When a GET response arrives with the real owner's member ID, the scaffold merge()delta()apply_delta() path rejects the change at configuration.rs:76-77 because FastHash(0) != real_owner_member_id.

Approach

For rooms where is_awaiting_initial_sync() is true (empty members + empty messages + non-owner), replace the local state wholesale with the retrieved network state instead of merging. The default state has no useful data to preserve — it's a placeholder created during import. Normal rooms (already synced) continue to use the merge path.

Testing

  • Added 3 regression tests in common/tests/import_merge_test.rs:
    • test_default_state_has_placeholder_owner — verifies the root cause
    • test_merge_fails_when_owner_member_id_differs — proves the merge failure
    • test_wholesale_replacement_works_for_imported_rooms — validates the fix
  • All 181 river-core tests pass
  • No WASM changes — only ui/ code modified, no delegate migration needed

Closes #195

[AI-assisted - Claude]

sanity and others added 2 commits March 25, 2026 11:51
When importing an identity, the local room state starts with a default
ChatRoomStateV1 that has owner_member_id: FastHash(0) — a placeholder.
When the real state arrives from the network via GET, the merge fails
because apply_delta rejects owner_member_id changes ("Cannot change the
owner_member_id"). The imported room is stuck with a broken local state.

Fix: when `is_awaiting_initial_sync()` is true (empty members + empty
messages + non-owner), replace the local state wholesale with the
retrieved network state instead of merging. The default state has no
useful data to preserve, so replacement is correct and avoids the
owner_member_id mismatch entirely.

Closes #195

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sanity sanity merged commit 9052d87 into main Mar 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export and Import of ID in UI still not working

1 participant