{"record":{"id":"543c97177a348038","repo":"block/buzz","slug":"seed-writer-member","errorCode":null,"errorMessage":"seed writer member","messagePattern":"seed writer member","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/buzz-db/src/runtime/tests.rs","lineNumber":1686,"sourceCode":"        .expect(\"connect admin\");\n    let (writer, wname) = create_scratch_db(&admin, \"mem_w\").await;\n    let (replica, rname) = create_scratch_db(&admin, \"mem_r\").await;\n\n    let community = Uuid::new_v4();\n    for pool in [&writer, &replica] {\n        sqlx::query(\"INSERT INTO communities (id, host) VALUES ($1, $2)\")\n            .bind(community)\n            .bind(format!(\"member-routing-{}.example\", community.simple()))\n            .execute(pool)\n            .await\n            .expect(\"insert community\");\n    }\n    let cid = CommunityId::from_uuid(community);\n    let writer_only = \"aa\".repeat(32);\n    let replica_only = \"bb\".repeat(32);\n    relay_members::add_relay_member(&writer, cid, &writer_only, \"member\", None)\n        .await\n        .expect(\"seed writer member\");\n    relay_members::add_relay_member(&replica, cid, &replica_only, \"member\", None)\n        .await\n        .expect(\"seed replica member\");\n\n    let mut db = Db::from_pools(writer.clone(), replica.clone());\n    db.fence().force_open_for_tests(chrono::Utc::now());\n\n    // Budget unset ⇒ bounded arm disabled ⇒ writer.\n    assert!(\n        db.is_relay_member(cid, &writer_only)\n            .await\n            .expect(\"gate off\"),\n        \"budget unset must answer from the writer\"\n    );\n    assert!(!db.is_relay_member(cid, &replica_only).await.unwrap());\n\n    // Budget set + fresh entry ⇒ replica.\n    db.set_replica_read_max_age_for_tests(Some(std::time::Duration::from_secs(5)));","sourceCodeStart":1668,"sourceCodeEnd":1704,"githubUrl":"https://github.com/block/buzz/blob/dad5a33865fc81a2e55b3b60746632f615ec1e3a/crates/buzz-db/src/runtime/tests.rs#L1668-L1704","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure migrations ran on the writer scratch DB so `relay_members` exists.","Confirm the `communities` INSERT loop completed on the writer before this call (it iterates both pools).","Unwrap with the underlying error to distinguish FK violation from missing table.","Check `add_relay_member`'s signature/schema expectations after any recent buzz-db change.","Use fresh scratch DB names to avoid stale conflicting rows."],"exampleFix":"// before\nrelay_members::add_relay_member(&writer, cid, &writer_only, \"member\", None)\n    .await.expect(\"seed writer member\");\n// after\nrelay_members::add_relay_member(&writer, cid, &writer_only, \"member\", None)\n    .await.unwrap_or_else(|e| panic!(\"seed writer member failed: {e}\"));","handlingStrategy":"validation","validationCode":"// Verify the parent community row exists before add_relay_member\nlet n: i64 = sqlx::query_scalar(\"SELECT COUNT(*) FROM communities WHERE id=$1\")\n    .bind(community).fetch_one(&writer).await.unwrap_or(0);\nassert_eq!(n, 1, \"community row must exist on writer before seeding members\");","typeGuard":"async fn community_exists(pool: &sqlx::PgPool, id: uuid::Uuid) -> bool {\n    sqlx::query_scalar::<_, i64>(\"SELECT COUNT(*) FROM communities WHERE id=$1\")\n        .bind(id).fetch_one(pool).await.map(|n| n == 1).unwrap_or(false)\n}","tryCatchPattern":"relay_members::add_relay_member(&writer, cid, &writer_only, \"member\", None)\n    .await.unwrap_or_else(|e| panic!(\"seed writer member (FK? migrations?): {e}\"));","preventionTips":["Insert the community row on the writer before seeding members","Migrate the writer scratch DB first","Keep relay_members schema and add_relay_member in sync","Assert seed success rather than relying on bare labels"],"tags":["postgres","foreign-key","test-panic","seed-data"],"backgroundTag":"postgres-insert-failed","analyzedSha":"dad5a33865fc81a2e55b3b60746632f615ec1e3a","analyzedAt":"2026-08-30T13:49:18.474Z","contentChangedAt":"2026-08-30T13:49:18.474Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}