Skip to content

REPL mode never persists wallet changes in the REPL loop #375

Open

Description

@emma31-dev

Describe the bug
In REPL mode, wallet changes are never written to the database. The non-REPL path calls wallet.persist() after every wallet command, but the REPL loop never does, and there is no Drop fallback.

The REPL does load a persisted wallet via runtime.build_wallet(true), so this is a missing write, not a no-database case. Affects both sqlite and redb, since both go through the same RuntimeWallet::persist() , which is only called from the two non-REPL sites. src/handlers/repl.rs also executes commands without persisting.

Consequence: everything done in a session is lost on exit , most visibly the address index, but also created/bumped txs, broadcast txs, UTXO lock state, and scan/sync results.

To Reproduce
On regtest with default features (repl, sqlite):

  1. Create a wallet with any datatype.
  2. Start bdk-cli repl --wallet w, run wallet new_address twice → indices n.
  3. Exit and start the REPL again, run wallet new_address → index n again.
  4. Control: run bdk-cli --network regtest --datadir <dir> wallet --wallet w new_address twice in separate processes → indices n, n+1 (correctly persisted).
  5. Running the REPL again after step 4 resumes at index n+2, proving reads work and only REPL writes are missing.

Observed:
REPL run 1: new_address -> index 0, new_address -> index 1
REPL run 2 (fresh process): new_address -> index 0 <– rolled back
REPL run 3 (fresh process): new_address -> index 0 <– still rolled back
non-REPL: 0 then 1 (persisted); REPL then resumes at 2

Expected behavior
REPL commands should persist the wallet (at least after each successful command), so a new session resumes from the last state and new_address never reuses an address.

Build environment

  • BDK-CLI tag/commit: 6579837 (master, v4.0.0)
  • OS+version: macOS 12.7.6
  • Rust/Cargo version: rustc 1.97.1, cargo 1.97.1
  • Rust/Cargo target: x86_64-apple-darwin

Additional context
Suggested fix: persist after each successful REPL command rather than only on exit, so a crash or Ctrl-C doesn't lose the session either:

let should_exit = crate::handlers::repl::respond(
    runtime.network,
    &mut wallet,
    /* ... */
    &line,
    runtime.home_dir.clone(),
    /* ... */
    &wallet_name,
)
.await
.map_err(Error::Generic)?;

wallet.persist()?;

if should_exit {
    break;
}

Activity

  1. added
    bug
    on Nov 7, 2026
  2. moved this from Todo to In Progress in BDK-CLIon Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    • Status
      In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions