Skip to content

feat(platform-wallet): store and commit a record in one backend step - #5955

Merged
QuantumExplorer merged 5 commits into
v5.1-devfrom
feat/platform-wallet-store-and-commit
Nov 17, 2026
Merged

QuantumExplorer merged 5 commits into
v5.1-devfrom
feat/platform-wallet-store-and-commit

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: The wallet saves its records through a storage backend in two calls: store puts a record in a waiting area (the buffer), and flush writes the buffer to disk. Before the wallet acts on a record being on disk (pays for a private contact request it must find again after a restart, publishes a wallet whose old backfill record must be gone), it has to know that this record was written. With two calls it cannot know that directly: something else can empty the buffer in between and lose the record, and the wallet's own flush then succeeds over an empty buffer. Until now the wallet worked the answer out from outside: it counted the flushes around the two calls and asked the backend how often it had dropped its buffer. This PR adds one backend operation, store_and_commit, that does both in a single step nothing else can come between, and that says exactly what happened to the record it was given. The SQLite backend implements it, and the wallet uses it wherever a backend offers it.

Value: On the SQLite backend, "this record is on disk" becomes something the backend states, not something the wallet concludes from counters. The counters on v5.1-dev (#5923) are safe, but all they can do is refuse: whenever another flush of the same wallet ran or returned while a record was being made durable, or the host committed in between, the wallet reports the record as not durable and the caller starts over, even when the record was written. With the step nothing can come between the store and its commit, so those cases succeed, and every failure says where the record is (never written, or still buffered for a later flush). Hosts that write at the store (the Swift and Kotlin apps) are not touched.

Risks: Low to medium. No consensus code. Behaviour changes only for a backend that offers the step, which today is SQLite alone:

  • In SQLite's default immediate mode, a durable store whose commit fails is now reported as a failed flush (PersisterFlush, with the backend's own kind) where it was reported as a failed store (PersisterStore, a transient one narrowed to fatal). The new report is the accurate one, since after a transient failure the record is still buffered and the next write for that wallet commits it. Every caller treats either as "not durable" and does not go on.
  • Also in immediate mode, the wallet's check that everything stored so far is on disk (flush_durably, made before the journal record of a private payment is discharged) now flushes and reads the flush ledger, where it answered Ok at once. Immediate mode can hold a record whose commit failed transiently, so the old answer could be given while that record was in the buffer only. The check takes the connection for one short flush, and in a database opened read-only for recovery it now answers "not durable", as it already did in manual mode.
  • Also in immediate mode, the wallet now reads SQLite's own count of dropped buffers (buffered_writes_dropped), which fix(platform-wallet): trust a stored record only when no other flush dropped it #5923 read in manual mode only. A write that fails for good in immediate mode, a plain store included, therefore counts as a loss for every handle of that wallet: from then on they do not discharge a private payment's journal record on the strength of what they track, and they store their markers again, until the wallet is loaded anew. That is what manual mode already does after a flush that fails for good. This one is my choice, made to close the gap described under "The step is counted in the flush ledger"; reverting it is one condition in losses_of.
  • In SQLite's manual mode, a durable store holds the connection from its merge to the end of its commit, as an immediate-mode store already does.
  • A backend that attested the step without keeping its contract would be trusted wrongly. The attestation defaults to false, and the default implementation refuses every changeset.
  • withdraw_durably (from fix(platform-wallet): trust a stored record only when no other flush dropped it #5923) takes the step too. Its Ok has to mean that nothing writes the withdrawn record afterwards, and on a backend with the step that rests on the step's contract, where it rested on the wallet's counters.

Issue being fixed or feature implemented

WalletPersister::store_durably (packages/rs-platform-wallet/src/wallet/persister.rs) answers "is this record on disk?" by inference. It reads the wallet's flush ledger (flushes in progress, failed, failed for good), calls store, calls flush, and reads the ledger again. #5923 extended that over ten review rounds, each closing one interleaving with one more counter. The review's verdict there was that the cause is structural: PlatformWalletPersistence has no per-wallet operation that binds a stored changeset to its durable result, so every counter closes one race and leaves another. It asked for an atomic primitive in the trait and in SqlitePersister, for the wallet to consume.

This PR is that primitive. #5923 merged while this was in review. v5.1-dev is merged into this branch and the PR builds on it: the counters stay for a backend without the step, and the step is used where a backend offers it.

What was done?

The trait: offers_store_and_commit and store_and_commit

packages/rs-platform-wallet/src/changeset/traits.rs gains two methods on PlatformWalletPersistence and one error type:

fn offers_store_and_commit(&self) -> bool { false }

fn store_and_commit(
    &self,
    wallet_id: WalletId,
    changeset: PlatformWalletChangeSet,
) -> Result<(), StoreAndCommitError>;   // default: refuses, staging nothing

pub enum StoreAndCommitError {
    NotStaged(PersistenceError),     // refused before it was staged
    NotCommitted(PersistenceError),  // staged, and the commit failed
}

The contract, required of a backend that attests the step:

  • One step. From before the changeset is staged until its commit has succeeded, or failed and been dealt with, nothing else drains the wallet's buffer: no flush, no other store_and_commit, nothing the host can call on the backend. A drain that began earlier has finished by then.
  • In order. What was buffered before the changeset is committed with it, the changeset after all of it. Nothing a drain took before the step reaches the disk after it.
  • All or nothing. A commit that fails leaves nothing of the changeset on disk.
  • An exact answer. Ok means the changeset is on disk. NotStaged means none of it is buffered or written and the buffer is as it was. NotCommitted means it is still buffered after a transient failure, and dropped after any other. A backend that lost its buffer while refusing a changeset (a poisoned lock) answers NotCommitted, never NotStaged, because the buffer is not as it was.

Both variants carry the backend's PersistenceError as their source(), like PlatformWalletError::PersisterStore and PersisterFlush do.

Scope: one backend instance. The contract is about one backend instance and the buffer it keeps. It orders nothing against another instance over the same storage, such as another process with the same database open: that is a writer of its own with a buffer of its own, and what it writes later lands later, through the step or through store and flush alike. For SQLite the guard is the persister's own connection, and the crate's rule for two processes on one database is the one its delete_wallet and restore_from docs already give: callers serialize them.

Why this shape. An attestation that defaults to false, plus a method whose default refuses, is how this trait already adds abilities (store_commits_inline, store_transient_is_reissuable, stores_dashpay_backfill). Every existing backend compiles unchanged, and the wallet takes exactly the path it took before for it: the only new code such a backend reaches is the attestation answering false. Two other shapes were considered and not taken:

  • One method whose default hands the changeset back as "unsupported". The wallet would have to call it to find out, and the call is counted in the flush ledger as in progress while it runs. For that instant a concurrent durable store on a backend without the step could be refused. That is a behaviour change for existing backends, however rare.
  • A default that calls store and then flush. It would look like the step without being one.

How a failed store is told from a failed commit

The two variants map one to one onto what call sites already report differently:

Backend answer store_durably answer classify_not_durable
NotStaged(e) NotDurable::Store(e) PersisterStore, with the backend's own kind. A transient one stays transient: the answer itself says nothing was staged or written, so the changeset may be issued again
NotCommitted(e) NotDurable::Flush(e) PersisterFlush, with the backend's own kind

NotDurable::Lost and NotDurable::OtherFlushUnsettled are never the answer on this path. Both stand for what could not be told from outside the backend.

A plain store that fails transiently on a backend without the step is still narrowed to fatal unless the backend attests store_transient_is_reissuable. That attestation speaks for store; the step's NotStaged makes the same promise by itself, for the changeset it was given.

The step is counted in the flush ledger

FlushLedger::store_and_commit (packages/rs-platform-wallet/src/changeset/flush_ledger.rs) wraps the backend call as FlushLedger::flush wraps a flush: in progress from before the call until its outcome is recorded, failed when the commit fails, lost when it fails for good or the backend panics. A changeset refused before it was staged took nothing from the buffer and is not counted.

A step that fails for good is counted as lost on every backend, one whose store is the commit included. "The store is the commit" says that a store which answers Ok is on disk. It does not say the buffer is empty: by the step's contract a changeset whose commit failed transiently stays buffered, and SQLite in immediate mode keeps it and commits it with the next write. So a backend that offers the step keeps a buffer whatever its store does (keeps_a_buffer in flush_ledger.rs), and on such a backend a flush that fails for good is counted as lost too, where it was counted as failed only. A backend whose store is the commit and that does not offer the step (the Swift and Kotlin hosts) is counted as before: its flush only notifies the host and is never a loss.

Not counted in the ledger: a drain the wallet does not make through it. A host's commit_writes is one. In immediate mode a plain store is another, since it commits whatever an earlier transient failure left in the buffer, or drops it when it fails for good. Only the backend can count those, and SQLite does: #5923's buffered_writes_dropped is added to the losses a handle compares. #5923 left that count out for a backend whose store is the commit, on the same "nothing is buffered there" reasoning. It is now read for every backend that keeps a buffer (losses_of in wallet/persister.rs decides by keeps_a_buffer), so in immediate mode too.

The caller of the step needs none of this for its own answer. It is counted for everyone else: a commit that fails for good drops the wallet's whole buffer, what other handles stored plainly included, so flush_durably and the stored private payment markers have to see it.

flush_durably stays on the ledger, and no longer skips it in immediate mode

flush_durably has no changeset of its own. It asks whether anything stored earlier, by any handle of the wallet id, was dropped since the handle was made. That is a question about the past, and a step that binds one changeset to one commit cannot answer it. It stays on the ledger for every backend that keeps a buffer, and sees a failed step there.

One thing about it changes. It answered Ok at once for every backend whose store is the commit, on the reasoning that nothing is buffered there. That holds for the Swift and Kotlin hosts. It does not hold for SQLite in immediate mode, which is such a backend and still holds a changeset whose commit failed transiently. Since this PR reports that case as "still buffered, a later flush writes it", flush_durably has to be a flush that writes it, and has to see a later failure that dropped it. It now answers at once only for a backend that keeps no buffer (keeps_a_buffer: the store is the commit and the step is not offered). For SQLite in either mode it flushes and reads the ledger: Ok only after a flush that succeeded with no flush or step in progress, nothing lost since the handle was made (by the ledger's count or the backend's own), and no other flush or step failed or returned during the call.

A host that applies a changeset in parts

The step requires all or nothing, so such a host cannot offer it, and nothing more can be said for it than before: a failed store does not say how much of the changeset reached the disk. FFIPersister (packages/rs-platform-wallet-ffi/src/persistence.rs) is not changed and does not attest the step, because its store fans out to host callbacks (the asset lock callback runs before the shielded recipient sidecar) and some hosts attest capabilities without ATOMIC_CHANGESETS. A call site has to keep treating NotDurable::Store from a backend without the step as "may be partly written".

What the step adds is the other half: for a backend that offers it, that doubt is gone, and the doubt that remains is tied to a backend property the code can ask about (offers_store_and_commit). A host that commits at the store and rolls a failed round back whole could later offer its store as the step, answering every failure as NotStaged. That needs nothing from this PR and is not done here.

SQLite: the immediate-mode path, made available in manual mode

packages/rs-platform-wallet-storage/src/sqlite/persister.rs: an immediate-mode store already held one connection guard across its buffer merge and its flush. That body is now stage_and_commit, used by the immediate-mode store (same behaviour, one error as before) and by the new store_and_commit in both flush modes. flush_inner (so commit_writes and the trait's flush) and delete_wallet_inner already take the same connection and hold it across their take, write and restore, so they are not changed: holding it is what keeps them out.

A poisoned lock is reported as NotCommitted(LockPoisoned), not as NotStaged. Finding the connection poisoned discards every buffered changeset, so although the new changeset never reached the buffer, the buffer is not as it was, and the ledger has to count the loss.

That discard is every wallet's, as on every other path that finds the connection poisoned, and the step reports it for its own wallet only. No other wallet can be told a record is on disk in the meantime: every later store, flush and store_and_commit on that persister fails with LockPoisoned, and each wallet's next flush or step counts the loss in its own ledger. A count that reaches every wallet's ledger at once is buffered_writes_dropped in #5923, which counts this discard for all of them.

The wallet uses it

WalletPersister::store_durably and withdraw_durably ask the backend for the step when it is offered, and otherwise run the code #5923 gave them, unchanged. The changeset is prepared the same way on both paths (an established contact's outbound-account marker is stripped on a backend that cannot keep it).

withdraw_durably stores a record's removal, and its Ok has to mean more than "the removal is on disk": nothing may write the record after it. Without the step it works that out by refusing whenever a flush was in progress or returned across the store. With the step there is nothing to work out. A drain that began earlier has finished before the removal is staged, and the commit writes whatever of the record is still buffered with the removal behind it, which is the contract's "one step" and "in order".

Before and after

A commit the host makes on a manual-mode SQLite backend, between the wallet's store and its flush:

Before (v5.1-dev)
  wallet: backend.store(record)           buffered
  host:   backend.commit_writes()         takes the record, the write fails for good,
                                          the record is dropped and the drop counted
  wallet: backend.flush(wallet)           empty buffer: Ok
  wallet: the backend's drop count moved
  => store_durably: Err(NotDurable::Lost)    right, and all the wallet can say: the caller starts over

After
  wallet: backend.store_and_commit(record)   holds the connection: merge, then commit
  host:   backend.commit_writes()            waits, then finds nothing to take
  => store_durably: Ok(())                   the record is on disk
     or Err(NotDurable::Flush(e))            its own commit failed, told to the caller whose record it was

Another flush of the same wallet running during a durable store, manual mode:

Before:  Err(NotDurable::OtherFlushUnsettled)   whenever that flush was in progress or returned while
                                                the record was made durable, though it was written
After:   Ok(())                                 the step is serialized with that flush by the backend

A durable store whose commit fails transiently, immediate mode (the SQLite default):

Before:  NotDurable::Store(FlushRetryable)  ->  PersisterStore, kind Fatal
After:   NotDurable::Flush(FlushRetryable)  ->  PersisterFlush, kind Transient
         (the record is still buffered, and the next write for the wallet commits it)

Asking whether everything stored is on disk (flush_durably) after that failure, immediate mode:

Before:  Ok(())   at once, no flush made: the record is in the buffer only
After:   the buffer is flushed first
           flush succeeds, nothing in progress, nothing lost  ->  Ok(()), the record is on disk
           flush fails transiently                            ->  NotDurable::Flush, kind Transient
           a flush or a step failed for good since            ->  NotDurable::Lost
           a step of another handle has not recorded yet      ->  NotDurable::OtherFlushUnsettled

Withdrawing a record (withdraw_durably) while a flush that took it is in progress, manual mode:

Before:  Err(NotDurable::OtherFlushUnsettled)   nothing flushed: that flush may write the record afterwards
After:   Ok(())                                 the step waits for that flush, then writes the removal behind it

How this builds on #5923

#5923 is merged, and v5.1-dev is merged into this branch (a merge commit, no rebase). Its conflicts were in the docs of store_durably, flush_durably and the ledger, and in the two bodies both PRs edit. What the two do together:

How Has This Been Tested?

Twenty-five new tests. Each was run with its fix taken out and fails, and passes with it back. The wallet-crate ones were run that way again on the merged tree.

Wallet crate (packages/rs-platform-wallet), seventeen:

Test Fails when
wallet::persister should_commit_a_store_in_one_step_so_a_commit_by_the_host_cannot_drop_it store_durably stores and flushes in two calls: answers Ok with nothing on disk
wallet::persister should_commit_a_store_in_one_step_so_a_flush_in_progress_cannot_write_an_older_state_last the same: the older state is written last, and the store is refused with OtherFlushUnsettled
wallet::persister should_commit_a_withdrawal_in_one_step_so_a_flush_in_progress_cannot_write_the_record_after_it withdraw_durably stores and flushes in two calls: refused with OtherFlushUnsettled, nothing flushed
wallet::persister should_take_the_backends_answer_for_a_withdrawal_committed_in_one_step the same: the backend is stored to and flushed, and its answer for the step is not consumed
wallet::persister should_report_a_refused_changeset_as_a_failed_store_and_a_failed_commit_as_a_failed_flush the same: the backend's answer is not consumed. Also when a transient refusal by the step is narrowed to fatal like a plain store's
wallet::persister should_still_narrow_a_transient_store_failure_of_a_backend_without_the_step every store failure keeps its kind, a plain store's included
wallet::persister should_tell_the_wallet_ids_other_handles_of_a_commit_in_one_step_that_dropped_the_buffer the step is not counted in the ledger
wallet::persister should_commit_a_contact_in_one_step_without_a_marker_the_backend_cannot_keep the step is handed the changeset unprepared
changeset::flush_ledger should_count_a_failed_commit_of_a_store_made_in_one_step_as_a_failed_flush the step is not counted in the ledger, or a step that fails for good is counted as lost only on a backend whose store buffers
changeset::flush_ledger should_count_a_store_being_committed_in_one_step_as_a_flush_in_progress the same
wallet::persister should_flush_an_inline_backend_that_commits_in_one_step_before_calling_its_records_durable flush_durably answers at once for every backend whose store is the commit: Ok with the record in the buffer only
wallet::persister should_report_the_loss_of_what_a_commit_in_one_step_left_buffered_on_an_inline_backend the same, or a flush of such a backend that fails for good is not counted as lost: Ok for a record that was dropped
wallet::persister should_not_answer_for_an_inline_backend_while_a_commit_in_one_step_is_in_progress flush_durably answers at once for every backend whose store is the commit: Ok while the step's outcome is not recorded
changeset::flush_ledger should_count_a_flush_that_fails_for_good_as_lost_on_an_inline_backend_that_commits_in_one_step a flush is never counted as lost on a backend whose store is the commit
wallet::persister should_read_the_drops_an_inline_backend_that_commits_in_one_step_reports the backend's drop count is not read for a backend whose store is the commit: Ok for a record a plain store dropped, and a stored marker is kept
changeset::traits should_not_offer_the_atomic_step_unless_the_backend_attests_it the attestation defaults to true
changeset::traits should_keep_the_persistence_error_as_the_source_of_a_failed_atomic_step the variants do not mark their error as the source

Storage crate (packages/rs-platform-wallet-storage), eight, in tests/integration/sqlite_store_and_commit.rs and sqlite_recovery_mode_write_block.rs. The racing ones park the second actor between the step's merge and its commit with the crate's existing release_at_store_seam, so they do not depend on timing:

Test Fails when
should_tell_the_step_that_staged_a_changeset_when_it_is_dropped_and_not_a_commit_by_the_host the connection is released between the merge and the commit: the host's commit_writes takes the changeset, eats the fatal failure, and the step answers Ok
should_keep_a_flush_racing_the_step_from_taking_what_it_staged the same, with a flush of the wallet as the second actor
should_keep_a_changeset_buffered_for_a_later_commit_when_its_own_fails_transiently the same, with a transient failure
should_commit_what_was_buffered_before_the_changeset_with_it_and_in_that_order the changeset is written alone, past the buffer: a later drain writes the older state over it
should_leave_the_buffer_as_it_was_when_a_changeset_is_refused_before_it_is_staged a refused merge is reported as a failed commit
should_report_a_poisoned_connection_as_a_dropped_buffer_and_not_as_nothing_staged a poisoned connection is reported as NotStaged
should_offer_the_step_through_the_trait_in_both_flush_modes SQLite does not attest the step
should_refuse_a_store_and_commit_in_recovery_before_it_stages_anything the step skips the recovery-mode check

The four flush_durably tests run against a wallet-crate backend that behaves as SQLite does in immediate mode (the store is the commit, the step is offered, a transient failure keeps the buffer). flush_durably is private to the wallet crate, so the storage crate cannot call it. What the SQLite side contributes, that an immediate-mode write which fails transiently leaves its changeset buffered and a flush then writes it, is already pinned there by tc_p2_006_immediate_surfaces_flush_retryable in sqlite_buffer_semantics.rs; the storage crate's code is not changed by this fix, only its docs.

One interleaving has no storage-level test, on purpose: a flush that took an older state and writes it after the step. On SQLite it cannot be produced with or without this PR, because flush_inner already holds the connection across its take, its write and its restore, so no test of it could fail. The wallet-level test above covers it against a backend whose plain flushes can do it, and the ordering test covers the half the step itself owns.

Commands, all passing on the final tree (cc61f1a538, which has v5.1-dev at 4505fc5667 merged in):

cargo fmt --all -- --check
cargo clippy --package platform-wallet --package platform-wallet-ffi --package platform-wallet-storage --all-targets --all-features --locked -- --no-deps -D warnings
cargo test -p platform-wallet --lib --features shielded --locked -- changeset:: manager:: wallet::persister wallet::identity::network wallet::shielded wallet::asset_lock   # 1521 passed
cargo test -p platform-wallet --lib --locked -- changeset:: manager:: wallet::persister wallet::identity::network wallet::asset_lock                                         # 1128 passed
cargo test -p platform-wallet-storage --locked --lib -- sqlite::buffer sqlite::persister                                                                                     # 6 passed
cargo test -p platform-wallet-storage --locked --test integration                                                                                                            # 568 passed, 1 ignored
cargo check --package platform-wallet --all-targets --locked

wallet::asset_lock is in the filter since the merge: the one caller of withdraw_durably is there.

The last one finishes with two dead-code warnings, in asset_lock/operation.rs and asset_lock/sync/tracking.rs, files this PR does not touch.

Not run: the full workspace suite, the platform-wallet-ffi and JNI test suites (those crates are not changed; clippy type-checks the FFI crate and its tests), a Swift or Kotlin build, anything against a live network.

Breaking Changes

None for consensus. For API users: PlatformWalletPersistence gains two methods with defaults, so no implementor has to change, and StoreAndCommitError is a new public type. The reporting changes are the three immediate-mode SQLite cases under Risks.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · cc61f1a

  • Bots — thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed
  • Build running
  • Approvals
    • wallet-storage (packages/rs-platform-wallet-storage/README.md, packages/rs-platform-wallet-storage/src/sqlite/persister.rs, packages/rs-platform-wallet-storage/tests/integration/main.rs and 2 more) — lklimek
    • rs-platform-wallet (packages/rs-platform-wallet/src/changeset/flush_ledger.rs, packages/rs-platform-wallet/src/changeset/mod.rs, packages/rs-platform-wallet/src/changeset/traits.rs and 3 more) — HashEngineering or ZocoLini or llbartekll or romchornyi

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

`WalletPersister::store_durably` stored a record and flushed it in two
backend calls, and worked out from the wallet's flush ledger whether the
flush had covered the store. Anything that drains the wallet's buffer can
run between the two calls, and a drain the wallet did not make (a commit
the host calls on the backend) is not in the ledger at all.

`PlatformWalletPersistence` gains `store_and_commit`, attested by
`offers_store_and_commit` (default `false`): stage a changeset behind what
is buffered for the wallet and commit that buffer as one step no other
drain can come between, with an answer for exactly what was staged.
`StoreAndCommitError` keeps the two failures apart: `NotStaged` (refused,
nothing buffered or written) and `NotCommitted` (buffered still after a
transient failure, dropped after any other).

`SqlitePersister` implements it in both flush modes with the one
connection guard an immediate-mode `store` already held across its merge
and its flush. `flush`, `commit_writes` and `delete_wallet` take the same
connection, so they are unchanged.

`WalletPersister::store_durably` uses the step where the backend offers
it and maps `NotStaged` to `NotDurable::Store` and `NotCommitted` to
`NotDurable::Flush`. The step is counted in the flush ledger as the flush
it contains, so `flush_durably` and the stored markers see its failures.
A backend that does not attest the step takes the code path it took
before, unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@QuantumExplorer QuantumExplorer added this to the v5.1.0 milestone Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4505fc5 and cc61f1a.

Files selected for processing: 11

  • packages/rs-platform-wallet-storage/README.md
  • packages/rs-platform-wallet-storage/src/sqlite/persister.rs
  • packages/rs-platform-wallet-storage/tests/integration/main.rs
  • packages/rs-platform-wallet-storage/tests/integration/sqlite_recovery_mode_write_block.rs
  • packages/rs-platform-wallet-storage/tests/integration/sqlite_store_and_commit.rs
  • packages/rs-platform-wallet/src/changeset/flush_ledger.rs
  • packages/rs-platform-wallet/src/changeset/mod.rs
  • packages/rs-platform-wallet/src/changeset/traits.rs
  • packages/rs-platform-wallet/src/error.rs
  • packages/rs-platform-wallet/src/wallet/persister.rs
  • packages/rs-platform-wallet/src/wallet/platform_wallet.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 17, 2026
@thepastaclaw

thepastaclaw commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress (commit cc61f1a) · live progress

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

The atomic SQLite operation and connection serialization are well structured, but three in-scope correctness issues remain. The ledger misclassifies fatal atomic commits on SQLite Immediate mode, poisoned connections can discard existing buffered state while reporting NotStaged, and several durability-critical wallet paths still use the old store-then-flush race. CI has no reported code failures; wallet tests and Kotlin checks are still pending.

🔴 3 blocking | 🟡 1 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: Route all pre-action durable records through the atomic persistence path
packages/rs-platform-wallet/src/wallet/identity/network/payments.rs:1566-1570

This payment-address reservation still calls store() and flush() separately, so it retains the Manual-mode race that this PR is intended to eliminate: another flush, host commit_writes(), or wallet drain can take and fatally drop the reservation between the two calls, after which this method's flush succeeds over an empty buffer and returns an address as if its reservation were durable. The same bypass exists in prepared_payment.rs:733-739, the funded invitation record at invitation.rs:214-220, both durable asset-lock record paths in asset_lock/build.rs:1482-1492 and 1507-1512, and the private-contact marker path in private_contact_requests.rs:700-706. These records gate broadcasts, dispatch, address exposure, or restart-sensitive recovery, so the wallet must use WalletPersister::store_durably() (and classify its NotDurable result) for each of these paths when the backend offers the atomic step.

self.persister
    .store_durably(changeset)
    .map_err(|error| self.persister.classify_not_durable(error))?;

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.1-sol (phase2-reviewer: general, architecture-layering, rust-quality, security-auditor)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a large and intricate Rust persistence and concurrency change affecting wallet durability guarantees, but it does not directly change consensus, funds movement, cryptography, key handling, network deserialization, or a storage migration.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-platform-wallet/src/changeset/flush_ledger.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/changeset/flush_ledger.rs:130-134: Atomic commits can drop buffered state without recording a loss
  `store_commits_inline()` describes ordinary `store()` behavior, but it does not describe whether `store_and_commit()` can drain and discard buffered state. SQLite advertises this flag as true in Immediate mode, while `stage_and_commit()` still merges into the shared buffer and `handle_flush_error()` restores that buffer on transient failures and drops it on fatal failures. If a prior store failed transiently and restored data, a later atomic commit can fatally fail and drop both changesets, but this code enters `InFlight` with `buffers = false`, so only `failed` is incremented and `lost` remains unchanged. Other handles can then trust `flush_durably()` or stored markers even though their buffered records were discarded. The ledger needs operation-specific buffer-loss semantics, such as a separate capability/outcome for `store_and_commit`, rather than reusing `store_commits_inline()`.

In `packages/rs-platform-wallet-storage/src/sqlite/persister.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1137-1141: Do not report NotStaged after discarding the existing buffer
  `stage_and_commit()` maps any failure from `self.conn()` to `StoreAndCommitError::NotStaged`, but `conn()` calls `self.buffer.discard_all()` when the connection mutex is poisoned before returning `LockPoisoned`. A wallet can therefore have unrelated pending changesets, receive `NotStaged`, and nevertheless lose those changesets. This violates the new `NotStaged` contract that the pre-existing buffer is unchanged and prevents `FlushLedger` from recording the loss. The operation must acquire the connection non-destructively for this path, or return an outcome that explicitly reports the buffer loss instead of mapping it to `NotStaged`.

In `packages/rs-platform-wallet/src/wallet/identity/network/payments.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/payments.rs:1566-1570: Route all pre-action durable records through the atomic persistence path
  This payment-address reservation still calls `store()` and `flush()` separately, so it retains the Manual-mode race that this PR is intended to eliminate: another flush, host `commit_writes()`, or wallet drain can take and fatally drop the reservation between the two calls, after which this method's flush succeeds over an empty buffer and returns an address as if its reservation were durable. The same bypass exists in `prepared_payment.rs:733-739`, the funded invitation record at `invitation.rs:214-220`, both durable asset-lock record paths in `asset_lock/build.rs:1482-1492` and `1507-1512`, and the private-contact marker path in `private_contact_requests.rs:700-706`. These records gate broadcasts, dispatch, address exposure, or restart-sensitive recovery, so the wallet must use `WalletPersister::store_durably()` (and classify its `NotDurable` result) for each of these paths when the backend offers the atomic step.

In `packages/rs-platform-wallet/src/changeset/traits.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/changeset/traits.rs:185-196: Preserve PersistenceError as the standard error source
  The new public `StoreAndCommitError` variants format their `PersistenceError` fields but do not mark them as sources. Consequently, callers using `std::error::Error::source()` cannot traverse to the typed persistence error or its backend cause, unlike the existing `PlatformWalletError::PersisterStore` and `PersisterFlush` variants. Mark both tuple fields with `#[source]` so the new API preserves the backend error chain.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 17, 2026
…count it

Three changes from review of the atomic store and commit.

A store committed in one step that fails for good is counted as lost in
the flush ledger on every backend. It was counted as lost only where
`store_commits_inline()` is false, but that attestation describes `store`:
SQLite in immediate mode keeps a changeset whose commit failed
transiently and commits it with the next one, so a step that fails for
good there can drop more than its own changeset.

`SqlitePersister` reports a poisoned lock inside the step as
`NotCommitted(LockPoisoned)` and no longer as `NotStaged`. Finding the
connection poisoned discards every buffered changeset, so the buffer is
not as it was, which `NotStaged` promises, and the ledger has to count
the loss.

Both `StoreAndCommitError` variants mark their `PersistenceError` as the
error's source, with a message of their own, as `PersisterStore` and
`PersisterFlush` do.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@QuantumExplorer

Copy link
Copy Markdown
Member Author

On the review finding that has no thread ("Route all pre-action durable records through the atomic persistence path"): not done in this PR, on purpose.

The call sites it names (reserve_payment_address, DashPayView::store_durably, the funded invitation record, the invitation funding index and the shielded recipient row) are on v5.1-dev as they were before this PR. Moving them onto WalletPersister::store_durably, with what each one has to do when the answer is not Ok, is the subject of #5923, which is open. Doing it here as well would duplicate that PR and conflict with it in every one of those files. Once both are in, those sites reach the atomic step through store_durably with no further change. The description now says this under "How this relates to #5923".

Two of the listed sites are left as they are by #5923 too: the drain row in asset_lock/build.rs, which is only admitted on a backend whose store is the commit, and the marker clear in private_contact_requests.rs, where a lost clear only keeps the identity held, which fails closed.

The other three findings are fixed in 2ae8617 and answered on their threads.

🤖 Addressed by Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 17, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

The atomic persistence path correctly separates staging and commit outcomes, but three current-head correctness issues remain. SQLite advertises the capability without coordinating drains across processes, poisoned-connection recovery drops buffers for every wallet while only notifying the active wallet's ledger, and transient NotStaged results are incorrectly narrowed to fatal store failures. The wallet test, Swift schema, and Kotlin checks were still in progress; no completed code check was failing in the supplied CI snapshot.

🔴 2 blocking

Follow-up candidates (optional) (1)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: Preserve retryability for transient NotStaged results
packages/rs-platform-wallet/src/wallet/persister.rs:835-837

Every StoreAndCommitError::NotStaged result is converted to NotDurable::Store and then passed through classify_store_failure, which narrows transient errors to fatal unless the backend separately attests store_transient_is_reissuable. That attestation describes ordinary store() reissuability, but a NotStaged atomic result guarantees that the incoming changeset never entered the buffer and nothing was written, so retrying it is inherently safe regardless of the ordinary-store policy. This unnecessarily turns a recoverable preflight or read failure from a backend offering the atomic operation into PersisterStore(Fatal). Preserve the transient classification for atomic-step NotStaged outcomes, or introduce a distinct classification path that bypasses the ordinary store reissue gate.

source: gpt-6.1-sol (phase2-reviewer: general)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a substantial cross-cutting Rust persistence and wallet-state change involving atomic storage semantics and concurrency, but it does not itself modify consensus, cryptography, key handling, funds movement, coin selection, or a storage migration.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Code unchanged since the last final review (988b62c7): 1 new suggestion(s) listed as follow-up candidates, not posted inline
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-platform-wallet-storage/src/sqlite/persister.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1487-1492: Do not attest atomic persistence without cross-process drain ordering
  SQLite returns `true` for `offers_store_and_commit`, but the ordering guarantee is enforced only by the instance-local `self.conn` mutex. The storage crate explicitly supports cross-process peers, and its open-path registry is process-local, so another process can hold an older changeset in its own buffer, take it from that buffer in `flush_inner`, and begin its transaction after this atomic step has committed. SQLite serializes the transactions but does not identify the stale in-memory changeset as stale; the later drain can therefore write older state over the state just attested by `store_and_commit`. The capability must either acquire a database-native ordering/generation guard before every participating drain removes its buffer, reject stale drains using a persistent generation check, or remain unattested until cross-process drain ordering is guaranteed.
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1144-1146: Record losses for every wallet when a poisoned connection clears the global buffer
  `stage_and_commit` maps a poisoned `conn()` result to `NotCommitted`, so the current wallet's `FlushLedger::store_and_commit` records a loss. However, `conn()` calls `self.buffer.discard_all()` when the connection mutex is poisoned, and that buffer contains pending changesets for every wallet handled by the persister. The other wallets' ledgers are not notified, even though their buffered records have been discarded; their durability checks and stored-marker decisions can consequently continue treating those records as present until another operation happens to update each ledger. The backend needs a backend-wide loss notification for all affected wallet IDs, or must avoid globally discarding other wallets' buffers on this path.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 17, 2026
…ryable

A changeset `store_and_commit` refused before it was staged was reported
like a plain store's failure: a transient one was narrowed to fatal unless
the backend attests `store_transient_is_reissuable`. That attestation
speaks for `store`. The step's `NotStaged` says by itself that nothing of
the changeset was staged or written, which is all a retry needs, so
`classify_not_durable` now keeps the backend's kind for it
(`PlatformWalletError::from_unstaged_store_failure`). A plain store's
transient failure on a backend without the step is narrowed as before.

Docs only, from the same review: the step's contract is about one backend
instance and its buffer, and orders nothing against another process that
has the same database open; and a poisoned connection's discard is every
wallet's, which the step reports for its own wallet while every later
operation of the others fails.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 17, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

The atomic persistence operation is otherwise correctly source-preserving and ledger-counted. One in-scope blocking durability issue remains: flush_durably returns before consulting the ledger for inline backends, so a failed atomic step can leave buffered or lost records while another handle is told they are durable. Rust workspace tests and Kotlin checks are still in progress, with no failed code check reported.

🔴 1 blocking

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: Do not bypass durability checks for inline backends that offer the atomic step
packages/rs-platform-wallet/src/wallet/persister.rs:895-897

flush_durably() returns Ok(()) whenever store_commits_inline() is true, before checking in_flight, failed, or lost. That flag describes ordinary store() behavior, but SQLite's atomic store_and_commit() can restore its changeset after a transient commit failure or drop buffered state after a fatal failure. During or after such a step, another handle's flush_durably() therefore skips the ledger and reports success even though the record is still buffered or was discarded. Keep the inline fast path only for backends that do not offer store_and_commit; atomic-capable inline backends must run the ledger-aware path.

if self.store_commits_inline() && !self.inner.offers_store_and_commit() {
    return Ok(());
}

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a large and intricate Rust persistence and concurrency change affecting wallet durability semantics, but it does not directly modify consensus, funds movement, cryptography, key handling, network deserialization, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-platform-wallet/src/wallet/persister.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/persister.rs:895-897: Do not bypass durability checks for inline backends that offer the atomic step
  `flush_durably()` returns `Ok(())` whenever `store_commits_inline()` is true, before checking `in_flight`, `failed`, or `lost`. That flag describes ordinary `store()` behavior, but SQLite's atomic `store_and_commit()` can restore its changeset after a transient commit failure or drop buffered state after a fatal failure. During or after such a step, another handle's `flush_durably()` therefore skips the ledger and reports success even though the record is still buffered or was discarded. Keep the inline fast path only for backends that do not offer `store_and_commit`; atomic-capable inline backends must run the ledger-aware path.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 17, 2026
…eft buffered

`flush_durably` answered `Ok` at once for every backend whose store is the
commit, on the reasoning that such a backend buffers nothing. A backend
that commits a store in one step keeps a changeset whose commit failed
transiently, by that step's contract, whatever its `store` does, and SQLite
in immediate mode is one. So a record reported as still buffered was
answered for as durable with no flush made, and so was one a later failure
had dropped.

`flush_durably` now answers at once only for a backend that keeps no
buffer (`keeps_a_buffer`: the store is the commit and the step is not
offered). Any other is flushed and its ledger read. `FlushLedger::flush`
counts a flush that fails for good as lost on a backend that keeps a
buffer, where it never did on one whose store is the commit.

The Swift and Kotlin hosts do not offer the step, so they are answered for
and counted as before.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@QuantumExplorer

Copy link
Copy Markdown
Member Author

On the blocking finding of the review of f35b208e (flush_durably returns before reading the ledger for a backend whose store is the commit, wallet/persister.rs:895-897): correct, fixed in 33aa670.

  • flush_durably now answers at once only for a backend that keeps no buffer: its store is the commit and it does not offer store_and_commit. SQLite, in either mode, is flushed and its ledger read. The condition is one predicate, keeps_a_buffer in flush_ledger.rs.
  • The same predicate now decides what FlushLedger::flush counts. Running the ledger path was not enough by itself: a flush of an inline backend that fails for good was counted as failed and never as lost, so after one dropped what a transient step had left buffered, flush_durably still found no loss and answered Ok over an empty buffer. It is counted as lost on a backend that keeps a buffer.
  • The Swift and Kotlin hosts do not offer the step, so they are answered for and counted as before.

Four tests, each shown to fail with its fix removed: should_flush_an_inline_backend_that_commits_in_one_step_before_calling_its_records_durable, should_report_the_loss_of_what_a_commit_in_one_step_left_buffered_on_an_inline_backend, should_not_answer_for_an_inline_backend_while_a_commit_in_one_step_is_in_progress (wallet::persister) and should_count_a_flush_that_fails_for_good_as_lost_on_an_inline_backend_that_commits_in_one_step (changeset::flush_ledger).

One limit stays, and the description states it: a drain the wallet does not make through its ledger is not counted. That is a host's commit_writes, and in immediate mode a plain store that fails for good over a buffer an earlier failure left. Only the backend can count those, which is #5923's buffered_writes_dropped; its losses_of takes the same predicate when the two meet.

🤖 Addressed by Claude Code

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 17, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

The exact head implements the atomic persistence path coherently across the wallet trait, flush ledger, wallet persister, and SQLite backend, and the previously identified defects are resolved or explicitly tracked. No new in-scope correctness, security, layering, or Rust-quality findings remain; the Rust workspace tests and PastaClaw review were still in progress in the supplied CI snapshot, with no failed code checks reported.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a large, intricate Rust storage and wallet-persistence change affecting durability guarantees and concurrent flush behavior, but it does not itself modify consensus, cryptography, key handling, funds movement, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 17, 2026
#5923 merged into v5.1-dev and edits the functions this branch edits.
The conflicts were in `store_durably`, in the docs of `flush_durably`,
`classify_not_durable`, `NotDurable::Flush` and the flush ledger, and in
the persistence trait, where both sides add methods.

Resolved by keeping both: a backend that offers the atomic step is asked
for it first, and any other backend runs #5923's code unchanged.

Beyond the resolution, so that the two meet:

- `withdraw_durably`, which #5923 added, takes the step too where it is
  offered. That nothing writes the record after its withdrawal is the
  step's contract there.
- `losses_of` reads the backend's `buffered_writes_dropped` for every
  backend that keeps a buffer (`keeps_a_buffer`), where #5923 left it out
  for one whose store is the commit. SQLite in immediate mode is such a
  backend and still holds a changeset whose commit failed transiently, so
  a plain store that fails for good there drops it, which only the
  backend counts.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 17, 2026
@QuantumExplorer
QuantumExplorer merged commit 18e26d9 into v5.1-dev Nov 17, 2026
25 of 27 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/platform-wallet-store-and-commit branch November 17, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Client Only waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants