Skip to content

Coordinator crashes on :remove mutation for unknown index during initial app-state sync #14

@sh41

Description

@sh41

Description

Syncd.Codec.mix_mutation/2 raises a RuntimeError when it receives a :remove mutation for an index that doesn't exist in the local index_value_map. This crashes the Coordinator GenServer on every fresh pairing during regular_low app-state sync.

Version: 0.1.0-alpha.7
Elixir: 1.19.5-otp-28
Erlang: 28.1

Error

** (RuntimeError) tried remove, but no previous op for index 22ih2vBBdIjulk01vd1PQi/qIdChj611M+cCvLN5I9E=
    (baileys_ex) lib/baileys_ex/syncd/codec.ex:170: BaileysEx.Syncd.Codec.mix_mutation/2
    (baileys_ex) lib/baileys_ex/syncd/codec.ex:326: BaileysEx.Syncd.Codec.decode_single_mutation/5

Steps to reproduce

  1. Delete auth state directory (rm -rf tmp/baileys_auth)
  2. Pair a fresh session
  3. Post-pairing 515 restart → reconnect
  4. Coordinator crashes during regular_low app-state resync

Analysis

The upstream JS Baileys has the same throw new Boom('tried remove, but no previous op') in mix():

However, in JS the caller in chats.ts wraps decodePatches / decodeSyncdSnapshot in a try/catch (lines 559–620) that:

  1. Catches the error
  2. Logs it
  3. Nulls the collection state (app-state-sync-version: { [name]: null })
  4. Retries from scratch (up to MAX_SYNC_ATTEMPTS)

The BaileysEx Coordinator does not have equivalent error handling around the decode pipeline, so the raise propagates uncaught and kills the GenServer.

Possible fixes

Either:

  • (A) Add try/rescue handling in the Coordinator's app-state resync (matching the JS try/catch + retry pattern), or
  • (B) Change mix_mutation/2 to skip the no-op remove gracefully (return gen unchanged) — which is arguably more defensive since Map.delete on a missing key is harmless anyway

Option (A) more closely mirrors JS Baileys. Option (B) is simpler and prevents the error from occurring at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions