Commit Graph

3012 Commits

Author SHA1 Message Date
Matt Toohey
a1d1703b38 fix(invites): collect native consent for app invite handoff
Co-authored-by: Jitter <d14dfe033ef0f809866f9f984de04821b0d900d7652fd85a54776ee40ca3a68f@buzz.block.builderlab.xyz>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
2026-10-26 21:36:55 +11:00
Bradley Axen
d676c7b8db fix(deps): bump p256 to 0.14 for RUSTSEC-2026-0387 (#8592)
## Summary
RustSec published
[RUSTSEC-2026-0387](https://rustsec.org/advisories/RUSTSEC-2026-0387)
against `crypto-bigint`. Some of its operations meant to be
constant-time could compile to code that branches on secret values.
Since the advisory came out, `cargo-deny check` reports advisories as
failed. That breaks `Security Domain / Security` on `main` and on every
PR that runs the Rust security job (for example #8575 and #8579).

`crypto-bigint` 0.5.5 came in only through `p256` 0.13 →
`elliptic-curve` 0.13 in `buzz-push-gateway`. The advisory has no 0.5.x
fix; the patched line is 0.7.6+. This PR moves `buzz-push-gateway` to
`p256` 0.14, which uses `crypto-bigint` 0.7.9.

| Advisory | Crate | Change |
|---|---|---|
| [RUSTSEC-2026-0387](https://rustsec.org/advisories/RUSTSEC-2026-0387)
| `crypto-bigint` | 0.5.5 → 0.7.9 (via `p256` 0.13.2 → 0.14.0) |

**Code changes:** `p256` 0.14 renamed the SEC1 encoder from
`ToEncodedPoint::to_encoded_point` to `ToSec1Point::to_sec1_point`. The
gateway calls it in two places, both to re-encode an App Attest public
key as uncompressed SEC1 bytes. The tests call it in five more. Nothing
else in the gateway's API use changed.

**Lockfile:** only the `p256` dependency chain changes: `ecdsa`,
`elliptic-curve`, `ff`, `group`, `primeorder`, `rfc6979` and `sec1` move
up a minor version. `primefield` and `wnaf` are added. The old
`der`/`spki`/`pkcs8`/`pem-rfc7468`/`const-oid` 0.x versions that only
this chain used are removed. `desktop/src-tauri/Cargo.lock` and the
`buzz-feature-flags` fixture lockfile don't contain `crypto-bigint`, so
they're unchanged.

**Exposure, for context:** in production the gateway uses `p256` only to
verify App Attest signatures against public keys. Signing with a private
key happens only in tests. So the timing issue didn't realistically
apply here, but the bump clears the advisory instead of ignoring it.

### Related issue
N/A. I searched open and closed PRs for `RUSTSEC-2026-0387` and
`crypto-bigint` and found none.

### Testing
- `cargo-deny check`: `advisories ok, bans ok, licenses ok, sources ok`.
On `origin/main` the Security job fails on this advisory.
- `cargo test -p buzz-push-gateway --all-features`: 82 passed, 18
ignored (the same tests are `#[ignore]` on `main`).
- `cargo clippy -p buzz-push-gateway --all-targets --all-features -- -D
warnings` is clean.
- `cargo check --workspace --all-targets` passes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Bradley Axen <baxen@squareup.com>
Co-authored-by: ART <ea39c1c8acf57180161ef4ba4ed68abf8589f5291956b909a5aa991fc66664ca@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:42:55 +11:00
Logan Johnson
9e8c9fc04d fix(deps): bump ctutils to 0.4.5 for RUSTSEC-2026-0385 (#8560)
🤖
## Summary
On 2026-10-23, RustSec published RUSTSEC-2026-0385 against `ctutils`, a
constant-time helper crate used by the RustCrypto hashing and HMAC
crates. Some of its functions were meant to run in constant time, so
their timing would reveal nothing about secret values, but in versions
before 0.4.4 they could compile to code that branches on those values.
Since the advisory came out, `cargo-deny check` reports advisories as
failed. That breaks `Security Domain / Security` on `main` and on every
PR that runs the Rust security job.

This PR changes `ctutils` from 0.4.2 to 0.4.5 in the three lockfiles
that pin it: `Cargo.lock`, `desktop/src-tauri/Cargo.lock`, and the
`buzz-feature-flags` relay-feature-selection test fixture. No other
packages change.

| Advisory | Crate | Change |
|---|---|---|
| [RUSTSEC-2026-0385](https://rustsec.org/advisories/RUSTSEC-2026-0385)
| `ctutils` (non-constant-time mask generation and `u128` comparisons) |
0.4.2 → 0.4.5 |

### Related issue
N/A. I searched open and closed PRs for `ctutils` and
`RUSTSEC-2026-0385` and found none.

### Testing
- `cargo deny check advisories`: `advisories ok`. On `origin/main` the
Security job fails on this advisory.
- `cargo check --workspace` passes.
- `cargo test -p buzz-feature-flags --test
relay_feature_selection_contract` passes. This test compiles the fixture
with `--locked`.
- The pre-push hook's Rust and Tauri lanes pass.

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 15:28:39 -04:00
ngoodger-block
016310d3cc docs(cli): drop private references from the agent format comment (#8508)
### Why?

#8234 merged before its last review fix landed, so the `agent_event` doc
comment on main names a private repository and its internal class.
Public code should not reference private implementations.

### What?

Keeps the public pointer to buzz-app's MCP formatter and replaces the
private one with a generic note that other agent read surfaces trim the
same fields.

Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
mobile-v0.26.0-rc.1
2026-10-23 14:48:13 +11:00
klopez4212
dc25198d53 Add project selection to new Solo chats on mobile (#8546)
New Solo chats can optionally choose a project in the Flutter form and
native iOS sheet. Project appears above the agent picker with matching
neutral text, and the choice survives retries and restarts.

Validation: full Flutter suite passed; analysis and iOS builds passed.
Installed in Pairing Preview on iPhone Air and visually approved,
preserving saved preferences. Successful live chat creation remains
unverified because no agents were available.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-22 15:33:49 -07:00
Ian Oberst
20ba95ed89 fix(db): rebuild events_pkey in declared order after pgschema apply (#8525)
## Summary

Re-applying `schema/schema.sql` to a database that `pgschema apply` and
`scripts/reconcile-schema-after-pgschema.sql` already bootstrapped fails
with `cannot drop inherited constraint "events_p2026_01_pkey" of
relation "events_p2026_01" (SQLSTATE 42P16)`. Because of that,
`scripts/start-relay-for-tests.sh` breaks against a reused database.

**Cause:** pgschema 1.7.4 moves a partitioned table's partition key to
the front of its primary key when it creates the table. A
pgschema-bootstrapped `events` therefore gets `PRIMARY KEY (created_at,
community_id, id)`. `schema/tables/public/events.sql` and
`migrations/0001` both declare `(community_id, created_at, id)`. Every
later plan drops and re-adds `events_pkey` and each declared child's
key. This happens even on a database that was never reconciled. The plan
only becomes unexecutable after the reconcile script attaches the
children, because their keys are then inherited. As a side effect,
pgschema-bootstrapped databases also had a differently ordered PK index
than migration-managed ones.

**Fix:** after the partition ATTACH block, the reconcile script now
compares `events_pkey` with the declared `PRIMARY KEY (community_id,
created_at, id)`. If they differ, it rebuilds the key on the parent. It
then asserts that `events` and every partition carry the declared key,
which is the "convergence plus live assertion" shape `docs/database.md`
requires. PostgreSQL recreates each partition's key with the same
`<child>_pkey` names, so a reconciled re-apply now plans nothing. The
block does nothing when the key is already correct. `migrations/0001` is
untouched. Only pgschema-bootstrapped dev and test databases run this
script, so it does not touch the out-of-band partitioned-table
procedure.

`delivery_log` is not affected. Its key `(delivered_at, id)` already
starts with the partition key.

**Existing local databases:** a database reconciled before this change
would still fail its next `pgschema apply`, because the reconcile script
only runs after apply. The repair therefore also lives in
`scripts/repair-events-pkey.sql`. That file does nothing when `events`
doesn't exist yet, and `scripts/start-relay-for-tests.sh` runs it before
apply; it's the only launcher that reuses its database. The reconcile
script keeps a verbatim copy for fresh bootstraps, and a unit test keeps
the two identical.

The rebuild drops the key with `IF EXISTS`, so a database that has lost
its key still converges. It also takes its locks with a 10s
`lock_timeout`. If a relay still holds `events`, it fails with "Stop any
relay using this database, then rerun" instead of hanging.

`start-relay-for-tests.sh` now builds the relay's `DATABASE_URL` from
the `PG*` variables it already exports. The secret scanner flags the
literal URI once the file is touched. The value is unchanged.

pgschema 1.13.3 keeps the declared order and creates children as native
`PARTITION OF`. Upgrading would make this block and the ATTACH blocks
unnecessary, but it changes behavior for every caller, so it is left for
a separate change.

### Related issue

Follow-up to block/buzz#8487, which added the probe test and
`.pgschemaignore`. Now rebased onto `main` after that PR merged.

### Testing

- `pgschema_reapply_keeps_runtime_partitions` now asserts the plan after
the maintenance pass is **empty**, which replaces the `DROP TABLE` and
per-monthly plan checks. It then applies and reconciles a second time.
Without the new block it fails with `ALTER TABLE events DROP CONSTRAINT
events_pkey; ...`. With the block it passes.
- It also includes the optional notes from the #8487 review:
- After maintenance, it checks that both catch-alls are still present
and attached, not only that the zipped bounds differ.
- The first runtime monthly comes from the declared catch-all's lower
bound instead of a hard-coded `p2026_07`.
- The doc comment now states only what the test pins: bounds are not
compared, and the plan is empty.
- I broke the rebuild on purpose by re-adding the key in the wrong
order. The new assertion fails the reconcile script with `events and its
partitions must have PRIMARY KEY (community_id, created_at, id)`.
- CLI runs against local Postgres 17:
- Fresh DB: apply → reconcile → apply → reconcile → plan. The second
apply reports no changes and the plan is empty.
- DB reconciled with the old script: the next apply fails with SQLSTATE
42P16. After running the new reconcile script once, apply reports no
changes and the plan is empty.
- `events_pkey_repair_runs_before_reused_apply_and_matches_reconcile`
checks two things: the reconcile script carries the repair block
verbatim, and `start-relay-for-tests.sh` runs the repair before
`pgschema apply`. It fails if the two copies drift.
- I ran the repair script and then the bootstrap against four local
probe databases: one reconciled with main's script, an empty one, one
applied but never reconciled, and one with no `events` key. All four end
with an empty plan. With another session holding a lock on `events`, the
repair fails after 10s with the hint and leaves the key untouched. It
succeeds once the lock is released.
- `admin_schema_parity_between_desired_state_and_migrations` and the
`runtime::migration` unit tests pass. fmt and clippy are clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ian Oberst <ioberst@block.xyz>
Co-authored-by: Ian Oberst <ioberst@block.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 10:57:49 -07:00
klopez4212
f7708d0694 Polish mobile onboarding and profile setup (#8438)
Originally stacked on #8375, now merged. Rebased onto main.

Polishes the onboarding landing page, community-link entry, and recovery
sheets. Profile setup uses a consistent sheet with a larger avatar,
inline display name, and draft photo/emoji/animated editing; iOS uses
native controls and coordinated avatar/sheet transitions.

Validation: mobile analysis, full tests, and normal pre-push checks
passed after rebase. Prior iOS build and device walkthrough passed;
native validation was not repeated after this rebase. Snapshots omitted
as requested.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>
2026-10-22 17:27:38 +00:00
klopez4212
8260b6ef4c feat(mobile): group typing avatars into one animated indicator (#8543)
## Summary
Replace stacked mobile typing rows with one animated avatar cluster and
one typing bubble. People and agents share diagonal, triangle, and
four-corner layouts, with a circular +N badge for overflow and
reduced-motion support.

Includes an opt-in local demo (`BUZZ_TYPING_PREVIEW=true`) with mixed
human/agent avatars and count controls; it never publishes typing
events.

### Related issue
Follow-up to #8505. No duplicate found in the typing-avatar PR search.

### Testing
- 3,736 mobile tests plus four unconfigured-push tests passed; analysis
and file-size checks passed.
- Installed and iterated on a physical iPhone with the existing
profile/community preserved; owner reviewed the motion and badge sizing.

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-22 10:20:23 -07:00
ravarora2
2d289f720d BUZZ-301: Add user deletion request intake (#8496)
## Summary

Add the first testable piece of user deletion: submit a synthetic
request, list requests, and inspect one by UUID. Operators can verify
that intake reaches PostgreSQL before we add inventory, approval, and
execution.

Add one operator-global `entity_deletion_requests` table with an
additive migration and matching desired-state schema. Identical
submissions return the same row. Conflicting submissions fail without
changing it. Only `demo:` targets are accepted, and requests stay
`submitted`.

Keep the commands in `buzz-deletion`, reached through a thin `buzz-admin
user-deletions` adapter. Reuse the existing database connection setup.
This change adds no worker, stage history, community gates, or deletion
operations.

### Rollout plan

This is an expand-only schema change plus an operator CLI. Existing
relay code does not use the new request table. No backfill or real
deletion is part of this release.

1. **Order the PRs.** Land #8496 first, using 0068; main now owns 0067
for channel join roles. Rework #8489 to build on this table with the
next available migration number. Renumbering its existing CREATE TABLE
migration alone is insufficient; both PRs currently create the same
request table.
2. **Apply on staging.** For deployments that manage schema separately,
apply the reviewed additive migration before using the new CLI. Where
auto-migration is enabled, the new relay binary applies it at startup.
Keep existing tables and records unchanged.
3. **Verify on staging.** Use the new `buzz-admin` binary with
`DATABASE_URL` pointing to staging. Submit a unique synthetic label,
list requests, and inspect the returned UUID:

   ```bash
buzz-admin user-deletions submit --target demo:staging-intake-1
--requested-by <operator>
   buzz-admin user-deletions list --limit 5
   buzz-admin user-deletions inspect <returned-uuid>
   ```

Verify one `entity_deletion_requests` row with status `submitted`.
Repeat the identical submission and verify the same UUID and timestamps.
Use a new label if this label was used by an earlier staging test.
4. **Apply beyond staging.** After verification, use the deployment's
reviewed schema/release workflow to add the table in the remaining
environments. Requests run only through the operator CLI; this release
starts no deletion worker. No feature flag is needed for this synthetic
intake: the database accepts only `demo:` targets, and real deletion is
absent.
5. **Rollback.** Keep the additive table and saved requests; stop using
the new commands and roll back the binary if needed. After 0068 is
applied, an older binary with auto-migration enabled can fail at startup
with sqlx `VersionMissing`. A binary rollback therefore requires
migration execution to be disabled on the older relay
(`BUZZ_AUTO_MIGRATE=false`, including the corresponding deployment
configuration).

### Related work

This is a smaller first slice of the full-workflow draft
[#8489](https://github.com/block/buzz/pull/8489), which is preserved for
later extraction. The two PRs overlap and should not both be merged as
written.

### Testing

The author submitted `demo:rarora-manual-1` to a separate local
PostgreSQL 17 database. Repeating the same submission returned its
original UUID and timestamps. List, inspect, and a direct SQL query all
returned the same saved request.

<details>
<summary>Actual command inputs and outputs</summary>

Commands ran from the new worktree with `DATABASE_URL` set to the local
`buzz_user_deletion_submit` database. Outputs below are stdout;
connection diagnostics on stderr are omitted.

**Submit again — returns the existing request without creating a
duplicate**

```bash
./target/debug/buzz-admin user-deletions submit \
  --target demo:rarora-manual-1 --requested-by rarora
```

```json
{
  "id": "2e5bcdec-ab68-44d2-9743-1dd9fa7d2f89",
  "entity_type": "user",
  "target": "demo:rarora-manual-1",
  "status": "submitted",
  "requested_by": "rarora",
  "reason": null,
  "created_at": "2026-10-20T19:57:44.516698Z",
  "updated_at": "2026-10-20T19:57:44.516698Z"
}
```

**List saved requests**

```bash
./target/debug/buzz-admin user-deletions list --limit 5
```

```json
[
  {
    "id": "2e5bcdec-ab68-44d2-9743-1dd9fa7d2f89",
    "entity_type": "user",
    "target": "demo:rarora-manual-1",
    "status": "submitted",
    "requested_by": "rarora",
    "reason": null,
    "created_at": "2026-10-20T19:57:44.516698Z",
    "updated_at": "2026-10-20T19:57:44.516698Z"
  }
]
```

**Inspect one request**

```bash
./target/debug/buzz-admin user-deletions inspect 2e5bcdec-ab68-44d2-9743-1dd9fa7d2f89
```

```json
{
  "id": "2e5bcdec-ab68-44d2-9743-1dd9fa7d2f89",
  "entity_type": "user",
  "target": "demo:rarora-manual-1",
  "status": "submitted",
  "requested_by": "rarora",
  "reason": null,
  "created_at": "2026-10-20T19:57:44.516698Z",
  "updated_at": "2026-10-20T19:57:44.516698Z"
}
```

**Read the table directly**

```bash
docker exec buzz-user-deletion-dev-20261020 \
  psql -X -U buzz -d buzz_user_deletion_submit -c \
  "SELECT id, entity_type, target, status, requested_by
   FROM entity_deletion_requests ORDER BY created_at DESC;"
```

```text
                  id                  | entity_type |        target        |  status   | requested_by 
--------------------------------------+-------------+----------------------+-----------+--------------
 2e5bcdec-ab68-44d2-9743-1dd9fa7d2f89 | user        | demo:rarora-manual-1 | submitted | rarora
(1 row)
```

</details>

A separate CLI smoke test also verified that a conflicting operator and
a non-demo target fail without changing the saved request. The existing
community-deletion `list --limit 1` command passed against the smoke
database.

See [the intake
walkthrough](729233c726/docs/operator-user-deletion-intake.md)
for setup, commands, expected fields, and the SQL query.

Generated with Codex

---------

Signed-off-by: Ravneet Arora <rarora@squareup.com>
2026-10-22 10:49:27 -04:00
Logan Johnson
a2d28eb6c4 fix(relay): apply channel setting changes atomically and lock every membership writer (#8516)
🤖
## Summary
This PR fixes two ways the relay could report a channel change that did
not fully happen.

**1. Channel settings could be saved only in part, while the app was
told that they all worked.**
When an owner or admin changed a channel's settings (name, description,
topic, public or private, message lifetime, archived or not, who can
join), the relay saved the request first and then applied each setting
with its own database write. If one write failed, the relay only logged
the error. It skipped the remaining settings and still reported success.
Sending the request again did nothing, because the relay saw it as
already saved. Example: a switch from public to private could fail while
the app showed success, and the channel stayed public.

Now saving the request, applying every setting and saving the "settings
changed" messages in the channel happen in one database transaction.
Either all of it is saved or none of it is:
- If anything fails, nothing is saved and the client gets an error. It
can send the same request again.
- A repeat of a request that already succeeded is reported as a
duplicate and changes nothing. This is also true when the repeat arrives
while the first copy is still being saved.
- A request to restore a channel that is not archived, or to change an
archived channel without restoring it, is refused and nothing is saved.
Before, the relay saved the request and a "settings changed" message,
and then the restore failed.
- Live updates go out only after the save commits. These are: removing
access for people who lose it, and pushing the new messages and channel
info to clients.

**2. A published member list could include someone who had just been
removed.**
For some channels the relay publishes a list of the channel's members.
While it builds that list, it holds a per-channel membership lock. Kicks
by a relay admin and the automatic kick after a deploy did not take that
lock. A kick could commit after the list was read, so the published list
still showed the removed member. Channel deletion also did not wait for
the lock. Kicks, channel deletion and the automatic add when someone
joins a Huddle (voice call) now all take the lock first. The published
list then includes the change, or the change waits until the list is
saved.

## Details
- **One lock order for all channel settings writes.** Before, each
writer took its own locks. Review kept finding writers that took them in
a different order or forgot one. `lock_channel_for_settings_write`
(`crates/buzz-db/src/store/channel.rs`) is now the only place that takes
them. The order is:
1. the membership lock, only when the public/private setting or the "who
can join" setting (`join_role`) changes. Without it, a member add could
read the old rule while the change commits.
2. the message-lifetime (TTL) lock: exclusive for a lifetime change,
shared otherwise.
3. the channel row (`FOR NO KEY UPDATE`). This does not block the key
lock that a member insert takes. The row lock also orders two copies of
the same request, so the second copy sees the first as already stored.
- The function returns a `ChannelSettingsWriter`. The writer borrows the
transaction that took the locks, so the compiler stops it from being
used with another transaction or after commit. The settings writes
(`update_channel_on`, `set_topic_on`, `set_purpose_on`,
`set_archived_on`) require the writer. They refuse a change its locks do
not cover.
- `Db::apply_channel_metadata_event` stores the channel-edit event
(kind:9002) and its mentions, applies the settings and stores the
"settings changed" messages (kind:40099) in one transaction. The older
single-purpose writes (`update_channel`, `set_topic`, `set_purpose`,
`archive_channel`, `unarchive_channel`) use the same helpers and behave
as before.
- `ingest.rs` and `validate_admin_event`: channel edits no longer check
archived/active state before the write. The transaction checks it after
its duplicate check, under the row lock. A refusal there goes back to
the client as `invalid:`. Channel edits have their own save path and
skip the general post-save step. `handle_side_effects` refuses them, so
no caller can go around the transaction.
- `side_effects.rs`: `emit_system_message` is split into signing and
sending. The messages are signed before the transaction and sent after
it. All "settings changed" messages from one edit share one timestamp
and come in a fixed order (topic, purpose, visibility, lifetime,
archive).
- A change to "who can join" (`join_role`) is applied in the same
transaction and announced with its own `join_role_changed` message.
- **Membership lock outside settings** (`relay_admin_actions.rs`,
`channel_members.rs`, `audio/handler.rs`): both kick paths
(`execute_kick_with_marker`, `deploy_kick_member`) take the membership
lock before they remove the member. The marker kick still undoes the
removal if its lease check fails after waiting. The Huddle join takes
its locks through a new `ChannelMembershipLocks` token, and the auto-add
is a method on that token, so it cannot run without the lock.
`soft_delete_channel` takes the full settings lock order.
- **Limit of the membership lock:** it covers member changes,
public/private and "who can join" changes, and channel deletion. It does
not cover archiving: archive writes and the cleanup of expired temporary
channels do not take it. The cleanup keeps its single UPDATE. A comment
in `channel.rs` explains why that is safe and why it must not be split
into a read and a write.

### Related issue
Follow-up to the review of #8143 (which added the "who can join"
setting). That review found that channel edits could be applied in part.
No separate issue.

### Testing
New PostgreSQL tests in
`crates/buzz-relay/src/handlers/edit_metadata_postgres_tests.rs`:
- `failed_edit_stores_nothing`: a test trigger makes one write fail
partway through the transaction. Nothing is stored or changed, on the
first send or a resend. Without the trigger, the same signed request
applies in full.
- `resent_edit_is_a_duplicate`,
`resent_archive_and_unarchive_are_duplicates`: a resend after success is
a duplicate and adds nothing.
- `resend_validated_after_the_first_commit_is_a_duplicate`: a resend
validated after its first copy committed is a duplicate, with no second
change and no second message.
- `concurrent_copies_of_a_restore_apply_once`: two copies of one
restore, held at the channel lock until both are waiting, apply once.
The other copy is a duplicate.
- `unarchive_of_an_active_channel_is_refused`,
`join_role_edit_is_applied_and_announced`.

Lock tests in buzz-db: each one holds a member list in progress and
checks that the writer waits for it. They cover a "who can join" change
(`channel_members.rs`), the deploy kick and the marker kick
(`relay_admin_actions.rs`), and channel deletion (`channel.rs`). The
kick and delete tests fail when the new locks are removed.

These tests and the existing channel-edit tests in
`group_state_postgres_tests` pass locally against a migrated PostgreSQL
database.

---------

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
2026-10-22 10:32:43 -04:00
klopez4212
e8781caa6f fix(mobile): remove Browse channels from channel list (#8539)
## Summary
Remove the “Browse channels” action above the mobile channel list. The
list now starts with its channel sections or empty state. Remove the
unreachable browse sheet and its obsolete tests; keep channel directory
providers and the create-channel/direct-message actions.

### Related issue
No duplicate removal PR found. Related: #6243 introduced mobile channel
browsing.

### Testing
- `just mobile-check mobile-test`: formatting and analysis passed; 3,729
tests passed, 16 skipped, plus all four unconfigured-push tests.
- Release iOS build succeeded. Installed and launched in place on a
physical iPhone Air in Pairing Preview; existing preferences retained
except channel read-state updated after launch.
- Existing quick-action test asserts the browse button is absent.
- `git diff --check` passed.
- Pre-push hooks passed on commit `269df8b3e` (full mobile checks and
tests plus file-size gate). The first attempt timed out in the unrelated
iOS push-gateway validator test; the unchanged-commit retry passed.
- Full repository `just ci` remains in progress through native desktop
checks; not claimed green.

Draft pending owner visual confirmation and review. Screenshots have not
been captured; installation/launch is not visual acceptance.

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-22 07:17:22 -07:00
Ian Oberst
347ce88d5d fix(db): keep pgschema re-apply from dropping runtime partitions (#8487)
## Summary

pgschema doesn't compare partition bounds. Re-applying
`schema/schema.sql` to a database a relay has used therefore plans `DROP
TABLE IF EXISTS ... CASCADE` for every `events` / `delivery_log` monthly
the partition manager created at runtime, and those tables' rows are
deleted with them. Since #8464 the manager advances the catch-all by
default, so any local dev or test database a relay has started against
now hits this. One example is the persistent `buzz` database that
`scripts/start-relay-for-tests.sh` re-applies.

This adds a root `.pgschemaignore` that hides dated monthlies
(`events_p2*`, `delivery_log_p2*`) from pgschema. The monthlies declared
in `schema/partitions/` are exempted with `!` patterns, so pgschema
still manages them. pgschema reads the file from its working directory,
and every caller already runs it from the repo root: the test-relay
launchers, `postgres-test-setup.sh`, the desktop release smoke and
`_ci-relay.yml`. Both partition files now carry a note pointing at it,
and AGENTS.md gotcha #7 adds "run pgschema from the repo root" next to
the reconcile rule.

New-install layout is unchanged.

**Why the drops haven't deleted data yet:** on a reconciled database a
re-apply also plans to drop and re-add the `events` primary key on the
parent and on each declared child. The apply then fails with `cannot
drop inherited constraint "events_p2026_01_pkey"` (42P16). That happens
with or without this PR. The planned drops run in the same single
transaction, so they roll back, and the runtime monthlies have survived
so far. Once that primary-key drift is fixed, re-applies will succeed
and this ignore file is what keeps them from dropping the runtime
monthlies. The primary-key fix is a separate follow-up.

### Related issue

Follow-up to #8464. Salvaged from an earlier branch; no existing issue
found.

### Testing

- `pgschema_reapply_keeps_runtime_partitions` (Postgres) follows the
real bootstrap path in a dedicated database:
- `bin/pgschema apply` from the repo root, then
`scripts/reconcile-schema-after-pgschema.sql`;
  - the relay's default maintenance pass (create plus advance);
- asserts that both catch-alls were attached before the pass and that
their bounds moved after it;
- asserts that each parent's `p2026_07` monthly exists. The catch-all
advanced past the declared bounds but kept its name.
- asserts that `pgschema plan` contains no `DROP TABLE` and no line
mentioning any runtime monthly.
- Falsified both ways:
- With `.pgschemaignore` removed, the test fails and prints the planned
drops.
- Without the reconcile step, it fails with `reconcile did not attach
both catch-alls`.
- `pgschemaignore_exempts_exactly_the_declared_monthlies` checks that
the `!` exemptions exactly match the dated monthlies in
`schema/partitions/`.
- The admin parity test now shares the `pgschema` helper, so it also
runs from the repo root like the real callers.
- All `runtime::migration` and `store::partition` tests pass against
local Postgres after merging current main, including the ignored ones:
104 passed, run with `--test-threads=1` because the full nextest
Postgres lane needs local `dropdb`. `clippy -D warnings` and the
pre-push lanes pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ian Oberst <ioberst@block.xyz>
Co-authored-by: Ian Oberst <ioberst@block.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 17:14:22 -07:00
Luke Tornquist
2f2f6e2774 fix(db): bound every statement and the #p mention scan (#8461)
## Problem

An agent `#p` + `#h` + `since` REQ (the `require_mention` subscription
in `buzz-acp`) ran for over 45 minutes on a production writer and held
`AccessShare` on every `events` partition. There were two causes:

1. **The mention side of the `#p` join was unbounded.**
`build_query_events_sql` joined `event_mentions` on `(community_id,
event_id)` only. The planner picked a nested loop whose outer side was
every mention of the pubkey, ever, and whose inner side range-scanned
the channel index from `since` on each partition. Cost ≈ total mentions
× channel rows since `since`.
2. **Nothing cancelled it.** The writer `statement_timeout` defaulted to
`0`. Only `#e` reads had a deadline (the 20s cap from #7854), and
read-replica sessions had none at all.

`pg_stat_statements` shows this shape has a multi-thousand-second max
going back months, so it is chronic and was not introduced by a recent
change.

## Change

**`#p` mention bound** (`store/event.rs`, `push_mention_join`, shared by
the page SELECT and COUNT)
- Join on the full event key, `AND e.created_at = m.event_created_at`.
Mention rows copy the event's `created_at` at insert (migration 0007
already relies on this equality), so the join can prune `events`
partitions by time.
- Repeat `since`/`until` on `m.event_created_at`, so the outer scan is a
range on the existing `idx_event_mentions_pubkey_created`. `until` is a
superset bound for the keyset cursor; the exact `(created_at, id)`
cursor test stays on `e`.
- Repeat `kinds` on `m.event_kind` when the filter has kinds. Every
production mention writer binds the event kind (`insert_mentions` in
`store/runtime/mod.rs`, and the replaceable-event path in
`store/replaceable.rs`, back to the first Postgres schema), and no
migration inserts mention rows, so this drops no rows written by the
relay. Rows imported out of band with a NULL `event_kind` would no
longer match a kinds-filtered `#p` read; a read-only production count on
2026-10-20 found 0 such rows on both production reader databases. The
pushdown makes `idx_event_mentions_pubkey_kind_created` available to the
planner for the `require_mention` kind-9 shape; its use has not been
observed (see below). An E2E fixture with a hand-set NULL `event_kind`
row confirmed the caveat: base returns 8 events, head 7.
- The feed's mentions and needs-action queries (`store/feed.rs`,
`build_mentions_query` / `build_needs_action_query`) join
`event_mentions` the same way, so each joined row probes one `events`
partition instead of all of them. Their `ORDER BY m.event_created_at ...
LIMIT` already kept them from running away; this removes the per-row
cross-partition probe.
- Observed plan (E2E at `9cb6638b1`, before the `kinds` pushdown; 60,000
historical mentions + 2,500 recent decoys, stock planner, `EXPLAIN
(ANALYZE, BUFFERS)` of the captured production SQL): the mention side is
a bounded range on `idx_event_mentions_pubkey_created` (13 rows), then a
hash join with a scan of the recent `events` partition. Base scanned
2,509 recent events and probed `event_mentions_pkey` 2,509 times. Head:
**1.1 ms / 319 shared hits**; base: **8.5 ms / 10,049 shared hits**. Not
measured against the production replica. A fresh `EXPLAIN (ANALYZE,
BUFFERS)` replay at `a7065c367`, after the pushdown, ran on a smaller
fixture where the planner chose a sequential mention scan, so it neither
confirms nor replaces these numbers.

**Reads: 20s deadline on every generic event read**
- `query_events_on` and `count_events_on` always run under the
transaction-local 20s deadline that `#e` reads used
(`fetch_with_read_deadline`, formerly `fetch_with_e_tag_deadline`). It
only tightens: shorter operator or caller caps are kept.
- Read-replica sessions get a 20s session default through
`after_connect`, using the same tighten-only SQL.
- Cost: every generic REQ history read and COUNT now pays BEGIN +
`set_config` + ROLLBACK (three extra round trips; before, only `#e`
reads did). In the local E2E the end-to-end history read was still
faster at head (median 4.1 ms vs 10.2 ms at base, 9 samples each, warm
cache), so the round trips are dominated by the bounded plan; this does
not isolate them or establish production p99. The round trips also
lengthen how long each such read holds its writer connection; that hold
time has not been measured against production pool sizing.
- A replica read cancelled at its deadline (57014) is returned, not
re-run on the writer. Usually the cancel means expensive work the writer
would only repeat. It can also mean the replica waited on a lock only it
holds (a replayed `ACCESS EXCLUSIVE` from primary DDL), when the writer
would have answered quickly; that miss is the accepted price of keeping
runaway reads off the primary. The rationale now lives once on
`DbError::is_statement_cancelled` instead of in a dozen copied comments.
The generic routed reads and `ReadSession` already did this; the eight
routed reads with their own SQL (feed mentions, needs-action and
activity; thread replies; channel window; relay membership; thread
window and its auxiliary scan) now do too. A cancelled auxiliary scan
also keeps its replica session instead of degrading it to the writer for
the rest of the request. Other replica failures (e.g. hot-standby
recovery conflicts) still fall back to the writer.
- Paths with their own tighter `SET LOCAL` (artifact 2–5s, thread window
4s, personal reads, usage 5–15s, serving lease 1.5s) are unchanged.

**Writes: every writer session is bounded**
- The default `statement_timeout` changes from `0` to 120s
(`DEFAULT_STATEMENT_TIMEOUT_MS`).
- `BUZZ_DB_STATEMENT_TIMEOUT_MS` still overrides it. `0` or any value
above 300s installs 300s (`MAX_STATEMENT_TIMEOUT_MS`), so a session can
no longer disable it, and a clamped value logs a `warn!` when the pool
is built. Only the operator-approved, fenced destruction paths below
lift it, per transaction.

**Long-running writer paths, audited**
| Path | Behavior |
|---|---|
| Migrations / schema destruction
(`with_exclusive_schema_destruction_lock`) | Unchanged: these lift lock
and statement timeouts on their own detached connection |
| Partition maintenance | Unchanged: own 5s `statement_timeout` |
| Partition audit (`buzz-admin`) | Unchanged: 30s |
| Community deletion inventory, purge and logical verification
(`inventory_schema` whole-tenant counts, `purge_postgres`
whole-community `DELETE` per table in one tx,
`verify_postgres_logically_deleted` whole-tenant `EXISTS` per table
right after the purge) | Lifted (`statement_timeout = 0`)
transaction-locally by `lift_statement_timeout`, like migrations; lock
and idle timeouts still bound them. Inventory counts each table in its
own lifted transaction, so each table's lock and snapshot are released
as soon as its count finishes, as the autocommit counts did. A cancelled
purge would retry from scratch and eventually block, so a cap here would
turn large-tenant deletion into an operator override |
| Audit appends (`buzz-audit`, audit pool inherits the writer cap) |
Waits on the audit-chain advisory lock. With `BUZZ_DB_LOCK_TIMEOUT_MS=0`
(or at least the statement cap), `statement_timeout` (57014) cancels the
wait instead of `lock_timeout` (55P03). The relay's audit worker now
retries both with the same backoff instead of dropping the entry on
57014; admission refusal stays terminal |

On HTTP routes a statement timeout already maps to the distinct
retryable 503 (`api/mod.rs`, `statement_timeout_maps_to_distinct_503`).
A cancelled REQ fails its history read instead of hanging.

## Tests
- `p_tag_query_bounds_mention_side_by_time` (unit): page and COUNT SQL
carry the `created_at` join and the `since`/`until`/`kinds` mention
bounds, and the bounds are absent when the filter has none.
- `p_tag_read_with_mention_bounds_keeps_results` (Postgres): through the
production mention insert, unbounded, `since`, window and keyset-cursor
reads return exactly the mentioned rows, and COUNT matches. Every bound
sits exactly on a mentioned row's second and the cursor page includes a
same-second sibling after the cursor id, so an off-by-one on either
mention-side bound fails it.
- `plain_read_is_cancelled_at_deadline_when_timeout_disabled` /
`count_events_cancels_at_read_deadline_when_timeout_disabled`
(Postgres): the production `#p` + `#h` + `since` shape and a plain COUNT
are cancelled at 20s with the session timeout disabled. Previously these
covered `#e` only.
- `writer_statement_timeout_is_always_bounded` (unit) and
`session_statement_timeouts_bound_writer_and_reader_sessions`
(Postgres): through `Db::new`, writer sessions install `2min` / `5min`
(for `0` and for 600s) / `45s`, and replica sessions install `20s`.
- `deletion_whole_tenant_stages_outlive_the_writer_statement_timeout`
(Postgres): on a scratch desired-state database with a 500ms writer cap,
the real `inventory_schema`, `purge_postgres` and
`verify_postgres_logically_deleted` each wait behind a held `ACCESS
EXCLUSIVE` lock on `events` for over 1s and still complete, a plain
statement is cancelled (57014), and pooled sessions still read `500ms`
afterwards. A lifted transaction reads `statement_timeout = 0`, so a
bounded lift (e.g. `'300000'`) fails it, as does removing any of the
three `lift_statement_timeout` calls.
- `mentions_query_is_tenant_scoped_and_joins_mentions_by_composite_key`
/
`needs_action_query_is_tenant_scoped_and_joins_mentions_by_composite_key`
(unit): both feed queries carry the `e.created_at = m.event_created_at`
join.
- `replica_statement_cancel_propagates_without_writer_rerun` (Postgres):
with the replica locked past its cap, each of the six routed reads above
returns 57014 instead of the writer's copy. Removing the cancel arm in
any of them fails it.
- `thread_window_statement_cancel_propagates_without_writer_rerun`
(Postgres): a thread-window read parked behind a replica lock and
cancelled (57014; the window's own 1s `lock_timeout` would otherwise
fire first) returns the cancel instead of the unlocked writer's window,
and an auxiliary scan timed out on a replica session returns 57014 and
leaves the session on the replica. Removing either guard fails it.
-
`audit_worker_retries_statement_timeout_until_original_entry_is_appended_once`
(Postgres, `buzz-relay`): the production audit worker, with
`lock_timeout` disabled and a 100ms statement cap, keeps the entry
through repeated 57014 cancels while the chain lock is held and appends
it exactly once after release. Treating only 55P03 as retryable fails
it.
- The existing writer and audit-pool GUC tests now expect `5min` for a
disabled statement timeout.

## After deploy, watch
-
`buzz_db_route_decision{decision="replica",reason="statement_cancelled"}`:
replica reads that now fail instead of falling back to the writer,
including the replica-only lock case above.
- `buzz_db_pool_acquire_wait_seconds` and `buzz_db_pool_waiters` on the
writer pool: every generic REQ history read and COUNT now holds its
connection for three extra round trips.

## Database checklist (`docs/database.md` § Review checklist)

This PR changes schema-dependent `buzz-db` queries (the `#p` join and
its `m.event_kind` pushdown). It does not change the schema.

- **Phase:** none. No schema change, so this is not an expand, backfill
or contract step. Nothing before or after it is required.
- **Triggers, functions, procedures, rules, foreign keys:** none added.
- **Row mutations / backfill:** no migration, and no row is mutated or
backfilled. The one data-shape dependency is mention rows with a NULL
`event_kind`: a kinds-filtered `#p` read no longer matches them (see the
`kinds` bullet under Change). Relay writers always bind `event_kind`, so
only rows imported out of band are affected. A read-only production
count on 2026-10-20 found 0 such rows on both production reader
databases.
- **Contract migration:** N/A.
- **Rule 4 locations:** none touched. No table, index or desired-state
file changes, so no parity test applies. The new bounds use the existing
`idx_event_mentions_pubkey_created` and
`idx_event_mentions_pubkey_kind_created`.
- **Deployed relay vs. new schema:** there is no new schema. The
currently deployed relay and this relay run against the same tables.
- **Lock and statement timeouts:** this PR is about them. Generic reads
get a 20s deadline, replica sessions a 20s default, and writer sessions
a 120s default capped at 300s. Community-deletion transactions lift
`statement_timeout` per transaction; migrations and schema destruction
are unchanged (see "Long-running writer paths, audited"). No index
builds and no operator prebuild step.

## What got simpler
- One read-deadline path instead of an `#e`-only branch in
`query_events_on` and `count_events_on`.
- The `#p` join SQL that was duplicated between SELECT and COUNT now
lives in one `push_mention_join`.
- The deletion tests share one scratch desired-state database helper
instead of an inline copy.
- "Is this query bounded?" now has one answer: yes, unless it runs in a
migration, schema destruction, or community-deletion transaction.

## Identified debt (not in this PR)
- `buzz-acp` re-sends the same filter after a timeout `CLOSED` (no
backoff or narrowing). With the `#p` bound the `require_mention` read
should finish well inside 20s, so this is a follow-up, not a blocker.

---------

Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
2026-10-21 19:35:03 -04:00
Logan Johnson
d97f6b4c6e feat(relay): add announce channels with a join_role setting (#8143)
🤖
## Summary
Channels are Buzz's main way to control access, but today they cannot
separate reading from writing. In an open channel, anyone who can read
can also write. So there is no way to say "many people read, a few
people write". Announcements, release feeds, plugin release records and
shared configuration all need that.

This PR adds **announce channels**: anyone can follow and read them, but
only members can post. It does this with one new channel setting and
without changing what any role means.

- **Roles mean the same thing in every channel.** A *guest* can read and
leave, but cannot write. A *member* (or *bot*) can write. *Admins* and
*owners* also manage the channel. The relay already had the guest role,
but no client used it until now.
- **A new setting, `join_role` (`member` | `guest`), picks the role a
new person gets** when nobody chooses one: when they join by themselves,
or when someone adds them without a role. The default, `member`, keeps
today's behavior for every existing channel.
- **An open channel with `join_role = guest` is an announce channel.**
Anyone can find, read and join it. People who join are guests, so they
cannot write until someone makes them a member.

The relay enforces these rules, so a client cannot get around them.

What each role can do (the same in every channel):

| Action | Guest | Member or bot | Admin / owner |
| --- | --- | --- | --- |
| Read, leave | ✅ | ✅ | ✅ |
| Post, reply, edit, delete own, react, artifacts, canvas, forum, pins,
topic, typing, workflow messages, save or run workflows, huddles | ❌ | ✅
| ✅ |
| Add people | ❌ | ✅ as member, guest or bot | ✅ any role |
| Make a guest a member (person or agent) | ❌ | ✅ | ✅ |
| Any other role change | ❌ | ❌ | ✅ |
| Change name, about, visibility, TTL, `join_role` | ❌ | ❌ | ✅ |

Other rules:

- **Joining by yourself.** A person who joins (kind:9021), or adds
themselves (kind:9000 with their own key), gets the channel's
`join_role`. They may ask for `join_role` or a lower role, never a
higher one. So in an announce channel nobody can join as a member by
themselves.
- **Non-members.** A non-member may write only where joining would let
them write: an open channel with `join_role = member`. That is today's
behavior for open channels.
- **Agents.** Agents follow the same rules as people. Any member who can
write may make a guest agent a member. Limits that only an agent's owner
may lift belong to the later IFC work (its "restricted" agent level),
not to this PR. That work only refuses more actions, so it can be added
later without breaking anything here.
- **Leaving always works.** A member may leave an archived channel too
(kind:9022, or kind:9001 naming themselves). The last owner still cannot
leave.
- **Agent owners keep edit and delete.** Today the human owner of an
agent can edit (kind:40003) and delete (kind:9005) that agent's messages
without being a member. This PR keeps that existing behavior in announce
channels too, and documents and tests it. It does not let the owner
post.
- **Changing the setting changes no roles.** Existing members can still
write after a change to `guest`. Existing guests stay read-only after a
change back to `member`.

A refused write gets `restricted: only members can post in this
channel`.

## Details
- **One write rule.** The relay's channel write check decides from the
actor's role and the channel's `join_role`. Some event types skip that
check and run their own: message edit, deleting your own message
(kind:9005), topic and purpose (kind:9002), add-member (kind:9000),
workflow messages and joining a huddle. Each of these now uses the same
rule. Membership changes (add, remove, leave) do not need write access,
so a guest can always leave. If the relay finds a stored `join_role`
value it does not know, it treats it as `guest`, so an unknown value can
never give more access.
- **Admission is decided in the database transaction.** The membership
write (`put_member`) makes the whole admission decision inside its
transaction, after it takes the channel's membership lock: `join_role`
for a missing role tag, the self-join ceiling, guests cannot add people,
who may grant admin or owner, and role changes
(`MemberRole::may_change_role`). The relay's request check uses the same
rules, but the database is the authority, so a write that skips the
request check cannot get around them. A change to `visibility` or
`join_role` takes the same lock, so an add and a setting change cannot
interleave.
- **No creator exception.** `put_member` used to give owner to a
channel's creator who added themselves to a private channel without an
active membership. A removed creator could use that: their join
(kind:9021) passes the open-channel check, the channel becomes private
before the join takes the membership lock, and the join restored them as
owner. Channel creation already makes the creator owner in the same
transaction, so the exception is removed. A removed creator is now
admitted like anyone else.
- **Huddles.** Joining a huddle needs write access in the huddle channel
**and** in its parent channel. The relay checks both before the join.
When it commits the join, it applies the same rule again while it holds
both channels' membership locks: a member needs a role that can post,
and a non-member needs an open channel whose `join_role` is `member`. A
guest in either channel cannot join. A join is also refused when the
joiner loses membership or the channel's `join_role` changes before the
commit.
- **One lock order.** Each writer that takes more than one of a
channel's locks takes them in this order: membership lock, TTL lock,
channel row. Settings changes, roster publication, TTL refresh and
huddle joins all use this order. Before this change, a `join_role`
change on an ephemeral channel at the same time as a roster publication
could deadlock.
- **Workflows.** Saving a workflow (kind:30620) skips the generic write
check, so it now checks the sender's role itself and needs a writing
role before anything is stored. Every path that starts a workflow run,
including the manual trigger (kind:46020), needs the workflow's owner to
hold a writing role now (and an elevated role for an elevated workflow).
So a workflow saved while its owner was a member stops running after the
owner is made a guest.
- **Channel names are checked before storage.** kind:9002 and kind:9007
refuse a name longer than the `channels.name` column (255 characters)
before the event is stored. Before this, the relay accepted the event,
then the name update failed, and the rest of the update (for example
`join_role`) was silently skipped. This PR only adds this check. Storing
the event and applying the update in one transaction is a larger change,
and it is not in this PR.
- **Changing the setting.** Owners and admins send a channel-metadata
update (kind:9002) with `["join_role", "guest"]` or `["join_role",
"member"]`. Buzz applies these updates as partial updates; a missing tag
means "no change". The relay posts a `join_role_changed` system message
in the channel.
- **What clients see.** The relay signs a channel description event
(kind:39000) that clients read. One shared builder now writes it for
both the relay and the `buzz-admin` backfill, which had a copy that had
drifted from the relay's. It always publishes an explicit `["join_role",
…]` tag, plus the standard NIP-29 group access flags:

| `visibility` | `join_role` | `public` / `private` | `restricted` |
`closed` |
  | --- | --- | --- | --- | --- |
  | open | `member` | public | | |
  | open | `guest` | public | ✓ | |
  | private | either | private | ✓ | ✓ |

This also fixes an old bug: `closed` ("join requests are ignored") was
published for every channel, even open channels that accept joins.
- **CLI and SDK.** `buzz channels update --join-role guest|member`.
`buzz_sdk::build_update_channel` takes a new `join_role` argument and
always writes it as an explicit tag.
- **Docs.** `NOSTR.md` has an "Announce channels" section with the role
table and the flag table.
- **Tests.** Relay end-to-end tests, run in the CI relay E2E step:
- `test_nip29_announce_channel_wire`: who can set `join_role`, the
kind:39000 flags, joining as a guest, refused guest and non-member
posts, reactions and adds, member posts, a member making a guest a
member who then posts, changing the setting back without changing roles,
and leaving.
- `test_nip29_member_raises_guest_agent`: a member who is not the
agent's owner can make a guest agent a member.
- `test_nip29_announce_channel_wire_workflow_send_needs_write_role`: a
guest's workflow message is refused; a member's is accepted.
- `test_nip29_departure_wire_archived_channel_allows_self_leave`: guests
and members can leave an archived channel.
- `test_private_channel_any_member_can_invite` now expects a
private-channel guest to be refused when it adds someone (it used to
expect success).
- `test_nip29_announce_channel_wire_workflow_commands_need_write_role`:
saving and triggering a workflow, by a member and by a guest, in
announce and normal channels; a guest cannot run a workflow saved while
it was a member.
-
`test_nip29_announce_channel_wire_overlong_name_is_refused_before_storage`:
a kind:9002 with an overlong name and `join_role` is refused, and
kind:39000 still shows the old settings.
- `test_nip29_announce_channel_wire_agent_owner_exception`: an agent's
owner, as a guest and as a non-member, can edit and delete the agent's
messages, while ordinary guests are still refused.
- `test_nip29_guest_is_read_only_in_normal_channel`: a guest in an
ordinary channel cannot write, and joining an ordinary channel still
gives `member`.

Unit tables cover the self-join rule for each `join_role`, and every
actor, current role and requested role for the role-change rule.
Database tests check the admission rules in `put_member`
(`put_member_enforces_announce_admission`), that an add which waits on
an uncommitted change to `guest` is decided on the new setting
(`put_member_waits_for_a_concurrent_join_role_change`), and that a
member can make a guest a member but not an admin. Unit tests cover the
name limit and the workflow owner rule
(`owner_authority_denies_roles_that_cannot_write`). A relay test covers
huddle joins with different roles in the huddle and its parent, and a
commit after a demotion, a `join_role` change or a lost membership
(`huddle_join_needs_a_write_role_in_the_huddle_and_its_parent`).
Lock-order tests:
`join_role_change_waits_for_a_roster_publication_on_an_ephemeral_channel`
reproduced a real deadlock (`40P01`) against the old order.
`f2d_join_lock_order_serializes_membership_and_settings_writers` checks
that membership and settings writers wait for a join and then succeed.
`removed_creator_cannot_rejoin_a_private_channel` checks that
`put_member` refuses a removed creator on a private channel, and
`removed_creator_join_racing_a_private_switch_is_refused` holds the
membership lock so a removed creator's kind:9021 passes the open-channel
check, then makes the channel private before the join continues. Each
new test was run against the old code and failed.

## Rollout
1. **Before the deploy, count guest rows** (`SELECT count(*) FROM
channel_members WHERE role = 'guest' AND removed_at IS NULL`). We expect
none. Any guest that exists loses the ability to post, change the topic
and add people when this ships. If some exist, decide first whether to
make them members.
2. Deploy. Every channel stays `join_role = member`, so nothing else
changes.
3. **Do not set any channel to `join_role = guest` until no old relay is
running.** Old relays ignore the column, so they would let guests and
non-members write in that channel.
4. Rerun the `buzz-admin` channel reconcile so open channels drop the
wrong `closed` flag.

## Migration and rollback
- Migration `0067` adds `channels.join_role TEXT NOT NULL DEFAULT
'member'` with a CHECK constraint. Postgres stores a constant default in
table metadata, so existing rows are not rewritten and there is no
backfill. The relay runs the migration at startup.
- Existing channels keep the old `closed` flag until their next change,
or until the reconcile in Rollout step 4.
- **Before rolling back the relay**, set every announce channel back to
`join_role = member`. An older relay ignores the column and does not
stop guests from writing, so those channels would accept posts from
their guests and give `member` to new joiners again.

## Not in this PR
Client UI: a Follow button, hiding the composer for guests, and an admin
toggle. Clients that ignore the new tag keep working. A guest who tries
to post sees the `restricted` error.

## Stack
1. #8143 (this PR): announce channels
2. #8494: store the bot role only for keys with a recorded agent owner

---------

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
2026-10-21 16:01:11 -04:00
Mohammad Asfour
1a54eec3db fix(mobile): keep token labels visible in authored Markdown links (#7545)
## Summary

On iOS, an authored Markdown link renders as blank when its label is
recognized as a Buzz channel, mention, or custom emoji. For example:

```markdown
[#2959](https://example.com/)
```

The surrounding text remains visible, but the link has no visible label
or tap target.

Buzz's `_ChannelLinkMd`, `_MentionMd`, and `CustomEmojiMd` components
return `WidgetSpan`s. `gpt_markdown` also renders an authored link
through a `WidgetSpan` and reparses its label through the registered
components. Because the Buzz components were allowed to run inside link
labels, the result was a placeholder nested inside another placeholder,
which does not paint on iOS.

This PR adds the same scope restriction used by `gpt_markdown`'s
built-in link component:

```dart
@override
Set<MarkdownScope> get scopes =>
    MarkdownComponent.allScopesExceptLinkLabel;
```

The override is applied to all three widget-based components. Authored
labels such as `[#2959](url)`, `[@Alice](url)`, and `[👋](url)`
therefore remain ordinary link text, while the same tokens outside links
continue rendering as Buzz pills and custom emoji.

The PR also updates the shared test helpers to find `RichText`
subclasses. Since the upgrade to `gpt_markdown` 1.2.1, body paragraphs
can render through `BidiRichText`; `find.byType(RichText)` does not
match that subclass and could allow an absence assertion to pass without
inspecting the message text.

The handling of unknown bare `#tokens` is deliberately unchanged.
Whether those should remain non-interactive pills or become plain text
is a separate product decision.

### Related issue

Fixes #6124.

This supersedes #6135. That PR solves the same issue by maintaining a
custom fork of `gpt_markdown`'s link component; this PR instead uses the
scoped-component API already available in `gpt_markdown` 1.2.1.

### Testing

Focused suites:

```bash
flutter test \
  test/features/channels/message_content_test.dart \
  test/features/channels/message_content_custom_emoji_test.dart
```

Result: 95 tests passed, 0 failed.

Additional checks:

- `just mobile-check` — passed; analyzer reported no issues.
- `just mobile-fmt` — passed; 549 files formatted with 0 changes.
- Six new regression tests cover channel, mention, emoji, plain-link
control, and outside-link behavior.
- Removing the `_ChannelLinkMd` override causes two regression tests to
fail; removing `_MentionMd` or `CustomEmojiMd` causes one test to fail
in each case.
- Three tests in `message_content_test.dart` directly assert that the
nested-placeholder structure is absent. The custom-emoji tests
separately verify literal text and the absence or presence of
`CustomEmojiImage`, depending on whether the shortcode is inside or
outside a link.

The complete local mobile suite reports 15 failures that reproduce
identically on a clean checkout of `main` at `44316ff7`. In [CI for that
same commit](https://github.com/block/buzz/actions/runs/34238736818),
`Clients / Mobile`, `Mobile`, and `Mobile Swift Domain / Mobile Swift`
all passed.

No native-device screenshot is included. The nested-placeholder fix was
verified through the rendered widget structure, but an iOS simulator
build was blocked by the existing `MLImage.framework` arm64-simulator
incompatibility.

Signed-off-by: Mohammad Asfour <masfour700@gmail.com>
Signed-off-by: Samin Yeasar Sohag <sssohag172@gmail.com>
Co-authored-by: Samin Yeasar Sohag <sssohag172@gmail.com>
2026-10-21 10:24:32 -07:00
Logan Johnson
c37d6b8eb6 test(relay): cover system channels in the workflows API and push matcher (#8509)
🤖
## Summary
Test-only. This adds end-to-end coverage for the last two system channel
read paths that had none. It changes no behavior.

A system channel is a channel type the relay leaves out of ordinary
reads. A client sees one only when it names the channel or opts in. The
system channels spec lists every read path that must follow this rule.
The Postgres end-to-end tests already covered subscriptions, counts,
search, the HTTP bridge and membership notices, but not these two:

- **Workflows API.** A workflow names its channel, so reading a workflow
in a system channel follows ordinary channel access. Members can read
it. Outsiders can read it only when the channel is open. For a private
one, an outsider gets 404, the same answer as for a missing workflow.
- **Push notifications.** This is database-backed matcher coverage: the
test stores real channel rows, memberships and push leases, loads the
matcher's context from the database, and runs the production matcher. It
builds the match batch directly, so it does not cover the outbox or
gateway delivery. A member's push filter that names no channel gets a
wake for a message in an ordinary channel, but not for a message in a
system channel. A member's filter that names the system channel by `#h`
gets a wake for that channel only (the rule since #8517). A non-member's
filter gets neither.

### Related issue
Part of the system channels spec (risks section: end-to-end cases for
the workflows API and push). Rebased on #8507 and #8517, which made push
follow the read rule: a system channel pushes only to a member's filter
that names it by `#h`. No duplicate PR found.

### Testing
- Both tests pass against local Postgres and Redis on this branch.
- Each test fails when the behavior it covers is removed: without the
named-channel check in the workflows API, a member gets 404 for its own
system channel's workflow; if the push matcher lets a filter that does
not name a system channel match it, the member's broad lease also wakes;
if the matcher never pushes system channels, the named lease does not
wake.
- clippy (`--tests -D warnings`) and fmt pass.

---------

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
2026-10-21 13:09:45 -04:00
Logan Johnson
cd8a968179 fix(relay): push system channel events to a lease that names them (#8517)
🤖
## Summary
Mobile clients can now get push notifications for a system channel, but
only when they ask for that channel by its ID. Before this change, the
relay never sent push for system channels, even when a client asked for
one directly.

System channels are channels the app uses for its own purposes (for
example, agent attention). They are hidden from clients that do not know
about them. #8507 made push use the same visibility rule as normal
reads: a push subscription sees a system channel, or any channel type
added later, only if its filter names that channel ID in `#h`. With that
rule, an older client can never get system channel pushes by accident.
The extra "never push system channels" rule in NIP-CL now only blocks
clients that ask on purpose, such as a future Live Activities
subscription. This PR removes that special case.

### Details
- `push_runtime.rs`: system channels now follow the same rule as other
named-only channel types. The relay still checks membership before it
sends a wake.
- `NamedOnlyChannels::is_system` had no other caller, so it is removed.
- NIP-CL and NOSTR.md now describe the shared rule instead of the ban.
- No behavior change for current clients. They do not name system
channels in their push subscriptions.

### Related issue
Follow-up to #8507 (see
https://github.com/block/buzz/pull/8507#issuecomment-6316180106).

### Testing
- `named_only_channel_pushes_only_to_a_filter_that_names_it` now expects
a wake for a system channel named by `#h`. It also checks that a broad
filter still gets no wake, and that a non-member still gets no wake.
- `cargo test -p buzz-relay --lib push_runtime`, `cargo clippy -p
buzz-relay --all-targets -D warnings`, and `cargo fmt --check` pass.

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
2026-10-21 10:38:57 -04:00
Logan Johnson
4dea51f644 fix(relay): scope push matches with the read path's channel rule (#8507)
🤖
## Summary
This is a consistency and forward-compatibility fix. It does not change
what users of current clients see.

Mobile push notifications now decide which channels can notify a device
with the same rule that reads use, with one exception that the protocol
requires: system channels never push.

Before this change, push and reads used two separate rules:
- **Reads** (subscriptions, counts, search and the bridge) show only the
original channel types (stream, forum, DM, workflow) unless the filter
names the channel.
- **Push** skipped only `system` channels.

Today `system` is the only non-original type, so the two rules give the
same result. But a channel type added later would be hidden from reads
and would still send push notifications to every member. This PR removes
that gap: push now calls the same function that reads use, so a future
type gets the correct push behavior with no extra work.

## What changes
- A channel of an original type pushes as before. Membership is still
required.
- A system channel never pushes, even when a push filter names it.
NIP-CL says: "The relay MUST NOT send push notifications for system
channels." This is the same as before.
- A channel of a type added later pushes only to a push filter that
names that channel with `#h` (the channel tag), as reads do.
- A push filter that names one channel does not get pushes from other
named-only channels.
- Events that are not in a channel (for example gift wraps) match as
before.

Push filters cannot carry the `#t` or `#P` opt-in that reads accept, so
for push, naming the channel means `#h` only.

## Impact on current clients: none
- System channels still never push, and no current channel type is
affected by the later-type rule.
- The mobile app names channels by `#h` only for joined, unarchived DM
channels (`mobile/lib/shared/push/push_subscription_provider.dart`). DMs
are an original type.
- Naming a channel cannot get around membership. A push filter that
names a channel still gets nothing unless its owner is a member of that
channel.
- Database cost is unchanged: one per-batch query replaces another, on
the same channel list, with no extra round trip.
- The push docs (NIP-PL and the push suppression doc) do not mention
channel types, so they need no update.

## Details
- The push matcher loads the named-only channels in each batch and
checks each lease filter with `filter_channel_scope`, the function REQ,
COUNT, search and the bridge already use. Before that check, it rejects
system channels outright.
- This removes `system_channel_ids_among`, which push was the last
caller of.

### Related issue
Part of the system channels spec (§2, rule 5). Builds on #8181 and
#8469. No duplicate PR found.

### Testing
- A `match_job` unit test covers: unnamed filters on an original-type
channel, on a channel-less event, on a system channel and on a
later-type channel; a later-type channel named by `#h` (1 wake); a
system channel named by `#h` (0 wakes); an unrelated `#h` (no widening);
and non-members. Removing either the shared scope check or the system
exception fails it.
- Before this PR, no test covered the push channel filter, not even for
`system`.

---------

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
2026-10-21 08:42:30 -04:00
Jason Holmes
ce3fc78cbd feat(ws-client): send custom headers on the WebSocket upgrade (#8159)
## Summary

NIP-FI relays verify the `Nostr-Federated-Identity` assertion on the
WebSocket upgrade request (#7224) and pair it with the NIP-42 AUTH key,
but `NostrWsConnection` can only connect from a bare URL, so no
`buzz-ws-client` consumer can present an assertion today.

This adds two additive constructors:

- `NostrWsConnection::connect_with_headers(url, headers)`
- `NostrWsConnection::connect_authenticated_with_headers(url, keys,
auth_tag, headers)`

The existing `connect` and `connect_authenticated` delegate with an
empty `HeaderMap`, so their behavior is unchanged (`connect_async(&str)`
already went through `into_client_request`). `HeaderMap`, `HeaderName`,
and `HeaderValue` are re-exported so callers don't need a matching
`tungstenite`/`http` dependency.

Caller headers are added after the handshake headers; the doc comment
notes that supplying a handshake header such as `Sec-WebSocket-Key`
replaces it. tungstenite doesn't follow redirects, so upgrade
credentials can't be forwarded to another origin.

Follow-up (not in this PR): renewing assertions on long-lived
connections. The relay ends the session at the assertion's deadline, so
clients reconnect with a fresh assertion; that's caller policy rather
than a transport concern.

### Related issue

NIP-FI spec: #1485. Relay enforcement: #7224, #7264. No existing
client-side issue or PR found.

### Testing

- New `connect_with_headers_sends_headers_on_upgrade` test runs a local
`accept_hdr_async` server and asserts the header arrives on the upgrade.
Confirmed it fails when the headers are dropped.
- `cargo test -p buzz-ws-client` (4 passed)
- `cargo clippy -p buzz-ws-client -p buzz-test-client -p buzz-cli
--all-targets -- -D warnings`
- `cargo fmt --all -- --check`
- Not run: full `just ci` (desktop/mobile toolchains unavailable in my
environment) and an end-to-end connect against a local relay with NIP-FI
enforcement on.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Jason Holmes <holmes@squareup.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 20:24:35 -07:00
klopez4212
0768397092 feat(mobile): show inline human typing and outgoing avatars (#8505)
## Summary

People typing in a mobile channel now appear beside their avatar in an
inline three-dot bubble, using the existing agent typing animation
instead of the separate composer status strip. Human avatars stay round;
agent identities retain their agent shape. Reduced Motion keeps the dots
still, and thread-scoped typing remains inside its thread.

Restore the viewer’s avatar on the right of their own messages in
channel and Me timelines. Grouped messages show the avatar on the final
bubble, with reactions and reply footers aligned to the bubble.

### Related issue

No duplicate found. Related: #3668 tracks observer-backed agent working
status; this PR changes presentation only and does not add observer
lifecycle behavior.

### Testing

- `just mobile-install`; final pre-push `just mobile-check && just
mobile-test` passed (3,728 tests passed, 16 skipped; 4 unconfigured-push
tests passed). Repository file-size gate and commit formatting passed.
- Regression checks fail against the original channel typing and
outgoing-avatar implementation.
- Pixel 10 / Honeycomb Studios: the recording build exercised inline
human/agent typing, avatar shapes, own-message avatars, and message
arrival. That build predates this fresh-main PR; the PR additionally
uses the shared agent identity lookup.
- Before/after widget-rendered previews use generic sample messages. No
recording identity, app-package override, or demo scripts are included.

### Before / after

Rendered from the production channel widgets using generic sample
messages; Reduce Motion enabled for the stills.

| Before | After |
| --- | --- |
|
![Before](https://raw.githubusercontent.com/block/buzz/cc8df55d3a8bbccee4205593fbcff6760a7d1143/pr-8505--before.png)
|
![After](https://raw.githubusercontent.com/block/buzz/cc8df55d3a8bbccee4205593fbcff6760a7d1143/pr-8505--after.png)
|

### Manual check

Open a channel and have another person type: their round avatar and
animated dots should appear at the bottom of the conversation and
disappear when the message arrives. Send two consecutive messages: your
avatar should appear once beside the final bubble. Repeat with Reduce
Motion and larger text.

Draft pending human testing of this PR snapshot. Do not merge based on
the earlier recording alone.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-20 21:59:41 -04:00
ngoodger-block
76d792f288 BUZZ-357: feat(cli): token-lean agent output format for event reads (#8234)
### Why?

Agents read channel history with `buzz messages get/thread`. Every
returned event includes its 128-hex `sig`. Every agent-authored message
also carries a NIP-OA `auth` tag, which is another owner pubkey and a
128-hex signature. An agent can't use either of these, but pays for them
on every history read. Measured with Claude's tokenizer, that is about
88 tokens per human message and about 180 per agent message, so a
history read shrinks 33% for short human messages and 40% once agent
messages are in the mix (details in the comment below). The existing
`compact` format is fixed at `{id, content, created_at}` (#6884), which
drops the author, tags and reply target, so agents can't use it.

### What?

- **New `--format agent` for event reads.** Applies to `messages
get/thread/search` and `feed get`.
- Drops `sig`, and trims the NIP-OA `auth` tag to `["auth", <owner>]` so
agents can still tell an author is an agent and who owns it.
- Folds the NIP-10 `root`/`reply` tags into a `reply_to` field, using
the same resolver as relay ingest, plus `thread_root` on nested replies.
That's the value `messages send --reply-to` takes.
- Keeps every other tag exactly as `json` output shows it: channel,
mentions, edit targets, diff metadata.
  - Non-event reads return the same output as `json`.
- **Default for agents.** Without `--format`, the CLI falls back to
`BUZZ_OUTPUT_FORMAT`; an empty or unknown value means `json` with a
warning, so a harness/CLI version mismatch never breaks commands.
buzz-acp sets it to `agent` for every agent runtime through
`default_agent_env` and forwards the effective value in the explicit MCP
server environment, so operator or persona env still wins, and `--format
json` still returns full signed events. buzz-agent adds the variable to
its MCP env allowlist.
- **Docs and cleanup.** The managed-agent skill doc (version bumped to
7) and `AGENTS.md` describe the new default. The two duplicate
`format_events` copies in `messages.rs` and `feed.rs` are now one
`commands/event_output` module, which also does the NIP-10 tag parsing.
The `json` and `compact` output contracts are unchanged.



### Example output
https://github.com/block/buzz/pull/8234#issuecomment-6259679347

### Testing

Started `buzz-acp run` with the deterministic task-agent fixture, then
passed its `session/new` MCP environment to Codex 0.163.0 (`codex
app-server`). With no format override the MCP child received `agent`;
operator overrides of `json` and `compact` reached the MCP child
unchanged. The probes used temporary local sessions and made no model
requests.

### Related

Same change on the other agent read surfaces: each drops `sig`, trims
`auth` to `["auth", <owner>]` and keeps thread context.
- block/buzz-app#1388: buzz-app MCP read lines (text, `claimed
owner`/`reply_to`)
- squareup/cash-server#139132: hosted agents' read tools (JSON events,
raw NIP-10 tags)

Generated with Codex

---------

Signed-off-by: Nikolaj Goodger <ngoodger@squareup.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 12:54:05 +11:00
Diem Nguyen
427488e2fc fix(desktop): surface a missing DATABRICKS_HOST instead of loading models forever (#8504)
## Summary

If the `databricks` / `databricks_v2` provider is selected but
`DATABRICKS_HOST` isn't set, the Model field stays on "Loading
models..." forever and never shows an error.

How it happens:

1. Desktop discovers Databricks models in-process only when
`DATABRICKS_HOST` is set. Without it, discovery falls back to `buzz-acp
models`. buzz-agent then fails at config time with `DATABRICKS_MODEL
required` (model is checked first) or `DATABRICKS_HOST required`.
2. `formatModelDiscoveryErrorStatus` maps those errors, and
`BUZZ_AGENT_PROVIDER is required`, to a `null` status. The idea was that
the field's Required row would explain the problem.
3. `deriveModelDiscoveryPending` treats "no data and no status" as still
pending. So a failed discovery with a `null` status looks like it is
still loading.

The fix:

- `formatModelDiscoveryErrorStatus` now always returns a status, and its
return type is no longer nullable. A failed discovery therefore always
settles.
- A missing Databricks host shows: "Set DATABRICKS_HOST to your
Databricks workspace URL under Advanced to load Databricks models."
- A missing provider shows a muted "Choose a provider to load models."

Builds that bake `DATABRICKS_HOST` in never reach this path.

### Screenshots

Settings → Agents → Agent defaults, with Buzz Agent + Databricks v2
selected, no `DATABRICKS_HOST`, and model discovery failing with
`DATABRICKS_MODEL required`. Captured from the desktop e2e build with
the mock bridge. The only difference between the two builds is
`personaModelDiscoveryStatus.ts`.

| Before | After |
|---|---|
| ![Before: Model field stuck on Loading
models](https://raw.githubusercontent.com/block/buzz/bbdfc1f8eb91d8f0f5dc6fd98567bc6af62d8117/pr-8504--before.png)
| ![After: Model field asks for
DATABRICKS_HOST](https://raw.githubusercontent.com/block/buzz/bbdfc1f8eb91d8f0f5dc6fd98567bc6af62d8117/pr-8504--after.png)
|

### Related issue

None found. Searched open PRs that touch `personaModelDiscoveryStatus` /
`usePersonaModelDiscovery`, and issues mentioning "loading models".

### Testing

- New jsdom test drives the real `usePersonaModelDiscovery` hook with a
rejected `DATABRICKS_MODEL required` discovery. It asserts that loading
settles and that the status names `DATABRICKS_HOST`. On `main` the test
fails (`modelDiscoveryLoading` stays `true`), and it passes with this
change.
- Updated unit tests in `personaModelDiscoveryStatus.test.mjs`.
- `pnpm test` in `desktop/` passes (6834 + 161 tests). `tsc --noEmit`
and biome are clean.
- Exercised in the desktop e2e build with the mock bridge (screenshots
above). Not yet exercised in the real Tauri app.

Signed-off-by: Fizz <6be7be23ec5bba868f3e1db5ec86013d76bd1a293dce5b435a192158fec13641@buzz.block.builderlab.xyz>
Co-authored-by: Fizz <6be7be23ec5bba868f3e1db5ec86013d76bd1a293dce5b435a192158fec13641@buzz.block.builderlab.xyz>
2026-10-20 18:03:48 -07:00
Will Pfleger
7e6461242a feat(audio-client): accept a client request in connect (#8497)
## Summary

Related:
[block/buzz-app#1424](https://github.com/block/buzz-app/pull/1424)
(native federated sessions; attaches the assertion on Huddle audio once
this lands)

`buzz_audio_client::connection::connect` took the audio URL as `&str`,
so a host had no way to add headers to the WebSocket upgrade. buzz-app
needs to send its NIP-FI user assertion (`Nostr-Federated-Identity:
Bearer <jwt>`) on the Huddle audio socket. The relay checks NIP-FI when
the audio connection upgrades (`audio/handler.rs` →
`check_nip_fi_at_upgrade`).

This PR widens the parameter to `impl IntoClientRequest + Unpin`, the
same bound `connect_async_tls_with_config` already takes. Nothing else
changes: TLS, timeouts and the NIP-42 handshake work as before. Existing
`&str`/`&String` callers, including
`desktop/src-tauri/src/huddle/relay_api.rs`, compile unchanged.

---------

Signed-off-by: Will Pfleger <wpfleger@block.xyz>
Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
2026-10-20 22:58:04 +00:00
Tom Brow
93114b4279 fix(mobile): lazily lay out new-DM recipients (#8435)
The new-message picker laid out every recipient inside an outer scroll
view. Searching or changing selection could therefore mount the whole
directory in one frame. Use a bounded sliver viewport so offscreen
recipients stay lazy while the search field and selection chips still
scroll above the keyboard.

### Validation

- Current-head CI passed, including all Flutter test shards, Android,
and native/release Swift jobs. Code and security reviews found no
issues. After merging main and retaining both test imports, all 81
channel-page tests and the full mobile check/test suite passed.

- Added a 200-person widget regression: the original mounts all 200
rows; the fix keeps fewer than 30 mounted through open, search,
selection and removal, and can scroll to the final recipient. Covers
no-match and closing too.
- Strengthened the keyboard/chip test to verify the eight-recipient
limit and that removing a chip makes the ninth recipient reachable.
- All 79 channel-page tests passed; the strengthened limit test and
Flutter analysis passed.
- Native iOS simulator build passed. On a separately cloned paired
simulator, verified populated directory/search, eight selected
recipients, limit message, removal, no-match, scrolling to the final
recipient and close without creating a conversation. Debug/AX
instrumentation and a newer Flutter baseline make this functional
validation, not a controlled release-speed benchmark.
- Normal pre-push mobile checks passed, including formatting, analysis
and the full Flutter test suite. Required CI exposed existing formatting
in `message_carousel_preview_cases.dart`; a separate formatter-only
commit corrects it.
- The full local repository gate hit an unrelated Rust failure in
`buzz-acp::signals_cancel_startup_turn_and_pending_stdin_without_hanging`
(exit status `None` rather than `Some(143)`). No Rust code changed. The
gate stopped at unit tests, so later build stages did not run.

### Related issue

No duplicate recipient-layout fix found in the existing issue/PR search.

### Before and after

The synthetic 200-person picker renders identically before and after
(with a reserved keyboard inset). One image represents both; mounted-row
assertions establish the performance mechanism separately.

![Recipient picker before and
after](https://raw.githubusercontent.com/block/buzz/c9980118b75e64ee8ba0b559b7cc981ee59f809b/pr-8435--dm-directory.png)

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
2026-10-20 15:17:52 -07:00
Tom Brow
bf4a163510 fix(mobile): lazily lay out channel member groups (#8437)
Opening a large channel member sheet mounted and laid out every person
in a grouped column. A captured Debug simulator entrance spent 242 ms in
the UI callback, including 223 ms in layout.

Build each person and agent as a lazy sliver row while preserving the
grouped cards, names, statuses, management menus, and activity actions.
Screen-reader row indices continue across both groups. A separate
formatting-only commit fixes an existing carousel-test formatter
discrepancy. No duplicate member-sheet performance PR or issue found.

### Validation

- Added a 200-member widget regression: the original mounts 100 people
initially; the fix mounts fewer than 20 nearby rows and reaches the
final person and agent.
- Added grouping, compact sizing, empty state, member tap identity,
accessible indices, and scrolled member/agent menu checks. Existing
channel-details “See all” navigation test passes.
- Mobile formatting, static analysis, and the full mobile test suite
passed on the committed tree.
- Synthetic before/after rendering is pixel-identical at the same
viewport.
- Populated native iOS 26.5 simulator workflow: open members, scroll
through people and agents to the end, then close. Final installed build
passed this workflow.

Debug, accessibility automation, profiler overhead, different Flutter
versions, and shared-host load limit timing conclusions. This removes
eager offscreen layout; it does not establish a controlled end-to-end
speedup or release-device performance.

### Visual check

Synthetic member sheet; before and after are pixel-identical at this
viewport.

![Synthetic member
groups](https://raw.githubusercontent.com/block/buzz/c327b1d973e6ec54a09358e8f6794dc0a2587304/pr-8437--members.png)

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
2026-10-20 15:14:29 -07:00
Tom Brow
a93f3282cc perf(mobile): retain preference crypto across reconnects (#8442)
Foreground reconnects rebuild preference managers and repeatedly derive
the same NIP-44 keys on the UI isolate. Retain the six crypto objects in
providers scoped to relay configuration and identity while preserving
manager refresh, subscription, and publication behavior. Community
changes, key rotation, and sign-out invalidate the retained objects.

RelayConfig normalizes the signing key once at its shared accessor, so
identity, theme encryption, event signing, and NIP-42 authentication
receive the same value, including when an active configuration key has
surrounding whitespace. The identity-export authorization snapshot uses
the same normalized key for the active-identity check and the outgoing
recovery payload. The branch incorporates main's relay-scoped preference
managers.

### Validation
- Regression exercises six production crypto providers across
reconnects, configuration/key changes, and sign-out. Reintroducing a
session dependency makes it fail.
- Added a loopback WebSocket regression that exercises actual
RelaySocket NIP-42 authentication with a padded key and verifies its
challenge, relay, pubkey and signature. It fails before shared key
normalization.
- Added a connected-theme regression for whitespace-padded keys,
encryption round-trip, and a valid published event signature. It fails
before the normalization fix.
- Added padded-key identity export coverage through authorization, SAS
confirmation, exactly one normalized payload, and successful completion.
Separate relay-change and key-rotation tests verify both fresh and
expired grants fail closed. The padded-key regression failed before the
fix.
- Current head: all 48 focused pairing/crypto/auth tests and mobile
analysis passed. All [CI
checks](https://github.com/block/buzz/actions/runs/39497098787) passed,
including mobile test shards, Android, native Swift tests and release
builds. Codex feedback is addressed; Jude approved this exact head after
independent regression and mutation checks. Fresh [Codex security
review](https://github.com/block/buzz/pull/8442#issuecomment-6300273942)
found no concrete issues.
- Previous head: 122 config/socket/crypto/theme tests, 44 read-state
tests, and all [GitHub CI
checks](https://github.com/block/buzz/actions/runs/39491550425) passed,
including mobile test shards, Android, native Swift tests and release
builds.
- Original implementation: native iOS Debug build and full local
repository checks passed. A paired simulator background/resume capture
had no samples in the targeted crypto constructors or key derivation; an
82 ms UI frame remained. Debug/JIT, profiler overhead and shared-host
activity prevent an overall speedup claim. The later normalization
change is covered by the production-provider regression above.
- Two image decode timing failures occurred in the initial local full
suite; direct baseline/patch runs, the subsequent full repository run,
and the latest full mobile suite passed.

Cold-start credential validation is unchanged: padded persisted keys are
rejected by AuthNotifier before RelayConfig is constructed. The
normalization regressions cover active configurations and identity
export, not broader persisted-key acceptance.

<!-- buzz-review-completed -->

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
2026-10-20 14:57:53 -07:00
Diem Nguyen
8bbfe44f77 fix(deps): bump webpki crates for RUSTSEC-2026-0381/0382/0383 (#8499)
## Summary
On 2026-10-19, RustSec published three advisories against the TLS
certificate crates in our lockfiles. Since then, `cargo-deny check`
fails on advisories. That breaks `Security Domain / Security` on `main`
and on every PR that runs the Rust security job.

| Advisory | Crate | Change |
|---|---|---|
| RUSTSEC-2026-0382 | `rustls-webpki` (distrusted intermediates) |
0.103.15 → 0.103.16 |
| RUSTSEC-2026-0381 | `webpki-roots` (distrusted emSign roots) |
1.0.7/1.0.8 → 1.0.10 |
| RUSTSEC-2026-0383 | `webpki-root-certs` (same roots) | 1.0.7/1.0.8 →
1.0.10 |

This PR bumps all three in `Cargo.lock` and
`desktop/src-tauri/Cargo.lock`. Only these packages change.

`webpki-roots 0.26.11` stays because `tokio-tungstenite` 0.28/0.29 (via
axum and nostr-sdk) still require `^0.26`, and no patched 0.26 release
exists. 0.26.11 is a semver-trick shim that bundles no certificates of
its own. It re-exports `webpki-roots` 1, which now resolves to the
patched 1.0.10. `deny.toml` ignores RUSTSEC-2026-0381 for that shim and
explains why. The ignore should come out once those consumers move to
`webpki-roots` 1.

### Related issue
N/A. I searched for open PRs bumping these crates and found none.

### Testing
- `cargo-deny check`: `advisories ok, bans ok, licenses ok, sources ok`.
On `origin/main` it reports `advisories FAILED`.
- `cargo check --locked -p buzz-ws-client -p buzz-cli -p buzz-relay`
passes.
- The pre-push hook's Rust unit tests pass.

Signed-off-by: Fizz <6be7be23ec5bba868f3e1db5ec86013d76bd1a293dce5b435a192158fec13641@buzz.block.builderlab.xyz>
Co-authored-by: Fizz <6be7be23ec5bba868f3e1db5ec86013d76bd1a293dce5b435a192158fec13641@buzz.block.builderlab.xyz>
2026-10-20 21:52:14 +00:00
klopez4212
ca35114209 fix(mobile): simplify and refine the quick actions menu (#8491)
Keeps the mobile + menu focused on Create channel and New direct
message, with 8-point facing corners, a 6-point gap, and the active
Home/Solo tab fill on iOS.

Moves Browse channels directly above the channel list, including its
empty state, preserving open-channel discovery, retry, and Join. Adds a
cold-start journey through the real channel loader and join action with
relay boundaries faked.

Validation: mobile formatting/analysis and full mobile test suite;
mutation check confirms the new journey fails when directory loading is
removed. The original menu styling was tried on a physical iPhone; the
replacement Browse entry has widget-journey coverage and has not yet
been tried on device.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-20 17:38:29 -04:00
Jason Holmes
a5767c67de fix(sdk): reject malformed mention pubkeys before signing p tags (#6372)
## Summary

`buzz_sdk::builders::mention_tags` lowercased whatever string it was
handed and pushed it straight into a `p` tag, so malformed mention
pubkeys were signed onto real events. A composer that mentioned someone
this way looked successful while notifying nobody, and the bad tag
propagated to every relay and client that read it.

Reproduced before fixing: `""`, `"not-a-pubkey"`, `"zzzz"`,
`"../../etc/passwd"`, and 63/65-character strings were all accepted and
emitted verbatim as `p` tags by `build_message` and `build_forum_post`.

Fixes #6291

## Acceptance criteria → evidence

Following @kiranmagic7's [recommendation on the
issue](https://github.com/block/buzz/issues/6291):

| # | Criterion | Evidence |
|---|---|---|
| 1 | Validate in the **private `mention_tags`**, not the public
`normalize_mention_pubkeys` | `crates/buzz-sdk/src/builders.rs` — the
single changed line inside `fn mention_tags`.
`normalize_mention_pubkeys` is untouched, so no public signature
changes. |
| 2 | Reuse the existing **`check_pubkey_hex`** helper | `let lower =
check_pubkey_hex(hex, "mention pubkey")?;` replaces
`hex.to_ascii_lowercase()`. No new helper added. |
| 3 | Reuse the existing **`SdkError::InvalidInput`** |
`check_pubkey_hex` already returns `InvalidInput`; no new error variant
is introduced. |
| 4 | Cover all **3 builders** |
`malformed_mention_pubkeys_are_refused_by_every_builder` asserts against
`build_message`, `build_forum_post`, **and** `build_forum_comment` — all
three share `mention_tags`. |
| 5 | Reject **empty / non-hex / 63-char / 65-char** | Same test's
table: `""`, `"not-a-pubkey"`, `"zzzz"`, `"../../etc/passwd"`, `"a"*63`,
`"a"*65`, plus `"z"*64` and a 64-char path-like string so a length-only
check cannot pass. |
| 6 | Preserve valid **uppercase canonicalization** |
`valid_mentions_are_canonicalized_and_deduped_across_case` — uppercase
hex is accepted and the emitted `p` tag is lowercase, across all three
builders. |
| 7 | Preserve valid **dedupe** | Same test: the same pubkey in both
spellings collapses to exactly one `p` tag. Pre-existing
`message_mentions_deduped` still passes. |
| 8 | Preserve **`TooManyMentions` precedence** for >50 |
`too_many_mentions_takes_precedence_over_validation` — a 51-entry list
that also contains a malformed entry still returns `TooManyMentions`.
The cap check stays ahead of validation.
`mentions_at_the_cap_still_sign` pins that the boundary itself did not
move. |
| 9 | Inspect **#3036 overlap**; keep the patch narrow | See the
compatibility note below. |
| 10 | Make these tests actually **gate** | `Justfile` +
`scripts/run-tests.sh` — see "Why the runner change is here". |

Out of scope by design: switching to `nostr::PublicKey::from_hex`. Its
stricter on-curve rule would change every one of `check_pubkey_hex`'s
~26 call sites, which is a repo-wide consistency decision rather than
part of this fix. The doc comment records that reasoning.

## Why validation lives in `mention_tags`

`mention_tags` is the single choke point every mention reaches, shared
by all three builders, and callers can hand those builders an explicit
list without ever going through `normalize_mention_pubkeys`. Validating
here closes that bypass without breaking the normalizer's public API.

This also aligns the SDK with behavior already shipping elsewhere:
desktop's own `events.rs::mention_tags` already validates with
`check_pubkey` on the identical structural rule (64 ASCII hex). The SDK
was the inconsistent one.

One malformed entry refuses the whole list rather than being filtered
out — a silently dropped mention is precisely the failure being fixed,
and filtering would preserve it.

## Why the runner change is here

Adding `buzz-sdk` to `just test-unit` and the mirrored
`scripts/run-tests.sh` fallback is a CI-behavior change, so it deserves
its own justification: **without it the regression tests above would
never run in CI.** `buzz-sdk` is a workspace member, so it was getting
`clippy` and `check`, but no CI job executed a single one of its tests.
This is the exact hazard the `Justfile` already warns about for other
crates — *"nothing in CI runs `cargo test --workspace` — workspace
membership alone buys clippy/check, not a single executed test."*

Verified with a positive/negative control rather than by reading the
config:

- **Negative control** — with the runner files at pristine `main` and a
deliberately panicking `buzz-sdk` test in the tree, `just test-unit`
exited **0** and printed "All tests passed!". The crate name never
appeared in the log.
- **Positive control** — same sabotaged test, with only these two runner
edits applied: `just test-unit` exited **1** with `buzz-sdk tests
FAILED`.

The sabotage test was removed afterward; it is not part of this PR. Both
entries are needed because the two lists (nextest path and the
no-nextest fallback) must stay in step. This is scoped strictly to
making the crate's existing tests execute — no other CI behavior is
touched.

## Compatibility with #3036

#3036 (`fix/nip10-reply-p-tags`) also edits `mention_tags`: it adds
`parent_author: Option<PublicKey>` to `ThreadRef`, emits a parent-author
`p` tag in `thread_tags`, and seeds `mention_tags`'s dedup set from `p`
tags already on `tags`. This PR replaces only the `let lower = ...` line
inside the loop, so the two changes are compatible in substance.
Mechanically, whichever lands second needs the trivial merge fixup:
#3036 adds `parent_author: None` to every `ThreadRef` literal, including
the ones in the tests added here.

One correction to the paragraph above, from an independent merge trial:
the fixup is not *only* the `parent_author: None` additions. Merging
#3036 into this head also produces one **textual conflict in
`crates/buzz-sdk/src/builders.rs`**, confined to the `mention_tags` doc
comment — both branches rewrote it, this PR to explain the validation
and #3036 to explain the seeded dedup set. The resolution is to keep
both blocks; there is no logic conflict, since this PR changes the `let
lower = ...` line and #3036 changes the `seen` initializer. For
reference, merging #3036 into plain `main` leaves `builders.rs`
auto-merging cleanly, so this conflict is specific to the combination.
Once the doc comment is resolved and `parent_author: None` is added to
the three new `ThreadRef` literals here, `buzz-sdk` compiles and the
only failing test is #3036's own `self_reply_drops_the_parent_p_tag` —
which fails identically with #3036 merged into `main` **without** this
PR, because `build_message` gained `.allow_self_tagging()` in #4975
after #3036's merge base.

## Test plan

- [x] `cargo test -p buzz-sdk` — **267 passed, 0 failed** (5 new tests;
pre-existing `message_mentions_deduped`, `message_too_many_mentions`,
and the three `*_preserves_self_mention_p_tag` tests still green)
- [x] `cargo fmt --all -- --check` — clean
- [x] `just clippy` (workspace, `-D warnings`) — clean
- [x] `just test-unit` — all 10 steps pass, now including `buzz-sdk`
- [x] `just file-size-check` — pass
- [x] `just desktop-tauri-fmt-check` / `desktop-tauri-check` /
`desktop-tauri-test` — pass (2684 tests; `desktop/src-tauri` consumes
`buzz-sdk`)
- [x] Full `just ci` — the remaining steps are JS/Dart (`desktop-test`,
`desktop-build`, `web-build`, `mobile-test`); this change touches only
Rust + two runner scripts, so CI covers them here

All gate results above were confirmed at commit
`5fe5929de39388cada354593ac875d3c42c3d830`.

## Open questions for maintainers

Out of draft and ready for review. Two calls I'd like from a maintainer:

1. **Do the runner entries belong here?** Adding `buzz-sdk` to `just
test-unit` and `scripts/run-tests.sh` is a CI-behavior change riding
along with a bug fix. I kept it because without it the regression tests
above never execute in CI (controls in the section above), but I'll
split it into its own PR on request.
2. **Is leaving `check_pubkey_hex` alone right for now?** Switching to
`nostr::PublicKey::from_hex` would add an on-curve check but changes the
contract at all ~26 call sites, which reads as a separate repo-wide
decision rather than part of this fix.

### A note on CI

The only check reporting here is **DCO Check** (pass). `CI`, `Desktop
Release Candidate`, and `Docker image` are all sitting in
`action_required` because this PR comes from a fork — a maintainer has
to approve the workflow run before they execute. That's the standard
first-time-contributor gate, not a failure, and I can't clear it from my
side. Every gate result in the test plan above is from local runs at
`5fe5929de39388cada354593ac875d3c42c3d830`, so CI has not independently
confirmed them yet.

Signed-off-by: rust worker <cb8459a6e4c936835834cef03b8331fe806108dd03da97d39c7036a7d710e860@buzz.block.builderlab.xyz>
Signed-off-by: Jason Holmes <holmes@squareup.com>
Co-authored-by: rust worker <cb8459a6e4c936835834cef03b8331fe806108dd03da97d39c7036a7d710e860@buzz.block.builderlab.xyz>
2026-10-20 13:44:19 -07:00
Tom Brow
cdc2b129c0 fix(mobile): resolve DM display labels once per sort (#8488)
Home's DM sort resolves participant identity names again for every
comparator call. This work appeared in a captured 82.163 ms UI frame
after foregrounding the full app (Debug/JIT iOS simulator, shared host).
Resolve each lowercase display label once per sort, retaining the same
label ordering and channel-ID tie-breaker. Sort keys are
invocation-local, so later viewer, profile, owner, participant, and
community changes cannot reuse stale labels.

No matching open mobile sorting PR or issue found.

### Validation

- Added synthetic regression coverage for bounded contextual resolution
and ordering parity across identity/name/channel changes, ties, unnamed
DMs, and empty/singleton lists. The 80-DM fixture performs 80 contextual
resolutions instead of the original comparator’s 982; restoring that
comparator makes the regression fail.
- 133 focused tests passed, including existing Home scrolling/reconnect
widget tests and identity-name tests.
- Mobile static analysis passed; 3,697 tests passed with 16 existing
skips, plus four no-gateway configuration tests.
- No new full-app or hardware capture. The existing trace establishes
repeated synchronous work, not its release-build magnitude or the cause
of every scrolling stall.

Signed-off-by: Tom Brow <tomb@block.xyz>
2026-10-20 13:13:15 -07:00
Luke Tornquist
fcdabcf774 docs(db): database target architecture and schema-change rules (#8273)
## Summary

Adds `docs/database.md`, which covers two things:

- **The target architecture.** `schema/tables/public/` is the
declarative source of truth, written within the constraints that
out-of-band, online schema tools can apply. Deployments at scale apply
schema changes out of band; auto-migration stays supported for smaller
and self-hosted deployments, and `migrations/` stays. The database has
no triggers, functions, or foreign keys; that behavior lives in the
owning application transaction or in durable application work. Data
repair runs through the backfill framework in `docs/data-backfills.md`,
not through migrations.
- **Rules for schema changes made now:**
1. Add no triggers, functions, procedures, rules, or foreign keys, with
no exceptions. New tenant-owned tables are fenced by community admission
in the application. Startup and deletion validation already tolerate
missing fences, but desired-state bootstraps still attach a fence
trigger to every `community_id` table, so a new tenant-owned table is
blocked until that loop stops (part of the fence-retirement work). The
doc includes checklists for adding a tenant-owned table and a
provenance-only table.
2. Migrations change schema only. They never mutate existing rows. Until
the backfill framework ships, a repair may be a reviewed, idempotent,
batched one-off script in `scripts/maintenance/` that takes the
community deletion lock and touches only active communities. A repair
that writes historical channel events must keep replica routing closed
until its WAL has replayed.
3. Update every schema location: `migrations/`, `schema/tables/public/`,
the manifest and sibling directories, the pgschema reconcile script
where it applies, and both homes of the existing `push_gateway_*` tables
(the target is for the gateway to own its tables alone). Never edit a
merged migration. Add catalog-level parity tests for what you touch.
4. Every migration must be safe for the relay that is currently
deployed, under both supported modes: auto-migration at startup and
out-of-band application. Either way the old relay runs against the new
schema for a while. Because auto-migration can apply expand and contract
in one boot, a contract migration must fail closed when its backfill has
not run, and a contract that depends on a writer release (such as
dropping a trigger whose work moved into the app) must name that release
as a required stop in the release notes, because no row check can prove
it. The order is expand, deploy, backfill, then contract. The doc
includes a table of changes that break the old relay and the safe form
of each.
5. Bound every lock, build `migrations/` indexes concurrently (the
declarative schema uses plain `CREATE INDEX`), and keep changes within
what out-of-band apply can make online.

AGENTS.md (Product Contract), ARCHITECTURE.md (buzz-db), and new
path-local `migrations/AGENTS.md`, `schema/AGENTS.md` (a pointer), and
`crates/buzz-push-gateway/migrations/AGENTS.md` point to the doc. The
path-local files mean agents editing those directories get the rules
automatically. AGENTS.md also had a stale claim that migrations are
"auto-applied on relay startup". This PR corrects it:
`BUZZ_AUTO_MIGRATE` defaults off in the binary and on in the Helm chart,
and both modes are supported.

## What got simpler

The rules were scattered across `schema/schema.sql` comments, AGENTS.md
Common Gotcha #7, the backfill spec, `docs/thread-window-deployment.md`,
and test names. They now live in one document, and the rest link to it.
No code changes.

## Testing

This PR changes documentation only. I checked links and diffs, and every
claim in the doc points to code at the base commit: the layout and
parity tests in `crates/buzz-db/src/runtime/migration.rs`,
`EXPECTED_SCOPED_TABLES` and the serving-catalog check in
`crates/buzz-db/src/store/deletion.rs`, and `BUZZ_AUTO_MIGRATE` in
`crates/buzz-relay/src/main.rs`. The new `AGENTS.md` files aren't
`.sql`, so neither the sqlx migrator nor the schema layout test picks
them up; CI's layout, migration-count, and deletion-parity tests pass.

At an earlier head, a real relay against isolated PostgreSQL 17 showed
that a new unfenced `community_id` table serves normally and makes
community deletion report `unknown=<table>`. Since then, the fence
requirement at startup was removed on main; the doc now cites
`migration_schema_fence_objects_are_optional_for_serving_and_deletion`
for that.

---------

Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
2026-10-20 15:47:05 -04:00
klopez4212
5fefec604f fix(mobile): restore channel icons and align chat colors with desktop (#8478)
## Summary
- Restores `#` and lock icons for public and private channels on Home,
with matching loading placeholders.
- Updates the dark-mode navigation colors to the desktop design-system
tokens (read and unread text, section headings).
- Replaces the chat color picker with the seven desktop accents (Gray,
Chartreuse, Flame, Magenta, Iris, Cobalt, Jade). Saved legacy colors map
to the closest one.
- Uses white text in your own bubbles, and black where white falls below
4.5:1 (Chartreuse, dark-mode Gray). Links (underlined), quotes, tables
and code use the same text color.
- Insets code blocks in bubbles evenly, with corners concentric to the
bubble and even inner padding.
- The swipe-to-reply indicator uses the chosen chat color.

## Testing
- `flutter analyze` and `dart format` are clean. The full mobile suite
passes (3,705 tests).
- Installed and checked on a Pixel 10 and an iPhone Air against a real
community.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Queue <874bf2d815c2c4b459b90438c669c57f2702f3a76bb6e16fa97184259aac3e9e@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 13:48:12 -04:00
Diem Nguyen
0b53fc699d test(desktop): read only the open effort menu in effort-picker e2e (#8476)
## Summary
`menuValues()` in `claude-effort-picker.spec.ts` read every
`menuitemradio` on the page right after it opened a menu. Dropdown menus
stay mounted for their 100ms exit animation
(`POPOVER_RADIX_MOTION_CLASS`). That means the model menu, which
`pick()` had just closed, could still be in the DOM, and its rows ended
up in the effort list:

```
- Expected  - 0
+ Received  + 6
+   "Default model (Opus)", "Opus", "Claude Sonnet 5", "Haiku", "Claude Opus 4.8", "Custom model...",
    "Adapter default", "max",
```

The helper now waits for the trigger to report `aria-expanded="true"`,
then reads rows only from the menu named in its `aria-controls`. The fix
only touches the test; no product code changes.

### Related issue
The flake was introduced with the spec in #8059. In CI it failed
`Desktop Smoke E2E (2)` on #8473 (all three attempts,
[job](https://github.com/block/buzz/actions/runs/39336482034/job/118347673219))
and failed once before passing on retry on #8474.

### Testing
- **Forced repro.** I temporarily stretched the closed-menu exit
animation to 1500ms using `page.addStyleTag` (not committed):
  - Before: 5/5 failed with the same `toEqual` diff.
  - After: 5/5 passed.
- **Natural repeats.** I ran `--repeat-each` locally with 3–4 workers,
100 runs on each version:
  - Before: 3 failures from the menu-row leak.
  - After: 0.
- Both versions also had the same local-only startup timeouts (`waiting
for getByTestId('open-agents-view')`), which this change doesn't affect.
- **Full spec.** `pnpm exec playwright test --project=smoke
tests/e2e/claude-effort-picker.spec.ts`: 27 passed.
- `biome check` is clean.

Signed-off-by: Fizz <6be7be23ec5bba868f3e1db5ec86013d76bd1a293dce5b435a192158fec13641@buzz.block.builderlab.xyz>
Co-authored-by: Fizz <6be7be23ec5bba868f3e1db5ec86013d76bd1a293dce5b435a192158fec13641@buzz.block.builderlab.xyz>
2026-10-20 09:53:46 -07:00
Ian Oberst
ca3be55018 fix(relay): advance the partition catch-all by default (#8464)
## Summary

The migrations leave `events` and `delivery_log` with a catch-all
partition that already covers every month from 2026-07. Only catch-all
advancement replaces it with monthly partitions. Advancement was off by
default, so any deployment that left out
`BUZZ_PARTITION_MANAGER_ADVANCE_ENABLED` routed every new row into the
catch-all. An operator then had to repair it by hand: drain the
catch-all, swap it for monthly partitions, and re-attach. This has
already happened in one staging environment.

- **Advancement on by default.**
`BUZZ_PARTITION_MANAGER_ADVANCE_ENABLED` now defaults to `true`, and an
explicit `false` still disables it.
`BUZZ_PARTITION_MANAGER_CREATE_ENABLED=false` remains the kill switch
for all automatic partition DDL.
- **Prompt retry while the current month routes to the catch-all.** If a
startup or periodic pass leaves the current month routed to an empty
catch-all that the maintenance planner would replace, the audit loop
retries on its existing backoff. That is 5 s, doubling to a 60 s cap,
for at most 8 retries (about 5 minutes). After that it returns to
`BUZZ_PARTITION_AUDIT_INTERVAL_SECS`. Before this change, a failed first
pass, such as a lock timeout during a rollout, waited the full 15
minutes.
- The routine monthly advance, where only the last lookahead month falls
into the catch-all, stays on the normal interval. Each attempt queues an
`ACCESS EXCLUSIVE` request on the parent, so it shouldn't be retried
without urgency.
  - The budget resets once the catch-all no longer awaits advancement.
  - A failed attempt keeps the last known state.
- Layouts the planner refuses, such as a catch-all that holds rows, need
an operator, so they are never retried early. Neither is a policy with
create or advance disabled.
- The check is `PartitionTableAudit::awaits_catch_all_advance(policy)`,
plus a `PartitionAudit` helper that applies it to every table. It is
derived from `plan_maintenance`, so it can't drift from the planner's
rules.
- **Fresh-install test.** A new `#[ignore = "requires Postgres"]` test
runs every migration in a dedicated database. It checks that both tables
start out waiting on the catch-all and that create-only maintenance does
not fix them. It then checks that the first pass with advancement
produces canonical monthlies, an empty `{table}_p_future`, trigger
parity and a non-degraded audit, and that a second pass is a no-op.

### Related issue

None found.

### Testing

**Automated:**
- `cargo test -p buzz-db --lib partition`, including `--ignored` against
local Postgres: 21 unit tests and 55 Postgres tests pass.
- `cargo test -p buzz-relay` for the config tests and the partition
schedule tests passes.
- `cargo clippy -p buzz-db -p buzz-relay --all-targets -- -D warnings`
and `cargo fmt --check` are clean.
- Mutation checks on `awaits_catch_all_advance`. Each fails the new unit
test:
  - matching any window month instead of the current month;
  - replacing the planner check with the policy flags alone;
  - short-circuiting the current-month gate.

**Local relay** (`BUZZ_AUTO_MIGRATE=true`, no advance env var):
- **Fresh database:** startup committed `advanced` for both tables,
creating `p2026_07` through `p2027_04` plus `_p_future`.
- **Failed first pass:** I held `LOCK TABLE ONLY communities IN SHARE
ROW EXCLUSIVE MODE` for 4 s across startup. The startup pass failed with
`lock_timeout` at 17:07:20.8, and the first periodic retry committed
`advanced` for both tables at 17:07:29.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ian Oberst <ioberst@block.xyz>
Co-authored-by: Ian Oberst <ioberst@block.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 16:20:18 +00:00
Luke Tornquist
039e1c8d59 feat(relay): write the NIP-43 member list in the membership transaction (#8482)
## Summary

The relay-signed NIP-43 member list (kind:13534) was published after
each membership change had already committed. If that publish failed, or
if a change never republished at all (startup `bootstrap_owner`), the
list stayed wrong until the background reconcile sweep found and fixed
it. #8467 moved that sweep off the startup path. This PR removes the
reason the sweep exists.

Now every `buzz-db` function that changes `relay_members` writes the new
list **in the same transaction**, as its last statement before commit:
- It takes the per-community list lock last, reads the members, signs
the list, retires the old one and inserts the new one.
- If the list write fails, the membership change rolls back and the
caller gets an error.
- A call that changes nothing (already a member, role mismatch, host
exists, limit reached) writes no list.

The functions return `MembershipWrite<T> { outcome, snapshot }`. Callers
push `snapshot` to live subscribers after commit. That push is the only
thing left outside the transaction; if it fails, live clients see the
change on their next fetch, and the stored list is already correct.

Write paths covered (RPR #2, every write path): `add_relay_member`,
`claim_relay_membership`, `claim_relay_invite`, `remove_relay_member`,
`remove_relay_member_if_role`, `update_relay_member_role`,
`bootstrap_owner` / `provision_owner`, `transfer_ownership`,
`backfill_from_allowlist`, and the owner insert in
`create_community_with_owner[_and_nip_fi_issuers]`. Community deletion
removes the members together with the community, so it writes no list.

The relay keypair is passed in explicitly instead of being stored on
`Db`, so the compiler finds every caller.

### Behavior changes

- **Open relays get an accurate list too.** Provisioning and ownership
transfer used to publish only when `require_relay_membership` was on.
The write is now unconditional.
- **Same-second changes can't reuse an id.** The list's `created_at` is
one second past the newest earlier list for that community, including
retired ones, or the current time if that is later. Before, adding and
then removing a member in the same second could produce an event with
the same id as an earlier list. The insert then failed, and the stale
list stayed live. A burst of changes can push `created_at` ahead of the
clock by up to one second per change; it returns to the clock once the
burst ends.
- **`buzz-admin add-member` / `remove-member`** no longer build their
own list (`publish_membership_list_with_bump` is deleted). They push the
list the database wrote. Concurrent CLI runs now serialize on the
database lock rather than depending on `run.sh` running one at a time.
- **Owner mutations lock the community row `FOR NO KEY UPDATE`.**
`transfer_ownership` and `bootstrap_owner` used `FOR UPDATE`. The list
insert takes `FOR KEY SHARE` on that row through `events.community_id`'s
foreign key, so a repair holding the list lock, or a removal or role
update holding a member row, deadlocked with a concurrent owner change.
`FOR NO KEY UPDATE` still conflicts with archive, unarchive and deletion
admission, so the lifecycle ordering is unchanged.
- **Startup delivers its list to other replicas.** When backfill or
`bootstrap_owner` changes members at startup, the relay fans the newest
list out through pub/sub once its state is ready, so clients connected
to other replicas during a rolling deploy see an owner rotation without
a refetch.
- **New `buzz-admin republish-members`.** Rewrites the community's list
from the stored members in one community-write transaction and pushes it
live. This replaces the sweep as the repair for a list that is missing
or stale: a `relay_members` change made directly in SQL, a restore, or a
deployment that turns on `BUZZ_REQUIRE_RELAY_MEMBERSHIP` after running
without it.

## Rollout

Nothing rewrites a list automatically once the sweep is gone. A
community whose list drifted before this deploys stays wrong until its
next membership change or until an operator runs `buzz-admin
republish-members`. Either deploy #8467 and let its sweep complete one
pass first, or run `republish-members` for each community after this
deploys. The command repairs only the community that `RELAY_URL` maps
to, so on a relay hosting many communities, run it once per community
host.

## What got simpler

Deleted:
- `reconcile_nip43_membership_snapshots`,
`spawn_nip43_membership_reconciler`, its leader lock key and #8467's
standby retry
- the three `nip43_membership_snapshot_needs_reconciliation*` drift
reads (one already deprecated)
- `publish_nip43_membership_list` / `publish_nip43_membership_locked`,
the separate after-commit republish at every call site, and
`buzz-admin`'s duplicate publisher
- the reconcile metrics `buzz_nip43_membership_reconciliations_total`
and `buzz_nip43_membership_reconciliation_failures_total`
- the after-commit publish metrics
`buzz_nip43_membership_publications_total` and
`buzz_nip43_membership_publication_seconds`, and the
`publish_nip43_membership_locked` transaction metric label. A failed
list write is now a failed membership write and shows up in the caller's
existing error handling and the transaction metrics of its write path.
- the `BUZZ_NIP43_RECONCILE_INTERVAL_SECS` setting

There is now one way the list gets written, and it can't disagree with
`relay_members` after commit.

**Unused deploy config (outside this repo):** hosted deployments that
set `BUZZ_NIP43_RECONCILE_INTERVAL_SECS` can drop it. It is now ignored.
Dashboards or alerts on the four deleted metrics will stop receiving
data.

## Testing

New Postgres tests (`buzz-db`):
- `relay_members::every_membership_write_commits_its_list`: for each
write path, the returned list is the single live kind:13534 and names
exactly the committed members. No-op calls return no list and leave the
live list alone.
- `relay_members::a_failed_list_write_rolls_back_the_membership_change`:
holds the list lock, waits for the join to block on it, cancels that
statement, and checks that the member was not added and the previous
list is still live.
- `relay_members::concurrent_joins_all_land_in_the_list`: 8 concurrent
joins; the final list names all 8.
-
`relay_members::same_second_return_to_an_earlier_membership_writes_a_new_list`:
add, remove, add, remove within a second; every list is newer than the
last and no id repeats.
- `relay_members::owner_transfer_and_list_repair_both_commit` and
`relay_members::owner_transfer_and_member_removal_both_commit`: hold a
repair (list lock) or removal (member row) open, wait until a transfer
blocks behind it, then finish it. Both transactions commit; with `FOR
UPDATE` back in place, one of them fails.
- `community::create_community_with_owner_is_atomic_and_create_only` and
`relay_invite::bounded_claim_exhausts_and_existing_member_retry_does_not_consume`
now also check the list.

Each new test was checked to fail against a mutation of the new code
that brings back the old behavior (details in the thread).

Stacked on #8467. Merge order: #8467, then #8468, then this.

---------

Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
2026-10-20 11:39:13 -04:00
Luke Tornquist
c99872f749 fix(relay): delete the startup NIP-33 d_tag backfill (#8468)
## Summary

Delete the NIP-33 `d_tag` backfill that ran on every relay boot.

On every boot, before the listener opened, the relay ran:

```sql
SELECT DISTINCT community_id FROM events
WHERE kind BETWEEN 30000 AND 39999 AND d_tag IS NULL
```

No index covers `d_tag IS NULL`. The only `d_tag` index is the partial
`idx_events_parameterized`, which is `WHERE d_tag IS NOT NULL`. So this
query scanned every partition of `events`. In production it averaged
about 11s per boot, max 19s
(`buzz_startup_phase_seconds{phase="d_tag_backfill"}`), and found
nothing.

These rows shouldn't exist anymore:
- The backfill was the one-time migration for #246, the change that
added `d_tag`.
- In `crates/buzz-db/src`, every production write path sets the column
for kinds 30000–39999 through `extract_d_tag`: the main insert,
`replaceable.rs`, `channel_members.rs`, `relay_members.rs`, and
`push.rs`. A new source test,
`every_production_event_insert_names_d_tag`, now enforces that.
- The `events` inserts that omit `d_tag` are all test fixtures.

`scripts/backfill-d-tag.sql` is still there as the manual fallback for
any database that predates #246 and somehow never booted a relay since.

### What got simpler

- Removed `Db::backfill_d_tags` and its admission test.
- Removed the source-shape assertion in `observability_source.rs`.
- Removed the `d_tag_backfill` startup phase.
- `StartupStep::ALL` is now a slice, so removing a step no longer means
editing a hand-kept array length.

### Notes

- The `buzz_startup_phase_seconds{phase="d_tag_backfill"}` series stops
reporting.
- **Rebased onto main after #8467 merged.** Both remove a startup phase.
With the fixed-length `ALL` array the two merged cleanly in git into a
17-entry `[Self; 18]`, which doesn't compile. This PR makes `ALL` a
slice.
- **Before merging**, run this read-only query against production and
confirm it returns `0`: `SELECT count(*) FROM events WHERE kind BETWEEN
30000 AND 39999 AND d_tag IS NULL`. It scans every partition, so use a
read replica. If it isn't `0`, run `scripts/backfill-d-tag.sql` first.
The cutover script copies legacy `d_tag` values as-is, so only this
query proves historical data is clean.
- **Self-hosted installs** should run the same check before upgrading.

### Related issue

None found. Companion to #8467, which also targets relay startup time.

### Testing

- New `every_production_event_insert_names_d_tag`
(`crates/buzz-db/tests/observability_source.rs`): every production
`INSERT INTO events` must name `d_tag` in its column list. Dropping
`d_tag` from `push.rs` makes it fail and name the function.
- Runtime E2E against a real relay: boot has no `d_tag_backfill` phase;
kind:30023 replacement via WebSocket and HTTP keeps only the newer
event, an unrelated `d` survives, and an older replay can't win
(confirmed in SQL).
- Stacked on #8467 at `501dfd83`: a fresh two-replica boot runs all
enabled startup phases, with neither `nip43_reconcile` nor
`d_tag_backfill` present. Both replicas pass readiness and return the
same signed message over authenticated HTTP and WebSocket, and outsiders
are denied.
- Blox, at `501dfd83`: `just fmt-check clippy security-review-check
file-size-check` passes. Every `test-unit` step and `just test` pass
except the `buzz-acp` `git_bootstrap` native-git tests, which fail the
same way at base `b6aa5539` on Blox, and one `buzz-agent` catalog timing
test that fails only under full-suite load and passes when run alone.
- `e27139de` adds only a doc comment on
`every_production_event_insert_names_d_tag`, saying which SQL shapes the
text match covers. No code changed, so the results above still apply.

---------

Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
2026-10-20 11:22:09 -04:00
klopez4212
c9e35f8ac7 fix(mobile): restore Solo chats from channel labels (#8466)
Restore Solo chats and project placement on mobile using `buzz.solo`
labels and creator metadata. Invalidate stale channel details when
identity changes so opening and sending preserve refreshed Solo
identity; shared chats retain ordinary sending. New mobile Solo chats
publish the discovery label, and the personal send guard enforces
ownership even when route hints or legacy placement suggest Solo.

The current desktop producer lives in `block/buzz-app`. [Contract
documentation](0201ca0572/docs/solo-mobile-contract.md)
links its production creation call to relay identity generation and
mobile regression coverage. Public metadata fields are documented.

Validation: clean analysis; 3,542 mobile tests (5 skipped), 4 push
checks, and 280 core unit/doc tests passed. Removing the cache fix
reproduces the send failure. Local push hooks were skipped with owner
approval after an unrelated terminal timeout and disk exhaustion; full
local CI is not green. GitHub CI must validate the pushed commit. The
initial build was installed/launched on iPhone; follow-up native and
live cross-client confirmation remain pending.

The ownership regression supplies a valid owned member recipient and
checks the exact rejection. A New chat UI test captures the real signed
kind-9007 command. Both regressions were mutation-verified: removing the
ownership guard or the production creation label causes the
corresponding test to fail.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-20 11:10:24 -04:00
Logan Johnson
25bcb791b4 fix(relay): show only legacy channel types to reads that name no channel (#8469)
🤖
## Summary
Every Buzz channel has a **type**, such as an ordinary chat channel
(`stream`), a forum, a DM or a workflow. A client app can only show the
types it was built to understand. This PR makes the relay (the Buzz
server) follow one rule everywhere: **a client sees a channel only if it
knows that channel's type.** #8406 applied this rule to membership
notices. This PR applies it to the reads that list channels without
naming one: the channel list, "channels I belong to", the sidebar's
unread list and artifact lists.

Before, these reads left out one type by name: system channels. Now they
return only the four types that every client has always known: `stream`,
`forum`, `dm` and `workflow`. Today the result is the same for every
user, because `system` is the only other type.

### Backward compatibility: old clients stay safe
- A client that was released before a new channel type exists will never
receive channels of that type in its lists. It cannot show such a
channel correctly, so it does not get one.
- Requests that old clients send today return exactly what they returned
before. Nothing changes for them now or when a type is added later.

### Forward compatibility: new types can be added safely
- Before, the rule was a deny list: "everything except `system`". Each
new type would appear in every deployed client by default, unless
someone remembered to update five separate checks in the relay. A missed
check would show the new type to clients that cannot handle it.
- Now the rule is an allow list that is frozen: the four original types.
A new type is hidden by default, with no relay change needed. Clients
that understand it can request it on purpose, the same way current
clients request system channels today. Each new type gets its own
opt-in, so adding a type cannot break clients that are already in use.

## Details
- One frozen list, `buzz_core::channel::LEGACY_CHANNEL_TYPES`.
Membership notices (#8406) now use the same constant, so channel reads
and notices cannot drift apart. The duplicate
`LEGACY_NOTICE_CHANNEL_TYPES` is removed.
- One SQL helper, `legacy_channel_type_sql`, builds `channel_type IN
('stream', 'forum', 'dm', 'workflow')` from that list. It replaces the
five `<> 'system'` checks:
- `get_accessible_channel_ids` (both halves): the implicit channel scope
of any filter without `#h`, for example kind 39000 channel metadata,
REQ, COUNT and search;
  - `get_accessible_channels`: the channel list;
  - the personal-read sidebar roster;
  - artifact queries.
- A filter that names a channel (`#h`, or `#d` on kinds 39000–39003)
reads it under the ordinary rules, whatever its type: the reader is a
member, or the channel is open. The uncached named-channel lookup,
`get_readable_named_only_channels`, now returns every readable
non-legacy channel with its type, not only system channels. Before, a
non-member could not read an open later-type channel, and `#d` read
nothing. Workflow run reads and thread windows use the same lookup.
- The relay keeps each named channel in the scope of the filter that
names it only. This also holds when it re-checks membership for a named
channel that the cache lacks.
- The opt-in to system channels (`#t:["system"]` or `#P` on kinds
39000–39003) adds readable **system** channels only. It never adds a
channel of another type, even one that a sibling filter in the same
request names. The relay scope type `NamedOnlyChannels` keeps the type
with each channel, so the opt-in can tell them apart.
- NIP-CL and NOSTR.md state the rule.

### Related issue
Follows #8406 (the same rule for membership notices).

### Testing
New Postgres tests use a scratch database with a `future_type` value
added to `channel_type`, as a later migration would add one:
- `reads_that_name_no_channel_leave_out_a_type_added_later`: the channel
scope, the channel list and the sidebar roster leave out the later type
and keep the legacy types.
- `artifacts_of_a_later_channel_type_are_read_only_by_name`: artifact
current and history queries and counts without `#h` leave out the later
type. With `#h` naming the channel, they return it.
- `channels_of_a_later_type_are_read_only_by_name`: production read
paths (WS REQ, WS COUNT, HTTP `/query` and `/count`). A member reads a
private later-type channel and anyone reads an open one, by `#h` and by
`#d`; an outsider cannot read the private one; a read that names no
channel returns neither. In one request, a filter that names the channel
plus a `#P` or `#t:["system", <label>]` sibling: the sibling does not
get it.
- `a_named_channel_of_a_later_type_stays_in_its_named_filter`: the
membership re-check for a channel joined mid-request, with an unnamed
sibling and a `#P` sibling. Only the naming filter gets the channel.

Each test fails when its predicate goes back to `<> 'system'`, when the
named lookup loads only `system`, or when the opt-in adds every
named-only channel. The #8406 notice tests and the system channel
Postgres tests pass on this branch.

---------

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
2026-10-20 11:04:29 -04:00
Luke Tornquist
e6c56ee5ee fix(relay): take NIP-43 snapshot reconcile off the startup path (#8467)
## Summary

Before the relay opened its listener, it reconciled the NIP-43
membership snapshot for every active community. Each community costs two
writer round trips, one after the other. On a production deployment with
about 80k communities, this one step averaged 174s of a roughly 180s
boot (max 324s). Pods in an availability zone farther from the writer
took 3–4× longer than pods in the writer's zone.

The step doesn't need to block startup. The snapshots live in the shared
database, and the replicas that are already running serve the same
snapshots. A new replica has nothing of its own to repair before it
serves. The sweep before bind did the same work as the background
maintenance sweep; only the metric labels differed.

This PR:

- Removes the NIP-43 sweep that ran before bind.
- Moves the background loop into
`side_effects::spawn_nip43_membership_reconciler`. Its first sweep now
runs as soon as the task starts. Before, the loop skipped its first
tick, so the first maintenance sweep waited a full
`BUZZ_NIP43_RECONCILE_INTERVAL_SECS`.
- Runs that loop on one replica only. The replica holding the
`NIP43_RECONCILE_LOCK_KEY` session advisory lock sweeps; the others
retry the lock every `NIP43_STANDBY_RETRY` (5s, capped at the interval).
This reuses the usage-metrics leader lease (a detached Postgres
session), renamed from `UsageMetricsLeader`/`try_lock_usage_metrics` to
the generic `SessionLeader`/`try_lock_session_leader`.
- Waits a full interval after each sweep (sleep after sweep), so a sweep
longer than the interval never runs straight into the next one.
- `reconcile_nip43_membership_snapshots` is now the only entry point and
keeps its original signature (`-> Result<usize>`). It's no longer
deprecated.

### What got simpler

Deleted:

- `Nip43ReconciliationPurpose` (the `Bootstrap`/`Maintenance` purposes)
and `reconcile_nip43_membership_snapshots_with_purpose`
- `Db::bootstrap_community_hosts` and
`Db::nip43_membership_snapshot_needs_reconciliation_for_bootstrap`
- The startup progress log (`NIP-43 startup reconciliation progress`,
`nip43_progress_due`) and its test
- The `nip43_reconcile` startup phase: `StartupStep::ALL` goes from 19
to 18 steps

The leader lock reuses the existing usage-metrics lease rather than
adding a second leader primitive. `StorageAccountingLeader` is still a
near-duplicate of it; folding that in is left as identified debt.

### Trade-offs

- **Repair before serving.** A newly started replica no longer
guarantees it has repaired stale snapshots before serving. The running
fleet doesn't guarantee that today either: the background sweep is what
repairs drift, and the leader starts it as soon as it takes the lock.
- **Rollout load.** Before, every replica swept before binding, and
every replica also ran the background loop. Now there is one sweeper in
steady state, so writer load from this job drops from one sweep per
replica to one per deployment, and rollouts no longer stack boot sweeps.
Standbys add one lock attempt every 5s each.
- **Leader handoff.** When the leader's process exits (including
SIGKILL), its connection closes, Postgres releases the session lock, and
a standby retries the lock at least every `NIP43_STANDBY_RETRY` (5s) and
sweeps as soon as it gets it. Each attempt also waits for a writer
connection, so under database pressure takeover can take longer than 5s.
Before this, a standby waited a full interval (3600s in production), so
after a rollout replaced the leader nothing swept for up to an hour. If
the leader is lost with its host or network instead, the lock is held
until the database server's TCP keepalive drops the session, and nobody
sweeps meanwhile. The usage-metrics leader already has the same
exposure. The lease is checked only between sweeps, so a leader that
loses its session mid-sweep finishes that sweep while the new leader
starts one; the per-community publication lock keeps that overlap safe.
- **Snapshot window.** A missing or stale kind:13534 snapshot is served
until the leader's sweep reaches that community; before, a booting
replica blocked until it was repaired. Admission reads canonical
`relay_members`, so this window doesn't change who's admitted. It does
affect clients that read the snapshot: desktop onboarding shows the
membership-denied page to a member missing from it, the desktop/mobile
member lists and join alerts lag, and desktop mesh discovery keeps its
existing allowlist when the snapshot is missing. In production the
inline publications that keep it current have not failed since
2026-10-07, and the sweep repaired no snapshots in the last 30 days.
- **Dashboards and alerts.** The
`buzz_startup_phase_seconds{phase="nip43_reconcile"}` series stops
reporting. Anything charting or alerting on it should move to the
sweep's existing counters
(`buzz_nip43_membership_reconciliations_total`,
`buzz_nip43_membership_reconciliation_failures_total`).

### Related issue

None found.

### Merge order

#8468 is stacked on this PR. Both remove a startup phase, and with the
old fixed-length `StartupStep::ALL` array, merging both would have built
a 17-entry `[Self; 18]` that doesn't compile. Merge this PR first; #8468
makes `ALL` a slice.

### Testing

- `background_reconciler_sweeps_immediately` (private scratch database):
spawns the production reconciler with a 24h interval and 24h standby
retry, and requires the first sweep to publish a missing snapshot. Fails
if the skipped first tick is restored.
- `background_reconciler_standby_takes_over_on_short_retry` (private
scratch database): with a 24h interval and 100ms standby retry, nothing
publishes while another session holds the leader lock; once it's
released the standby must publish within 10s. Fails if the standby
sleeps the full interval again (checked by reverting that line).
- `test_usage_metrics_lock_has_single_owner_and_releases_on_drop` covers
the renamed lease.
- `maintenance_sweep_skips_archived_and_deleted_communities` now calls
the single entry point.
- Runtime E2E at `574b28b3`: two real relays sharing one database, 3600s
sweep interval, production 5s standby retry. While the leader was alive,
the standby made only lock attempts (no sweep or snapshot-comparison
reads). SIGKILL of the actual lock holder, 3/3 trials: the survivor took
the lock in 4.81–4.86s and repaired the snapshot within 10ms after that.
Both replicas served authenticated reads while the initial publication
was stalled.
- Blox, at `574b28b3`: `just fmt-check clippy security-review-check
file-size-check` passes. Every `test-unit` step and `just test` (118
suites) passes except the `buzz-acp` `git_bootstrap` native-git tests,
which fail the same way at base `b6aa5539` on Blox (environment, not
this change).

---------

Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
2026-10-20 10:19:46 -04:00
Wes
6e6173acd5 test(buzz-db): fix two PostgreSQL-lane timing flakes (#8472)
## Summary

Two timing flakes in the PostgreSQL lane, one fix each.

### Deletion lock order

`abort_serializes_before_fence_without_deadlock` failed on main ([run
39330176879](https://github.com/block/buzz/actions/runs/39330176879)):
`post-lock lease verification rejects aborted request: 1`.

The test slept 50ms and assumed `abort` had queued on the community
advisory lock by then. On a slow runner, `fence` queued first, won the
lock, and succeeded.

The test now waits until `pg_locks` shows each contender waiting on that
community's lock, `abort` first and then `fence`. Postgres grants queued
advisory locks in arrival order, so `abort` always wins. The sleeps and
their timing guess are gone.

### Saturated-reader fixture

`routed_fallback_spends_one_acquire_budget_when_aurora_cache_is_cold`
failed this PR's first run ([run
39335038111](https://github.com/block/buzz/actions/runs/39335038111)):
`establish the reader's sole connection: PoolTimedOut`. Setup opens the
reader's only connection through the production lazy pool, which has a
150ms acquire timeout. On a loaded runner that first connect took
longer, so the test failed before reaching the budget it measures. Setup
now retries on `PoolTimedOut` within 5s. The pool and its 150ms budget
are unchanged for the routed read under test.

Test-only. Production code is unchanged.

## Validation

- Deletion test against an isolated local Postgres 17 database: 40/40
passes. Saturated-reader test: 15/15.
- `cargo fmt --check`, `cargo clippy -p buzz-db --tests -D warnings`,
pre-push Rust unit tests: pass.
- Three other `store::deletion::postgres_tests` fail locally on
unmodified `main` as well (local environment). CI's PostgreSQL lane is
the authoritative check for them.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 23:40:43 +00:00
Wes
edbfbf08db test(mobile): journey-first testing guidance and suite cleanup (#8397)
## Summary

This PR does two things. It updates the mobile testing conventions to
favor a few journey tests over many small logic tests. It also applies
those conventions to the existing mobile suite, one commit per step.

### Testing conventions (`AGENTS.md`, `mobile/README.md`)

- Start with one widget journey per user-visible flow, driven through
the real widgets, notifiers and coordinators. Assert what the user sees
and what is durably saved.
- Cover retry, cancel and resume as steps inside the journey, not as
separate tests.
- Fake only external boundaries (network, relay, OS, browser, storage).
- Use focused, table-driven tests only for security and data-loss
invariants, protocol or crypto vectors, and pure functions with many
input combinations.
- When review finds a defect, extend an existing journey or table
instead of adding a test per finding.
- Delete a lower-level test only once a journey demonstrably catches the
same failures.
- Every test must fail when the production code it guards is broken.

These conventions keep the Review-Proven Rules' safety bar and change
only how coverage is organized.

### Suite inventory and plan

The suite has 234 Dart test files, about 110k lines and about 2,600
declared tests. Native tests are separate: BuzzPushKit, RunnerTests,
NativeControlTests and Android. Line-saving estimates are hypotheses,
not a deletion budget. Each deletion needs a replacement that rejects a
representative production mutation.

1. **CI and reliability.** Run the native tests CI skipped, make
time-dependent tests deterministic, and make tests that could not fail
falsifiable. *(done, see below)*
2. **Shared harness.** Add one fake relay (socket plus HTTP boundary,
with the real `RelaySessionNotifier`) in `test/helpers/`. Today 38 files
each write their own `RelaySessionNotifier` fake. *(done, see below)*
3. **Per-area journeys.** Convert page tests that fake the flow's own
notifiers (for example, `channel_detail_page_test` overrides about 60
providers). Fold near-duplicates into tables. Remove constant-pinning,
pixel-geometry and call-count tests once a journey covers the outcome.
Split `channel_detail_page_test.dart` (17.7k lines). Each area commit
reports before/after counts and the mutation it rejects.
4. **CI speed.** Shard by file instead of by test, since every shard
currently compiles the whole suite. *(done, see below)*

Keep as-is: relay protocol and NIP handling, crypto vectors, auth, push
security, persistence and journal invariants, recipient routing, and
real-socket transport and cancellation tests.

### Step 1 changes

- **Android CI** runs the 23 JVM unit tests, which were never run
before. It retries the APK build once, only on SDK or plugin download
failures (the cause of 4 recent `main` failures).
- **iOS CI** runs all RunnerTests (previously 2 of 99) and the
previously uncalled Me-agent accessibility script. The Swift Native lane
builds the simulator app once, in the background while the simulator
boots and runs the native-control scripts, instead of twice. The lane
stays non-required.
- **Stale RunnerTests.** Two reaction-details tests still expected the
filter list that #8280 replaced; they now cover the toggle list. #8393
moved navigation bar controls onto a shared glass surface and made
unknown Tabler symbols assert. The avatar and members-activity tests now
find controls on that surface, three tests use real symbol names, and a
240 pt title width pinned to the old control sizes is removed (its gap
assertions remain).
- **Known bug, not fixed here.** Since #8393 the DM title avatar image
is nil, because `makeItem` returns avatar data as a custom-view item. No
screen passes a title avatar yet. The test marks it `XCTExpectFailure`.
- **Typing retry** and **sections backoff** tests use fake time instead
of about 37 s of real sleeps and a `Stopwatch < 100ms` threshold.
- **Manage-channel sheet tests** previously asserted inside callbacks
that the sheet's `catch (_)` swallows. A wrong saved description made
the test loop until killed. The tests now record arguments, assert
outside the caught code, and cancel instead of re-presenting endlessly.
- **`video_viewer_transport_test` removed.** It exercised only
`package:http`. Removing the production `request.sink.close()` already
fails `video_viewer_test`.

### Step 2 changes

- **`test/helpers/fake_relay.dart`** fakes only the websocket (through
the session's socket factory) and the HTTP bridge (through its client).
The real `RelaySessionNotifier` still connects from `build()`, handles
OK and CLOSED, batches events, backs off and replays subscriptions.
- The fake serves the NIP-CW channel window. It can hold OK and live
echo independently, reject a chosen publish, and drop the connection.
Any request it cannot answer faithfully fails the test at teardown,
because the app often catches relay errors and falls back.
- **`channel_messages_journey_test`**: history through the channel
window, a live message, a send that is pending until OK and stays one
row after the echo, a rejected send rolled back, then drop and reconnect
with missed and later messages.
- **`channel_send_journey_test`**: type and send on `ChannelDetailPage`
with no feature-notifier overrides. The row and sending spinner show at
once, OK settles them, and a rejected send puts the text back in the
composer and shows a snackbar.
- Existing per-file relay fakes and `SidebarRelay` are unchanged. Step 3
migrates them area by area.

### Step 4 changes

- `scripts/mobile-test-shard.sh` splits the 235 test files across the 3
shards, balanced by line count. `flutter test --total-shards` split
tests, so each shard compiled and loaded every file. Locally at 4
workers, one shard took 63 s instead of 73 s and used 40% less CPU.
`channel_detail_page_test.dart` (17.7k lines) is now the long pole;
splitting it in step 3 shortens the slowest shard.

Out of scope here: requiring branches to be up to date before merge (a
repository setting), and the onboarding tests in #8375.

## Validation

- Mutation checks:
  - Typing retry bound: test fails.
  - Sections backoff reset: test fails.
- Wrong saved description: fails in about 11 s. The old tests hung
instead.
  - Removed sink close: `video_viewer_test` fails.
- Changed Dart files pass locally, and `flutter analyze` is clean.
- Android `testDebugUnitTest` passes locally (23 tests). The Me-agent
accessibility script passes on a local simulator.
- Step 2 mutation checks, each made a journey fail: accepted OK ignored,
rejected row not rolled back, optimistic row not added, draft not
restored, local message left pending after OK, channel window replaced
by the fallback, live subscriptions not replayed after reconnect.
- Both journeys run in about 1 s on fake time.
- All 99 RunnerTests pass on an iPhone 16 iOS 26.5 simulator, the CI
destination, after rebasing on #8398.
- The shard script partitions all 235 test files exactly once.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 17:19:07 -06:00
Wes
3ec6327618 fix(mobile): keep cached state with its community (#8349)
## Summary

One identity can be paired with several communities, but mobile keyed
several caches by pubkey only. Mobile keeps a single `ProviderScope` and
doesn't remount on a community switch, so one community's data showed up
in another, and some of it was published to the other community's relay.

- **Channel groups**: the second community showed the first community's
groups.
- **Read marks** (contexts, publishable set, NIP-RS client and slot
IDs): the first community's context IDs were merged into, and published
to, the second community's read-state slot.
- **Inbox done/unread rows and thread follows**: one shared 500-entry
cap, so activity in one community evicted another's entries.
- **Channel stars and mutes**: union-merged across communities and
published to every relay.

Every one of these is now keyed by pubkey + normalized community relay,
the same way channel sort already is.

**Switching communities.** The relay session rebuilds for the new
community before the previous community's managers are retired. Each
manager (groups, read state, stars, mutes) now checks that the session
still serves its own community before it publishes, merges a fetch, or
handles a live event. Previously, a pending publish flushed on dispose,
or an in-flight fetch, could cross into the next community.

**Old pubkey-only entries.** Channel IDs can repeat across communities,
so nothing tells us which community an old channel-keyed entry belongs
to:
- **Groups, stars, mutes and read marks** are dropped on upgrade, and
each community restores its own from its relay. Any change that never
reached a relay is lost, and a read mark the relay doesn't hold shows as
unread once. That's an accepted tradeoff: such changes would be very old
by now.
- **Inbox, thread follows, and read-state slot and client IDs** seed
every community, and the old entry is kept. The inbox and follows
entries are event IDs, which only ever match their own community. The
slot ID keeps each community publishing to the slot it already has on
its relay.

This PR also removes the **Pulse** feed (`features/pulse/` and the Nostr
filters only it used). Nothing in the app navigates to it anymore, and
its providers were among the community-unscoped caches.

### Related issue

None found.

### Testing

- Each affected store has a regression test through the real provider
that switches A → B → A. For groups, read marks, stars and mutes, the
test sets a value in A, switches to B while A's change is still pending,
and checks two cases: B's data arriving live and B answering A's
in-flight fetch. It asserts that nothing sent to B contains A's IDs, B
shows only its own value, and A comes back unchanged. Each guard was
removed in turn to confirm a test fails without it, except two that the
current switch order never reaches: the groups merge guard and the
read-state live-event guard.
- Upgrade tests cover each kind of old entry: dropped for groups, stars,
mutes and read marks, seeded for inbox, follows and slot IDs.
- `flutter analyze` is clean, and the full mobile suite passes in the
pre-push hook at `89ebfcc12`.
- Not yet exercised in the app.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:59:38 -06:00
Nur Fatima
139f8903d5 fix(desktop): set window title to "Buzz" for Windows taskbar (#6317)
## What
    
The Tauri window title field in tauri.conf.json was an empty string. On
Windows, the taskbar draws its label from the window caption, so the
Buzz entry rendered as an icon with no name.
    
## How
    
Set app.windows[0].title to "Buzz" in desktop/src-tauri/tauri.conf.json
(line 19).
    
This is the only change — one line in one file. The hiddenTitle: true
field on line 26 only affects the macOS title bar and does not interfere
with the Windows taskbar label.

## Before / After
    
    |                 | Before             | After         |
    |-----------------|--------------------|---------------|
    | Windows taskbar | Icon only, no text | Icon + "Buzz" |
    
## Testing
    
    - Verified the JSON is valid after the change
    - hiddenTitle: true is unchanged — macOS behavior is unaffected
    
Fixes [#6295](https://github.com/block/buzz/issues/6295)

Signed-off-by: Fatima Nur <fatimanur424@example.com>
Co-authored-by: Fatima Nur <fatimanur424@example.com>
2026-10-19 15:36:57 -07:00
Wes
dcced2c4f7 fix(mobile): preserve saved identity lookup after enumeration fails (#8470)
An account-scoped saved identity could fail to open when secure-storage
enumeration succeeded while showing choices, then failed before
selection. Retain the discovered storage location and reread/validate
that exact record before falling back to inventory lookup. Only public
location hints are retained; signing material is read fresh.

Follow-up accepted at merge of #8375:
https://github.com/block/buzz/pull/8375#pullrequestreview-5577985447.

Validation: existing self-hosted widget journey now injects enumeration
failure after choices load and verifies the same key is admitted and
persisted. Three focused files passed: 37 tests with hosted domains
configured; 28 passed and 9 hosted-only skips with default
configuration. Changed-file analysis passed. In an isolated clone,
removing the location lookup failed that journey; control and restored
runs passed. Self-review found no blocking defect.

Draft acceptance gate: native/device behavior and human acceptance are
not established by widget fixtures. On a disposable saved identity,
enter a self-hosted community link, choose the identity, and confirm
admission preserves it; cancel/retry as well. Hosted live-backend
acceptance remains separate and pending backend availability. No full
local suite was manually run; mandatory hooks/CI provide broader
coverage.

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@feedback.communities.buzz.xyz>
2026-10-19 16:33:42 -06:00
Wes
91b1cc4761 perf(mobile): reuse the derived pubkey when signing auth events (#8460)
## Summary

Each relay `/query` signs a NIP-98 event, and each relay media image GET
signs a Blossom auth event. Both run on the UI isolate. `nostr`'s
`Event.from` derives the pubkey from the secret key on every call, which
is about a third of the cost of a signature.

Both call sites now pass the pubkey that `myPubkeyProvider` already
caches for the active key. The provider is derived from the same
`relayConfigProvider` state as the key, so the two always match.

This is the quick win. Moving signing to native secp256k1 or a worker
isolate would remove the rest of the cost, and that would be a separate
change.

## Before and after

AOT-compiled benchmark on Apple silicon, `nostr` 2.0.0 `Event.from`,
three runs of 50 signatures each:

| | ms per signature |
|---|---|
| `main` (pubkey derived) | 8.8 to 9.6 |
| this PR (pubkey passed) | 5.9 to 6.4 |

A scroll that shows 20 uncached relay-media images now spends about 60
ms less on the UI thread.

## Test

There are no new tests. The existing `queryRelay` test runs through the
real `relayConfigProvider` and `myPubkeyProvider`, and asserts the
signed event's pubkey for one identity. It does not verify the signature
or switch identities, and it would still pass with this optimization
removed. The media tests build the service directly, so they only cover
the fallback where the pubkey is derived.

Review traced the pairing instead. Both the key and the pubkey come from
`relayConfigProvider`. `_postForEvents` reads both and signs with no
await in between, and the media provider watches both. So the key and
pubkey change together on community switch and sign-out.

## Validation

- `flutter analyze`
- Full mobile suite: 3,534 passed.

**Human test:** Wes ran #8456, #8460 and #8462 together on the simulator
with his real account and confirmed they work.

buzz-review-completed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:10:14 -06:00
Wes
52aa37a929 perf(mobile): stop an open chat rebuilding on other channels' events (#8456)
## Summary

While a chat is open, a message in any other channel rebuilt every built
row of that chat. There were two causes:

- **The chat watched the whole channel list.** `channelsProvider`
republishes the list on every live event in any channel. The chat page,
its message list and the thread page watched all of it. They now watch
only their own channel's entry. The `#channel` name map comes from a new
`channelIdsByNameProvider`, which notifies only when a channel name or
id changes.
- **The root `App` rebuilt often, and each rebuild rebuilt every pushed
route.** It watched the agent observer and the user-status cache only to
keep them alive, and it watched the whole Me unread set. It now listens
to the first two and selects only whether Me has unread.

Rows still remount when a message arrives in the open channel. That
comes from `scrollable_positioned_list` keying rows by index, and it
gets its own PR.

## Before and after

Setup:
- iPhone 18 Pro simulator, debug build.
- Local relay with about 120 ms of added round-trip time.
- Seeded community: 120 channels, about 5.5k messages, a busy chat of
about 1.4k messages.
- The same scripted run on `main` at `5730c83f7` and on this branch,
counted with local probes that are not part of this PR.
- Counts are exact. Debug milliseconds are only useful for comparing the
two runs.

10 messages arrive in another channel while the busy chat is open:

| | `main` | this PR |
|---|---|---|
| Chat page rebuilds | 42 | 0 |
| Message row rebuilds | 1,218 | 0 |
| Frames with build time over 16.7 ms | 42 of 129 | 0 of 10 |
| Worst frame build time (debug) | 78 ms | 13 ms |

5 messages arrive in the open chat: 1,300 row rebuilds on `main`, 693 on
this PR. Most of the rest are the remounts from the index-keyed list.

## Test

A widget test publishes a new channel list where only another channel
changed, and fails if any `MessageContent` rebuilds. Reverting the
production change makes it fail.

## Validation

- `just mobile-check`
- Full mobile suite: 3,532 passed.
- The simulator run above.

**Human test:** Wes ran #8456, #8460 and #8462 together on the simulator
with his real account and confirmed they work.

buzz-review-completed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:09:52 -06:00
Wes
db50afd8a7 perf(mobile): load the channel list's membership-scoped reads together (#8462)
## Summary

At startup and on every community switch, the channel list waits on a
chain of relay reads, one round trip after another. Four of those reads
need only the membership ids: channel metadata, hidden DMs, member
snapshots and Huddle starts. Yet each one waited for the read before it.

They now go out together, right after the membership list. Everything
that depends on them is unchanged: DM participant names still follow
metadata, and the latest-message batch still follows the filtered list.

- `Future.wait(eagerError: true)` handles every request's failure and
rethrows the first one unchanged, as soon as it happens. Before this
change a failed read also stopped the chain. Hidden DMs and Huddle
starts still fall back to empty on failure, as before.
- The refresh fence checks the combined result once, before any state is
written. That's the same fence check each read had before.

This keeps the duplicate member-snapshot read. Replacing it with the
membership list's events would need a relay-contract check first.

## Before and after

Setup:
- Simulator, debug build.
- Local relay with about 120 ms of added round-trip time.
- Seeded community with 120 channels.
- 5 cold launches each, after one warm-up launch, on the same build with
and without this change.
- Timed with local probes that are not part of this PR. All 10 launches
loaded 120 channels.

| | `main` | this PR |
|---|---|---|
| Connected → channel list ready (median) | 1,233 ms | 715 ms |
| Range | 1,154–1,297 ms | 689–747 ms |

## Test

A test parks the metadata, hidden-DM and member-snapshot reads at the
same time, then checks that all four reads were sent. If any read waits
on another, it stays unsent and the test fails. It fails on `main`,
where only metadata goes out, and on a version that sends metadata first
and the rest after. Three switch tests park before discovery now, so
their names say "during a directory refresh" instead of "after directory
success".

## Validation

- `flutter analyze`
- Full mobile suite: 3,535 passed.
- The simulator runs above.

**Human test:** Wes ran #8456, #8460 and #8462 together on the simulator
with his real account and confirmed they work.

buzz-review-completed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:09:29 -06:00
Wes
bc9e7de904 fix(mobile): stop Settings rows blinking while Settings opens (#8463)
## Summary

On iOS, opening Settings made the Status, Profile and Notifications
cards disappear for most of the slide-up. They came back when the
transition finished. Closing Settings did the same thing.

**Cause:** Flutter's iOS compositor (`flow/view_slicer.cc`) puts Flutter
content that's painted after a platform view and overlaps no native view
into the background canvas. During the transition, Home's native nav bar
and glass tab bar are still on screen under the full-screen Settings
page, so the overlay created for Home's tab bar already covers the whole
background. Everything painted after the native presence pill, outside a
native view's rect, was hidden behind it. "Send identity to desktop"
stayed visible only because it overlaps Home's tab bar.

**Fix:** `IosPresenceMenu` mounts its native view only after its route
settles (animation completed, nothing covering it). During route
transitions, and while the native view is being created, it draws a
matching Flutter stand-in: same capsule, colors, SF Pro Text at the same
size and weight.

### Related issue

N/A, none found. Reported by Wes from a screen recording.

### Testing

- Reproduced in an uncommitted harness on an iOS 27 simulator: Home with
native nav bar and glass tabs, then `BottomUpPageRoute`, then a
Settings-shaped page using the real `IosPresenceMenu`. The cards blank
out on every open and close.
- A/B in the same harness: the blink goes away if any one of the three
is removed (native pill, Home nav bar, Home glass tabs).
- With this change, the open and close cycles in the harness show no
blank frames. At rest the native pill is mounted again. Its pixels are
identical to before, and the stand-in matches it within about 1px of
text rasterization.
- `settings_overlay_test.dart` now checks that the native pill isn't
mounted mid-transition, and that exactly one native view is created
after settling. The new assertion fails without the fix.
- Pre-push mobile checks passed: analyze, format, full mobile test
suite.

**Human test:** on iOS, open and close Settings from Home a few times.
Every card should stay visible throughout, and the "Online" pill should
open the native availability menu once Settings has settled.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:09:17 -06:00
Wes
b6aa5539e3 feat(mobile): account onboarding, key recovery and hosted reconnect (#8375)
## Behavior

Adds optional mobile Builderlab sign-in, identity backup/recovery,
community discovery/creation, and account-aware reconnect. **Builderlab
features are disabled by default:** when `BUZZ_AUTH_DOMAINS` is unset or
empty, account login, creation, backup/recovery, reconnect prompts, and
background account restoration are hidden/disabled. QR/code pairing,
links, and invites retain Nostr-only entry. Saved account state is
retained for later opt-in.


`--dart-define=BUZZ_AUTH_DOMAINS=communities.buzz.xyz,communities.public.builderlabstaging.xyz`
opts those DNS domains and their subdomains into required account setup.
The same policy gates pairing, deep links, durable community admission,
and reconnect. A nonempty list enables Builderlab features;
`BUZZ_BUILDERLAB_URL` alone does not. Enabled flows still require their
backend services. Existing Nostr relay authentication remains mandatory.

`BUZZ_HOSTED_RELAY_AUTH=true` enables scoped relay assertions and
reconnect prompts only for configured authentication domains. Configure
assertion issuance and each community's issuer binding before enabling
assertions; enable relay enforcement last. Account credentials stay at
Builderlab. Wrong-account recovery preserves keys; failed writes are not
replayed; authentication is bounded by request deadlines.

Hosted flows preserve keys across cancellation/restart, reconcile
interrupted creation/invitation acceptance, and support manual nsec file
import/export. Account identities are scoped to backend and
authenticated subject; reusing an existing local key for an unbound
account requires an explicit selection. Recovery reconciles the
advertised and recovered inventories before automatic selection.
Successful self-hosted admission retires its pending key, and iOS
startup removes interrupted export files. Adds authenticated relay `GET
/operator/communities/joined` for the companion Builderlab membership
endpoint.

## Validation

- Follow-up review repair at `66a12ac92`: self-hosted entry presents
readable choices and import despite incomplete enumeration, while
generation still requires a complete empty inventory; explicit selection
uses exact-key lookup. Consuming a value-equal duplicate now advances
dispatch. Reconnect requires an existing account binding or a
subject-scoped backup receipt before signing an assertion, and pins the
subject inside the serialized account request. An empty different
account is refused without sending key proof. Focused checks: configured
domains 58 passed; default 49 passed, 9 hosted-only skips. Separate
isolated mutations fail the incomplete-inventory sheet, exact-key reuse,
duplicate dispatch and reconnect journeys (including an
empty-account-only bypass); restored controls pass. Evidence uses
synthetic storage/network boundaries, not physical Android or live
backend association. All mandatory commit/push hooks passed; fresh
GitHub CI is pending.

- Bounded review repair at `d3cc0003f`: incomplete secure-storage
enumeration now blocks automatic identity generation while explicit
known-key reads retain their fallback; declined/failed onboarding links
release the queue; HTTP 429/5xx keeps Retry regardless of response
encoding. Default app-gate coverage exercises a bind link followed by
ordinary community entry. Focused checks: configured domains 47 passed;
default 38 passed, 9 hosted-only skips. Removing the three production
fixes in an isolated source/Git/build copy fails the
identity-resolution, declined/failed queue, and Retry journey
assertions; clean and restored controls pass. Storage and HTTP failures
are synthetic; physical Android and live outage behavior were not
exercised. Published after all mandatory commit/push hooks passed
(mobile analysis/tests, branch-skew and file-size gates); fresh GitHub
CI remains pending.

- Existing whole-PR source review cleared the reconnect defects at
`fb15d5b82`.
- Domain-policy increment: focused environment, entry, app-gate, pairing
and onboarding journeys pass with empty and configured domains. Existing
pairing provider/page tests pass. Changed Dart files analyze cleanly.
- Isolated source/Git/build mutation: forcing paired credentials through
hosted login fails the default-build journey; clean and restored
controls pass. CI now runs configured-domain journeys in addition to the
default-build suite.
- Integrated main through `5b433d929` at `0067c069c`, including its
pinned Flutter upgrade. Preserved the PR welcome UI with the updated
transition API and added Material surfaces around onboarding
selection/consent rows. Focused post-merge runs pass in both
configurations; all mandatory local push gates passed (mobile
analysis/tests, Rust tests, desktop-native checks, branch-skew and
file-size checks).

- Merge-review repair at `a315bce11`: focused identity/storage/admission
and widget journeys pass, including account switching with an empty or
already-bound second account, explicit reuse, and self-hosted
removal/rejoin with another key. Default-domain journeys pass too
(hosted-only cases intentionally skip there).
- Isolated source/Git/build mutation checks: bypassing account scoping,
reuse consent, pending-key retirement, or recovery inventory
reconciliation fails the relevant journey/invariant assertions; clean
and restored controls pass.
- Native `RunnerTests/IdentityFilePluginTests`: both tests pass on the
iPhone 18 Pro iOS 27 simulator with an isolated app identifier. At
`24a0dcaac`, the picker journey seeds residue in Library/Caches,
matching path_provider_foundation, and verifies plugin startup removes
it while preserving an unrelated file. The earlier tmp-only fixture did
not exercise the actual export location. This is synthetic native
cleanup/picker evidence, not a real terminated-share or live account
round trip.

- Follow-up: Caches and tmp cleanup; fallback to individually known
identity slots when Android bulk enumeration fails; explicit replacement
of a refused self-hosted key preserves its original before swapping the
retry slot. Configured-domain journeys/invariants: 34 passed; default:
31 passed, 3 hosted-only skips. Isolated enumeration/retry mutations
fail with passing controls. Bulk-read fallback preserves but cannot
enumerate arbitrary other-account slots until bulk reads recover.

- Configured-domain CI exposed a stale pairing-status assertion after
account scoping. The repaired test checks the admission mismatch,
preserved account/transfer keys, and no admitted community. The
configured-domain CI selection passes locally (56 tests); removing the
production mismatch guard fails the updated test, with clean/restored
controls passing. This is synthetic coordinator evidence, not physical
QR acceptance.

- Final review repair (`40e1e6101`): native iOS export creation uses
atomic complete file protection; normal and restart cleanup remain.
Account/policy/claim HTTP uses one 30-second total deadline with request
abort and body cancellation. Removed the unrelated NIP-FA spec edit.
- Focused account/admission/export tests: 25 pass; configured-domain
account/admission/onboarding journeys: 33 pass. Isolated deadline and
native-dispatch mutations fail, with passing clean/restored controls.
Native export/picker tests: 2 pass on iOS 27 simulator. The real
file-protection attribute assertion is physical-device-only because
simulator provides no Data Protection attribute; locked-device
protection and interrupted real sharing have not been observed.

- Opt-in UI: configured-domain CI selection passes (57 tests); default
selection passes (7 tests, 10 hosted-only skips); URL-only plus
whitespace/empty domains passes (6 tests, 9 hosted-only skips). Changed
Dart files analyze cleanly. Independent mutations that unconditionally
initialize the coordinator in the app gate, welcome entry, or link form
fail the default journey; clean/restored controls pass.
- Native welcome screens exercised on iPhone 18 Pro / iOS 27 simulator
in default and configured builds: default exposes community link / QR /
pairing code only; configured build additionally exposes Builderlab
connection and community creation. No live hosted login was exercised in
this check.

- Delivery at `e48fe73a9`: all mandatory push hooks passed (full mobile
analysis/tests, Rust tests, desktop-native checks, branch and file-size
checks). GitHub checks had not yet populated at the immediate post-push
snapshot.

## Review disposition

| Feedback | Disposition |
| --- | --- |
| Explicit self-hosted entry under unreadable inventory, duplicate
invite dispatch, reconnect cross-account binding
([entry](https://github.com/block/buzz/pull/8375#discussion_r4318421622),
[queue](https://github.com/block/buzz/pull/8375#discussion_r4318421640),
[reconnect](https://github.com/block/buzz/pull/8375#discussion_r4318455512))
| Repaired at `66a12ac92`; evidence above. Reconnect refuses unproven
ownership rather than silently establishing a binding. |
| Incomplete Android identity inventory, stranded deep-link queue,
transient HTTP retry classification
([review](https://github.com/block/buzz/pull/8375#pullrequestreview-5576864143))
| All three repaired in `d3cc0003f`; focused journeys and isolated
mutation evidence above. |
| Account cross-link, incomplete recovery inventory, committed invite
checkpoint, pending local key retirement/replacement | Repaired in the
preceding commits; journey and mutation evidence above. |
| iOS interrupted key export
([review](https://github.com/block/buzz/pull/8375#pullrequestreview-5575253252))
| Native cleanup plus complete protection at creation implemented.
Physical-device lock and real interrupted sharing acceptance remains
pending. |
| Trickle responses bypass idle timeout; unrelated NIP-FA edit
([review](https://github.com/block/buzz/pull/8375#pullrequestreview-5575764556))
| Total request deadline/abort implemented; spec edit removed. |
| Production domains rejected | Ordinary entry now needs no Builderlab
configuration. Opt-in account-required domains must still use supported
community mappings. |
| Lost Android Keystore recovery | Backup exclusions prevent the
reviewed stale-restore scenario; genuine key loss still has no in-app
recovery/reset and remains deferred. |
| Native secp256k1 dependency question | Obsolete against the current
base: upstream C integration landed in #8398; no package diff remains
here. |
| Operator membership endpoint contract | Documentation now states the
operator chooses the pubkey; no end-user session binding is implied.
Additional handler-level coverage is optional follow-up. |
| Optional Android partial document cleanup/activity retention; local
work after backup cancellation | Follow-up hardening, not claimed
implemented. Cancellation prevents remote backup upload. |
| Semgrep crypto inventory notices | Informational inventory, not
demonstrated defects. |

## Remaining draft gates

Native QR/browser-return acceptance remains unverified for this
revision. Optional Builderlab onboarding still needs backend
backup-status and joined-community routes, recovery
policy/configuration, and real backup/recovery/reconnect acceptance. The
empty-domain build removes these services as prerequisites for ordinary
pairing; it does not make the optional hosted flows backend-ready. Human
acceptance and current CI are still required before merge.



Review dispositions retained: production auth-domain configuration must
use supported community mappings; enabling `builderlab.xyz` does not add
support for `buzz.block.builderlab.xyz`. Recovery after genuinely losing
an Android Keystore key remains a follow-up, not a newly implemented
capability.


Human acceptance steps: build once without `BUZZ_AUTH_DOMAINS`
(including with a previously saved account) and confirm no Builderlab
controls/restoration while ordinary link and QR/code entry work. Build
with supported domains and confirm connection/creation appear; exercise
browser return and live backup/recovery/reconnect. On physical iOS,
exercise export and interrupted sharing/locked-device protection. Record
results before marking review complete.

---------

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz>
Co-authored-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@wes.communities.public.builderlabstaging.xyz>
2026-10-19 15:46:58 -06:00
Logan Johnson
cc6336d985 feat(relay): tag every membership notice with its channel type (#8406)
🤖
## Summary
- When someone is added to or removed from a system channel, the relay
now sends them the usual "you were added / removed" notice. Before, it
sent nothing, so a client could learn about a new system channel only by
rereading every channel.
- **A client sees a notice only if it knows the channel's type.** Every
membership notice now carries its channel type. Clients that do not send
`#t` (every client today) see only the types that existed before system
channels, so they see no change. A type that Buzz adds later is hidden
from them by default.
- The notices are stored like every other membership notice, so a client
that was offline can catch up with `since` instead of rereading all its
channels.

## Details
- Every kind:44100 (added) and kind:44101 (removed) notice now carries
`["t", <channel_type>]`, for example `["t","stream"]` or
`["t","system"]`.
- **One place reads the channel type:** `emit_membership_notification`
in `side_effects.rs`, where the relay signs the notice. A channel's type
is set when it is created and no code path changes it, so the tag stays
correct. If the channel row is missing, the relay sends no notice rather
than an untagged one.
- **The rule (NIP-CL):**
- a filter with `#t` matches a notice only when the notice's type is one
of its `#t` values;
- a filter without `#t` matches only the **legacy types**: `stream`,
`forum`, `dm`, `workflow`. This list is frozen
(`LEGACY_NOTICE_CHANNEL_TYPES`), so a new type never joins it;
- a notice without a `t` tag was stored before this change. It is always
a legacy type, so the relay treats it as one, and replay across the
upgrade stays complete.
- **Fails closed.** The rule lives in two shared places, and both
default to the legacy types. A read path that is not updated behaves as
it does today:
- `filters_match` / `notice_visible` (buzz-core). Live fan-out, the REQ
history post-filter, COUNT, the HTTP bridge and push all match through
it.
- `EventQuery::notice_channel_types` (buzz-db). Its SQL keeps only
visible notices before `LIMIT`, so page limits and COUNT stay exact.
`None` means legacy types. Only `filter_to_query_params` sets it, from
the filter's `#t`.
- A client that knows every current type sends one filter:
`{"kinds":[44100,44101],"#p":[<me>],"#t":["stream","forum","dm","workflow","system"]}`.
NIP-CL and NOSTR.md describe this.
- **Only the target receives a notice.** A notice names the target, the
channel and who made the change, and the relay signs it, so knowing its
id is not permission to read it. 44100/44101 are now in
`RESULT_GATED_KINDS`, the one list used by the `ids` exemption check,
the per-result reader check (WS and HTTP history, push), live fan-out
(same pod and Redis) and COUNT. This also closes the same id lookup for
ordinary channels' notices.
- No migration: 44100/44101 are already excluded from search indexing.

## Testing
- `buzz-core`: a table test covers untagged, `stream`, `system` and a
future type against filters without `#t`, with `#t` for one type, and
with `#t` for every type. Other kinds keep the plain `#t` match.
- Postgres tests (`system_channel_postgres_tests.rs`): live fan-out, REQ
history, COUNT and the HTTP bridge, for a filter without `#t`, a
`#t:["system"]` filter and an all-types filter; an untagged legacy
notice; a non-target with an `ids` filter on each path; and a raw
`EventQuery` that does not set the field.
- I broke each part on purpose and the tests failed: no type tag on the
notice, no rule in `filters_match`, no SQL rule, and no untagged clause
in the SQL.
- End to end: I built a relay container from f24f8e7ba and ran
buzz-app's `container-relay.e2e.test.ts` (block/buzz-app#1290) against
it. The live system channel test passed 5 of 5 runs.

Paired client change: block/buzz-app#1290. It works unchanged against
this relay.

---------

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
2026-10-19 16:29:32 -04:00