block/buzz · error

routed query, gate on

Error message

routed query, gate on

What it means

This is an `.expect("routed query, gate on")` panic on the `query_events_routed` future in buzz-db's runtime routing tests. `query_events_routed` returns a `Result`, and the expect unwraps it, panicking with the message "routed query, gate on" if the query fails after the replica-read budget has been enabled (the replica-served arm). The library surfaces DB-level failures this way in tests so a routing regression manifests as a loud panic naming the exact routing arm under test.

Source

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

    let rows = db
        .query_events_routed("test_routed", &q)
        .await
        .expect("routed query, gate off");
    assert!(
        contents(&rows).contains("writer-only"),
        "budget unset must serve the writer"
    );
    assert!(
        !contents(&rows).contains("replica-only"),
        "budget unset must not reach the replica via the covered arm"
    );

    // Budget set ⇒ the covered arm serves it from the replica.
    db.set_replica_read_max_age_for_tests(Some(std::time::Duration::from_secs(5)));
    let rows = db
        .query_events_routed("test_routed", &q)
        .await
        .expect("routed query, gate on");
    assert!(
        contents(&rows).contains("replica-only"),
        "budget set + covered-eligible must route to the replica"
    );
    assert!(!contents(&rows).contains("writer-only"));

    drop_scratch_db(&admin, replica, &rname).await;
    drop_scratch_db(&admin, writer, &wname).await;
}

/// COUNT is bounded-only (rev 5 deletion-visibility rule): a
/// covered-eligible shape must NOT let a count take the covered arm.
/// With the budget unset the count reads the WRITER even with an open
/// fence; with the budget set and a fresh entry it reads the replica
/// under the bounded arm. Divergent row counts prove the serving pool.
#[tokio::test]
#[ignore = "requires Postgres"]
async fn count_events_routed_is_bounded_only() {

View on GitHub (pinned to dad5a33865)

Solutions

  1. Start Postgres and confirm the admin URL (from `admin_url()`) is reachable before running the test (test is normally skipped via #[ignore]).
  2. Run pending migrations against the scratch writer and replica databases so events tables exist.
  3. Check the inner sqlx error by temporarily replacing `.expect` with `.unwrap_err()` or match to see the real DB failure.
  4. Verify `set_replica_read_max_age_for_tests(Some(Duration::from_secs(5)))` was applied and the fence is open before the query.
  5. Ensure no firewall/timeout kills the replica pool connection mid-test; reuse the same Db instance as the test constructs.

Example fix

// before
let rows = db.query_events_routed("test_routed", &q).await.expect("routed query, gate on");
// after
let rows = db.query_events_routed("test_routed", &q).await
    .unwrap_or_else(|e| panic!("routed query (gate on) failed: {e}"));
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight before routed queries in tests
async fn assert_replica_ready(db: &Db) -> Result<(), sqlx::Error> {
    sqlx::query("SELECT 1").execute(db.replica()).await.map(|_| ())
}
// call before query_events_routed

Type guard

fn routed_ok<T>(r: &Result<T, sqlx::Error>) -> bool { r.is_ok() }

Try / catch

match db.query_events_routed("test_routed", &q).await {
    Ok(rows) => rows,
    Err(e) => panic!("routed query failed: {e}"),
}

Prevention

When it happens

Trigger: Calling `db.query_events_routed("test_routed", &q)` in the `query_events_routed_defaults_dark_and_routes_covered_when_enabled` test after `set_replica_read_max_age_for_tests(Some(5s))` when the underlying sqlx query against the replica pool returns Err (connection failure, missing table/schema in the scratch replica DB, query error).

Common situations: Running the `#[ignore = "requires Postgres"]` integration tests without a reachable Postgres admin server; scratch replica DB created but not migrated (missing events tables); the replica pool pointing at a dropped or locked scratch database; invalid `until`/channel parameters in the EventQuery causing a SQL error.

Related errors


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