block/buzz · error

seed writer member

Error message

seed writer member

What it means

This is `.expect("seed writer member")` on `relay_members::add_relay_member(&writer, cid, &writer_only, "member", None)`. It panics if the helper fails to insert the writer-only membership row, which the test later relies on to prove the writer answered when the gate is off. Failures are typically FK violations (community row missing) or missing `relay_members` table.

Source

Thrown at crates/buzz-db/src/runtime/tests.rs:1686

        .expect("connect admin");
    let (writer, wname) = create_scratch_db(&admin, "mem_w").await;
    let (replica, rname) = create_scratch_db(&admin, "mem_r").await;

    let community = Uuid::new_v4();
    for pool in [&writer, &replica] {
        sqlx::query("INSERT INTO communities (id, host) VALUES ($1, $2)")
            .bind(community)
            .bind(format!("member-routing-{}.example", community.simple()))
            .execute(pool)
            .await
            .expect("insert community");
    }
    let cid = CommunityId::from_uuid(community);
    let writer_only = "aa".repeat(32);
    let replica_only = "bb".repeat(32);
    relay_members::add_relay_member(&writer, cid, &writer_only, "member", None)
        .await
        .expect("seed writer member");
    relay_members::add_relay_member(&replica, cid, &replica_only, "member", None)
        .await
        .expect("seed replica member");

    let mut db = Db::from_pools(writer.clone(), replica.clone());
    db.fence().force_open_for_tests(chrono::Utc::now());

    // Budget unset ⇒ bounded arm disabled ⇒ writer.
    assert!(
        db.is_relay_member(cid, &writer_only)
            .await
            .expect("gate off"),
        "budget unset must answer from the writer"
    );
    assert!(!db.is_relay_member(cid, &replica_only).await.unwrap());

    // Budget set + fresh entry ⇒ replica.
    db.set_replica_read_max_age_for_tests(Some(std::time::Duration::from_secs(5)));

View on GitHub (pinned to dad5a33865)

Solutions

  1. Ensure migrations ran on the writer scratch DB so `relay_members` exists.
  2. Confirm the `communities` INSERT loop completed on the writer before this call (it iterates both pools).
  3. Unwrap with the underlying error to distinguish FK violation from missing table.
  4. Check `add_relay_member`'s signature/schema expectations after any recent buzz-db change.
  5. Use fresh scratch DB names to avoid stale conflicting rows.

Example fix

// before
relay_members::add_relay_member(&writer, cid, &writer_only, "member", None)
    .await.expect("seed writer member");
// after
relay_members::add_relay_member(&writer, cid, &writer_only, "member", None)
    .await.unwrap_or_else(|e| panic!("seed writer member failed: {e}"));
Defensive patterns

Strategy: validation

Validate before calling

// Verify the parent community row exists before add_relay_member
let n: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM communities WHERE id=$1")
    .bind(community).fetch_one(&writer).await.unwrap_or(0);
assert_eq!(n, 1, "community row must exist on writer before seeding members");

Type guard

async fn community_exists(pool: &sqlx::PgPool, id: uuid::Uuid) -> bool {
    sqlx::query_scalar::<_, i64>("SELECT COUNT(*) FROM communities WHERE id=$1")
        .bind(id).fetch_one(pool).await.map(|n| n == 1).unwrap_or(false)
}

Try / catch

relay_members::add_relay_member(&writer, cid, &writer_only, "member", None)
    .await.unwrap_or_else(|e| panic!("seed writer member (FK? migrations?): {e}"));

Prevention

When it happens

Trigger: Calling `add_relay_member` on the writer scratch pool when the `communities` row with `cid` was not inserted (or inserted only on the replica), the `relay_members` table doesn't exist (no migrations), or `cid`/pubkey types don't match schema expectations.

Common situations: Running against unmigrated scratch DBs; earlier `insert community` silently skipped on the writer; schema change renaming role/pubkey columns without updating `add_relay_member`; connection drop mid-test.

Related errors


AI-assisted analysis of block/buzz@dad5a33865 (2026-08-30). Data as JSON: /api/errors/543c97177a348038. Report an issue: GitHub.