Skip to content

Relay compare-and-set for sidebar sections snapshot writes #8805

Open

Description

@blakemcanally

Problem

buzz sidebar sections (added in #8759) edits the channel sections preference (kind:30078, d=channel-sections) with a one-shot read-then-publish. Each command fetches the current head, applies its edit, and publishes the full snapshot as a NIP-33 replacement.

Two writers that read the same head before either publishes both produce a complete document derived from the old head. The relay accepts both as replacements. The one with the later created_at (or the lower id within the same second) wins, and the other writer's changes disappear. Both commands report success.

Review thread: #8759 (comment)

Who is affected

  • One-shot CLI writers: two CLI runs, or a CLI run and the desktop app, can silently overwrite each other.
  • Desktop mitigates this by keeping a pending edit and merging live head events. A one-shot CLI process cannot do that.

#8759 documents the limitation in the sidebar sections help text, the CLI README, and the nest skill.

Proposed fix

Add a relay-side compare-and-set check for sections snapshot writes:

  • The writer sends the id of the head event it read (the expected current head).
  • The relay rejects the publish when the stored head has a different id.
  • The CLI maps the rejection to exit code 5 (write conflict) so the caller can re-read and retry.
  • Desktop can send the same expected head and keep its pending-merge flow on conflict.

This also needs a decision on how the expected head travels with the event (for example a tag) and how it behaves for the first write, when no head exists.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions