clockworklabs/SpacetimeDB · error

database ` ` not yet initialized

Error message

database `{addr}` not yet initialized

What it means

update_module runs module.update_database only when the database already stores a program hash; stored_program_hash(db) returning None means this database identity never had a program published. The host refuses to 'update' an uninitialized database instead of invoking the module. It indicates an update was requested before the initial publish completed, or against the wrong database.

Solutions

  1. Publish (initialize) the module on the database first, then retry the update.
  2. Verify the DatabaseIdentity/address used for the update matches the intended database.
  3. Inspect the stored program (stored_program_hash / describe APIs) to confirm initialization before updating.
  4. If the first publish crashed, re-run the full publish rather than the update path.

Example fix

// before
update_module(&db, &module, program, old_info, policy).await?; // database `{addr}` not yet initialized

// after
if stored_program_hash(&db)?.is_none() {
    module.publish_database(/* ... */).await?; // initial publish initializes the program
} else {
    update_module(&db, &module, program, old_info, policy).await?;
}
Defensive patterns

Strategy: validation

Validate before calling

if stored_program_hash(&db)?.is_none() {
    // not initialized: run the publish path, not the update path
    return publish_database(&db, program).await;
}

Try / catch

Catch the error in update orchestration and fall back to the publish/initialize flow for that database identity.

Prevention

When it happens

Trigger: The publish pipeline routes a module update to a freshly created database before the initial program publish commits; update_module is called on a database recreated after data loss; the wrong DatabaseIdentity is passed to the update path.

Common situations: Race between database creation and publish in CI; a crashed first publish leaving no stored program; a misconfigured address variable pointing updates at an empty database.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-09-20). Data as JSON: /api/errors/ca41fde86b26b3f1. Report an issue: GitHub.

Appendix: source

Thrown at crates/core/src/host/host_controller.rs:1145

/// Update a module.
///
/// If the `db` is not initialized yet (i.e. its program hash is `None`),
/// return an error.
///
/// Otherwise publish the complete environment with the module, including when
/// its program hash is unchanged.
async fn update_module(
    db: &RelationalDB,
    module: &ModuleHost,
    program: Program,
    old_module_info: Arc<ModuleInfo>,
    policy: MigrationPolicy,
    environment: std::collections::BTreeMap<String, String>,
) -> anyhow::Result<UpdateDatabaseResult> {
    let addr = db.database_identity();
    let Some(stored) = stored_program_hash(db)? else {
        bail!("database `{addr}` not yet initialized");
    };
    info!("publishing `{}` from {} to {}", addr, stored, program.hash);
    // Even an unchanged program publishes a complete replacement environment.
    module
        .update_database_with_environment(program, old_module_info, policy, environment)
        .await
}

/// Encapsulates a database, associated module, and auxiliary state.
struct Host {
    /// The [`ModuleHost`], providing the callable reducer API.
    ///
    /// Modules may be updated via [`Host::update_module`].
    /// The module is wrapped in a [`watch::Sender`] to allow for "hot swapping":
    /// clients may subscribe to the channel, so they get the most recent
    /// [`ModuleHost`] version or an error if the [`Host`] was dropped.
    module: watch::Sender<ModuleHost>,
    /// Pointer to the `module`'s [`ReplicaContext`].

View on GitHub (pinned to eddf9f5014)