Repository navigation
fix(incentive): graceful failure on concurrent buyer-store open (#942) - #946
Conversation
A second `decdn fetch`/`bundle pull` against the same `--data-dir` trips redb's
process-exclusive write lock. `RedbBuyerChannelStore::open` mapped that to a raw
`StoreError::Backend("...DatabaseAlreadyOpen...")` string. Add a dedicated
`StoreError::AlreadyOpen { path }` and map redb's `DatabaseError::DatabaseAlreadyOpen`
to it, so the second process fails fast with a clear, actionable message
("another decdn process is using the channel store at <path> — run one
fetch/pull at a time per --data-dir, or give each invocation a separate
--data-dir") instead of a backend dump.
This is the deliberate, safe outcome: two processes must never share one
channel's serial voucher nonce. Truly-concurrent cross-process shared-channel
fetch stays out of scope — the supported answer is one process that multiplexes
internally (the puller-daemon direction in #944). #942 closes as superseded by
that design; this just makes the meantime failure graceful.
- store: new `StoreError::AlreadyOpen` variant.
- node buyer reconcile: its exhaustive (no catch-all) StoreError match gains the
variant in the "store unavailable, skip — don't clobber" arm (it can't arise
from that read path, but classifies cleanly).
- test: second concurrent open returns `AlreadyOpen` with the user-facing
message, and recovers after the first handle drops.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR improves client-side (buyer) channel-store ergonomics and safety by converting redb’s “database already open” condition into a dedicated, user-facing StoreError::AlreadyOpen { path }, preventing confusing backend dumps and ensuring concurrent use of the same --data-dir fails fast and clearly.
Changes:
- Add
StoreError::AlreadyOpen { path }with an actionable error message for cross-process store-lock collisions. - Map
redb::DatabaseError::DatabaseAlreadyOpentoStoreError::AlreadyOpeninRedbBuyerChannelStore::open. - Extend node-side buyer-channel reconcile matching to include the new
AlreadyOpenvariant and add a regression test covering the new error behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/node/src/buyer_channel.rs |
Updates the explicit StoreError match to include AlreadyOpen in the “store unavailable → skip” arm. |
crates/incentive/src/store.rs |
Introduces StoreError::AlreadyOpen { path } with a dedicated, user-facing error message. |
crates/incentive/src/buyer_channel_redb.rs |
Maps redb’s DatabaseAlreadyOpen to StoreError::AlreadyOpen and adds a unit test verifying the dedicated error and recovery after dropping the first handle. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 84.22% (was 84.21%, ▲ +0.01%) — 38434/45635 lines
History
|
There was a problem hiding this comment.
Code Review
This pull request introduces a dedicated StoreError::AlreadyOpen error variant to handle cases where a second concurrent process attempts to open the channel store database, replacing raw backend error strings with a user-friendly message. It also updates the reconciliation logic to skip this error and adds a corresponding unit test. The review feedback highlights a compilation issue where the closure mapping the error needs the move keyword to take ownership of path, and suggests enhancing the unit test to verify the path field in the asserted error.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Strengthen the concurrent-open assertion to also verify the StoreError::AlreadyOpen path field matches the buyer-channels db file, per PR #946 review. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closes #942 as superseded — the truly-concurrent shared-channel case is out of scope (it needs the single-owner puller daemon from the #944 design comment). This PR is the minimal meantime fix: make the collision fail gracefully instead of corrupting a shared voucher nonce.
Problem
Two
decdn fetch/bundle pullprocesses on the same--data-dircan't safely share one payment channel — itsnonce/bytes/amountledger is serial and channel-wide. redb already prevents the dangerous case via a process-exclusive write lock on the buyer-channel DB, butRedbBuyerChannelStore::openreported it as a raw backend string:Fix
StoreError::AlreadyOpen { path }.open()maps redb'sDatabaseError::DatabaseAlreadyOpento it, so the second opener fails fast with an actionable message:StoreErrorexhaustively (no catch-all, by design); the new variant joins the "store unavailable → skip, don't clobber" arm (it can't actually arise from that read path).This is the safe outcome the issue's "Cross-process concurrency" section calls for: SAFE (no nonce corruption), blunt (whole-process granularity, fail-not-queue). Internal multiplexing within one process (e.g.
bundle pull --jobs) is unaffected and already nonce-safe via the per-provider lock from #391.Test
second_concurrent_open_is_already_open_not_raw_backend: a second open on the same data dir returnsAlreadyOpenwith the user-facing message (not a redb dump) and recovers once the first handle drops.Verification
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo doc,cargo deny,cargo nextest run --workspace(1872 passed) all green.🤖 Generated with Claude Code