block/buzz · error

build_ref_state_event: {e}

Error message

build_ref_state_event: {e}

What it means

emit_initial_ref_state builds the initial empty kind:30618 ref-state event for a newly announced repo using build_ref_state_event, which constructs and signs the event with the relay keypair. This error wraps construction/signing failure — the initial ref snapshot could not be built, so the announcement aborts with 'failed to emit initial kind:30618 ref state'.

Source

Thrown at crates/buzz-relay/src/handlers/side_effects.rs:2937

async fn emit_initial_ref_state(
    tenant: &TenantContext,
    state: &Arc<AppState>,
    lease: &buzz_db::deletion::ServingWriteLease,
    owner_hex: &str,
    repo_id: &str,
) -> anyhow::Result<()> {
    use crate::api::git::manifest_event::{build_ref_state_event, RefStateInputs};
    use std::collections::BTreeMap;

    let empty_refs: BTreeMap<String, String> = BTreeMap::new();
    let inputs = RefStateInputs {
        repo_id,
        head: DEFAULT_HEAD,
        refs: &empty_refs,
        actor_pubkey_hex: owner_hex,
    };
    let event = build_ref_state_event(&inputs, &state.relay_keypair)
        .map_err(|e| anyhow::anyhow!("build_ref_state_event: {e}"))?;
    let (stored, was_inserted) = state
        .db
        .insert_event_with_serving_write_guard(lease, &event, None)
        .await
        .map_err(|e| anyhow::anyhow!("insert kind:30618: {e}"))?;
    if was_inserted {
        // Routed through the guarded send path for uniformity; the access gate
        // no-ops for this globally-scoped (channel_id = None) ref-state event.
        crate::handlers::event::fan_out_event_to_local_subscribers(
            state,
            tenant.community(),
            &stored,
        )
        .await;
    }
    Ok(())
}

View on GitHub (pinned to dad5a33865)

Solutions

  1. Validate BUZZ_RELAY_PRIVATE_KEY — restart with a valid 32-byte hex key so signing succeeds.
  2. Check wrapped {e} for the specific build/sign failure and fix the offending input.
  3. Verify the kind:30617 announcement's owner pubkey is valid hex (32 bytes) before re-running.
  4. Re-announce the repo; the announcement fence allows retrying emit_initial_ref_state.

Example fix

// before: announcement proceeds with possibly invalid pubkey hex
let owner = owner_hex.clone();
// after: guard before emitting refs
anyhow::ensure!(hex::decode(&owner_hex).is_ok(), "invalid owner hex");
Defensive patterns

Strategy: validation

Validate before calling

anyhow::ensure!(!repo_id.is_empty() && validate_repo_id(repo_id), "bad repo id");
anyhow::ensure!(hex::decode(&actor_pubkey_hex).map_or(false, |b| b.len() == 32), "bad owner hex");
Keys::parse(&relay_key_hex)?; // fail early on bad signing key

Try / catch

match build_ref_state_event(&inputs, &state.relay_keypair) {
    Err(e) => return Err(anyhow!("emit_initial_ref_state failed: {e:#}")),
    Ok(event) => { /* insert under lease */ }
}

Prevention

When it happens

Trigger: Calling emit_initial_ref_state when the relay keypair cannot sign (invalid/corrupt key) or build_ref_state_event receives invalid inputs (malformed repo_id, owner pubkey hex, or refs payload).

Common situations: Same relay-keypair misconfiguration as signing errors elsewhere; a repo_id that slipped through with characters the event builder rejects; corrupted owner_pubkey_hex in the announcement pipeline.

Related errors


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