buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Deleting an auto-archived huddle channel returns 400 "channel is archived"

Open lnbc1QWFyb24 opened this issue 4 months ago • 2 comments

Describe the bug

Deleting a channel after it has been archived fails with:

relay returned 400 Bad Request: invalid: channel is archived

The user-visible case is an ephemeral huddle channel. When the last participant leaves, the relay automatically archives the huddle channel. Desktop can keep the channel row visible and offers Delete channel; confirming deletion sends NIP-29 DELETE_GROUP (kind 9008), which the relay rejects before reaching the delete handler. The same context menu can show Archive channel even though the relay already considers the channel archived.

The underlying protocol path is broader than huddles: the relay rejects kind 9008 for any archived channel. Both archived-channel guards exempt only an unarchive event (kind 9002 with archived=false), even though the later kind 9008 validator independently enforces owner authorization and the handler performs a soft delete.

Steps to reproduce

  1. Create a channel as its owner.
  2. Archive it with kind 9002 and archived=true; ending a huddle so its ephemeral channel auto-archives also reproduces this.
  3. As the same owner, submit a kind 9008 delete-group event for that channel. In Desktop, right-click the retained huddle channel, select Delete channel, and confirm.
  4. Observe the HTTP 400 response: invalid: channel is archived.

Expected behavior

An authorized owner should be able to permanently delete an archived channel. Kind 9008 should pass the archived-channel gates and continue through its existing owner-only validation before the soft-delete handler runs. Other writes to archived channels should remain rejected.

Desktop should also render lifecycle actions from the authoritative archived state, offering Unarchive channel rather than Archive channel when appropriate while still allowing deletion.

Version and platform

  • Buzz version: 0.4.26
  • OS: macOS 26.5.2
  • Relay: commit c0d7b52af8d5f3572790be697dd2c4bf3c6a3b8f; current upstream main at c2a4ee711e481bb427d6cf8cd08b2c7329d1508c has the same guards

Logs / additional context

Relevant code paths:

  • validate_admin_event rejects archived channels before its kind 9008 owner check: https://github.com/block/buzz/blob/c0d7b52af8d5f3572790be697dd2c4bf3c6a3b8f/crates/buzz-relay/src/handlers/side_effects.rs#L276-L290
  • The general ingest guard independently rejects every archived-channel event except unarchive: https://github.com/block/buzz/blob/c0d7b52af8d5f3572790be697dd2c4bf3c6a3b8f/crates/buzz-relay/src/handlers/ingest.rs#L1953-L1968
  • Kind 9008 already has owner-only authorization: https://github.com/block/buzz/blob/c0d7b52af8d5f3572790be697dd2c4bf3c6a3b8f/crates/buzz-relay/src/handlers/side_effects.rs#L635-L654
  • Huddle teardown auto-archives the ephemeral channel: https://github.com/block/buzz/blob/c0d7b52af8d5f3572790be697dd2c4bf3c6a3b8f/crates/buzz-relay/src/audio/handler.rs#L834-L842

A focused regression should archive a channel, submit a correctly signed kind 9008 as its owner, and assert that the channel is soft-deleted; a non-owner kind 9008 must still be rejected.

Duplicate search: no existing open or closed issue or pull request was found for this archive-then-delete failure.

lnbc1QWFyb24 avatar Jul 26 '26 06:07 lnbc1QWFyb24

Still present, and there is a second half to this that I think belongs in the same issue: the TTL reaper never purges, so every huddle leaves a permanent row even if delete were allowed.

Versions: relay 0.2.1 (deploy/compose, Postgres), desktop 0.5.23 (macOS).

What happens

A huddle creates an ephemeral channel (kind 9007, ttl_seconds = 3600). end_huddle archives it immediately.

The TTL reaper (reap_expired_ephemeral_channels in crates/buzz-db/src/store/channel.rs) only sets archived_at; it never deletes. For a huddle channel it does not even fire, because the channel is already archived.

Deleting the archived channel from the desktop app fails with relay returned 400 Bad Request: invalid: channel is archived — the same rejection this issue describes. The app offers the delete action anyway.

Result: every huddle leaves a huddle-<id> row in channels forever, visible in the channel management and archive views. The only way to remove it is unarchive followed by delete, or a manual SQL cleanup on the relay.

Expected

Either the relay purges archived ephemeral channels (TTL passed, archived_at older than a retention window, e.g. 24 h) together with their events, mentions, thread metadata and memberships, or delete is allowed on an archived channel, at least for ephemeral ones, so the client can remove them.

Steps to reproduce

  1. Start a huddle in any channel, end it.
  2. Wait longer than the TTL (1 h).
  3. Observe the archived huddle-<id> channel still present. Try to delete it from the desktop app: invalid: channel is archived.

Suggestion

A purge_archived_ephemeral_channels step in the existing reaper loop with a configurable retention (default 24 h), plus either hiding the delete action on archived channels in the desktop app or letting the relay accept it. Keeping archived ephemeral channels indefinitely has no user-facing value.

Related: #7596 and #7026 look like duplicates of this one from the client side; #4879 covers the kind:39000 divergence that makes the ghost row visible, which is orthogonal to the purge question above.

willi-werner avatar Sep 13 '26 07:09 willi-werner

Reproduced again with a newer Desktop/self-hosted Relay combination, and the guard is still present on current main.

Environment

  • Buzz Desktop: 0.5.28, macOS
  • Self-hosted relay image: block/buzz@sha256:e1865b3f89194d7d6068629d7ff62d3993140c4b920ee3a3f5f81564256a038d
  • Relay image revision: 5fdb2e53659ee29002545f1022c138fe0b8282f9
  • Current upstream main checked while reproducing: 1d9f2c81a5583f12be1239a088e2f0b379292dc3

Observed state

An ephemeral huddle backing channel ended up as:

channel_type = stream
visibility = private
ttl_seconds = 3600
archived_at = set
deleted_at = NULL
owner = creator identity

The newest kind 39000 metadata for that channel still had d/name/private/closed/t/ttl/ttl_deadline, but no ["archived","true"], matching the projection divergence in #4879. Desktop therefore continued to expose the channel/actions while the relay treated it as archived.

Attempting the channel action produced the same relay rejection:

HTTP 400
reason: invalid: channel is archived

Current main source

Both production gates still exempt only unarchive, not delete:

  • crates/buzz-relay/src/handlers/side_effects.rs (validate_admin_event) rejects every archived-channel mutation except kind 9002 with archived=false: current main lines 468-482.
  • crates/buzz-relay/src/handlers/ingest.rs independently rejects every event targeting an archived channel except that same kind 9002 unarchive shape: current main lines 2903-2915.

Kind 9008 never reaches its later owner-only authorization or handle_delete_group/soft_delete_channel path.

Verified workaround

Using the channel owner identity from the CLI, this sequence works:

buzz channels unarchive --channel <huddle-channel-id>
buzz channels delete   --channel <huddle-channel-id>

I used this to clean four accumulated archived huddle channels. After the two events, channels.deleted_at was set for all four and channels list no longer returned them. No SQL mutation was needed.

Suggested regression

Please cover both gates, not just one:

  1. owner archives a channel;
  2. owner submits kind 9008;
  3. delete is accepted and the channel is soft-deleted;
  4. non-owner kind 9008 is still rejected by owner authorization;
  5. other archived-channel mutations (message, membership change, rename/archive) remain rejected.

The existing fix direction in #7569 (shared helper allowing 9002 archived=false and 9008 through both gates) matches the behavior observed here. The stale kind 39000/ghost-row half is tracked separately in #4879 and #4918.

BMGY avatar Oct 13 '26 13:10 BMGY