Skip to content

fix(cli): batch of five CLI fixes around the node-vs-client data dir - #2085

Merged
thiras merged 10 commits into
mainfrom
fix/batch-cli-issues
Sep 21, 2026
Merged

thiras merged 10 commits into
mainfrom
fix/batch-cli-issues

Conversation

@thiras

@thiras thiras commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Five CLI issues, all downstream of #2078/#2081's node-vs-client data-dir rule. One commit per issue.

decdn fetch / bundle pull escrow into a node's dir under the node's own keystore — #2082 (BREAKING)

decdn pool refuses this; these two did not, and they are the worse case: the keystore defaults to the same dir, so the client pool opened under the node's own operator address. The daemon then reports that deposit as stranded, and on a store reset its adoption path can take the pool over — two independent watermarks on one lane.

A human buying on a node host is a legitimately separate client, so the rule is weaker than pool's: an explicit --data-dir naming the node's dir is accepted, an implicit one (identity.data_dir from ~/.decdn/node.toml) is not. The refusal runs before the keystore prompt.

The classifier moves out of pool.rs into commands::buyer_store, and the guard and the store open are fused — open_client_store_for_escrow / open_client_store_for_buy return the store, so a future subcommand cannot reach one without passing the check. ADR 012 records the asymmetry, which was previously an omission.

No way to read a stopped node's buyer.redb — #2084

redb holds its lock only while a Database is open, so a stopped daemon's store is readable — and the lock is also what tells the cases apart. On a refused admin connection, pool list now tries a read-only open of the daemon's own buyer.redb:

outcome behaviour
opens render it; store=… (read from disk; no daemon running), source=node_store_offline
AlreadyOpen a daemon is running — say the admin URL is wrong, not "start decdn-node"
anything else previous error, plus what the disk read found

New ReadOnlyBuyerPoolStore takes a file path, never creates, and maps redb's RepairAborted to StoreError::NeedsRepair — a crashed daemon's store is exactly the file that needs a repair pass a reader cannot run. Read-only and read-write loads share one decode-and-skip implementation.

Clearing a stopped daemon's row from close/reclaim is deliberately out of scope: it needs the write lock this type does not take.

pool list cannot show a pool the store has lost — #2077

--all enumerates getPools by the keystore address: every pool, every lifecycle state, on-chain deposit, total redeemed, reclaim window, and whether the local record tracks it. TRACKED distinguishes no from ? — an unreadable store leaves it unknown rather than claiming every pool is untracked. Not refused on a node data dir: the sweep refusal covers the two commands that write.

PoolListArgs now flattens PoolChainArgs as close/reclaim do. --data-dir unchanged.

doctor keeps a drifted copy of the store-file list — #2083

floor-loss.redb was created by nothing. The list now comes from DAEMON_STORE_FILES + CLIENT_BUYER_DB_FILE. A new channel_store test asserts the daemon creates every file in that set and nothing outside it — the premise daemon_marker, and with it #2078's classification, rests on.

whoami aborts when the two keystores have different passwords — #2008

One Mac Mismatch killed the whole command, printing nothing — not even the address of the keystore whose password was right. The shared password is still tried first; a keystore it does not open degrades its own line to a note, and on a TTY gets one prompt of its own first. Exit 0.

eth address: 0x240D80d7…
client eth address: (keystore at …/client/keystore.json did not open with this password: Mac Mismatch)

Verification

  • cargo nextest run --workspace — 3678 passed
  • cargo clippy --workspace --all-targets --all-features -- -D warnings, plus both decdn-incentive --no-default-features configurations
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
  • pre-commit run --all-files
  • cargo nextest run -p decdn-e2e --features anvil-e2e cli_pool_list_all — new journey: open a real pool, delete the client store, pool list reports nothing while --all still names the pool and marks it untracked
  • By hand against the built binary: doctor --offline --json (no floor-loss finding) and the two-password whoami repro above

No contract changes, so no gas snapshot. No decdn-protocol surface change, so no public-API snapshot.

Closes #2084. Closes #2083. Closes #2082. Closes #2077. Closes #2008.

🤖 Generated with Claude Code

thiras and others added 8 commits September 21, 2026 02:00
`decdn doctor` kept its own copy of the names of the store files a daemon
owns, and that copy had drifted: it listed `floor-loss.redb`, which nothing
creates. The list drives doctor's permission and zero-length checks, so a
fifth daemon store would have been checked by nothing.

The iteration now comes from `decdn_common::data_dir::DAEMON_STORE_FILES`
plus `CLIENT_BUYER_DB_FILE`, the same names `channel_store.rs` and
`buyer_pool_redb.rs` already use. A new `channel_store` test opens a
`PersistentPoolStateStore` in a temp dir and asserts every
`DAEMON_STORE_FILES` entry exists afterwards and that no `.redb` file
outside the set was created — the claim `daemon_marker` rests on, and with
it the node-vs-client classification from #2078.

Two stale docs go with it: `buyer_pool_table`'s module doc named a
floor-loss family and the wrong module for `PersistentPoolStateStore`, and
the node's buyer-table adapter said it viewed `lanes.redb`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…pen (#2008)

`decdn whoami` resolved one password and applied it to both the node and
the client keystore. `key-gen` writes those two at different times and
prompts for each, so they can hold different passwords — and when they did,
the first `Mac Mismatch` aborted the command. Nothing printed: not the node
id, not the paths, not the address of the keystore whose password was
correct.

The shared password stays the common case and is still tried first. A
keystore it does not open now degrades its own line to a note naming the
keystore and the reason, and on a TTY that keystore gets one prompt of its
own before the note. Every other line still prints and the command exits 0,
which is what the module doc already promised for the node id and the paths.

`eth_address_line` returns the line plus a retry flag instead of a
`Result`, so the decrypt failure is a value the caller can act on rather
than an abort, and the retry decision stays testable without a TTY.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`decdn pool` refuses to escrow into a `decdn-node` daemon's data dir
(#2078). `decdn fetch` and `decdn bundle pull` opened the client store on
the same resolved `data_dir` with no such check — and the keystore defaults
to that dir too, so on a node host they opened a client pool under the
node's OWN operator address. The daemon then reports that deposit as
stranded and tells the operator to close a pool a human may be fetching
against, and after a store reset its adoption path can take the pool over,
putting two independent watermarks on one lane.

A human buying on a node host is a legitimately separate client, so the
rule is weaker than `pool`'s: an explicit `--data-dir` naming the node's dir
is accepted, and an implicit one is not. `identity.data_dir` from
`~/.decdn/node.toml` is the implicit case, so `ResolvedChain` now carries
which step of the ladder produced the dir, not just the path.

The classifier moves out of `pool.rs` into `commands::buyer_store`, where
`fetch` and `bundle pull` can reach it, and the guard and the store open
are fused: `open_client_store_for_escrow` and `open_client_store_for_buy`
return the store, so a future subcommand cannot reach one without passing
the check.

ADR 012 records the asymmetry beside the store-split paragraph — it was an
omission there, not a decision.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#2081 routed `decdn pool list` on a node data dir through `admin_v1_pools`
and deliberately did not fall back to the client store, because falling back
to a different file with unrelated contents is the defect #2078 was about.
The consequence was that a stopped node's `buyer.redb` became readable by
nothing: a post-mortem after a crash, or a look at a host that is down for
maintenance, had no route.

redb holds its process-exclusive lock only for the lifetime of an open
`Database`, so the impossibility is specific to a running daemon — and the
lock is also what tells the two cases apart. On a refused admin connection,
`pool list` now tries `ReadOnlyBuyerPoolStore::open_file` against the
daemon's own `buyer.redb`:

- it opens, so no daemon holds it: render it, labelled `store=… (read from
  disk; no daemon running)` and `source=node_store_offline` under `--json`,
  its own value rather than the client store's;
- it is write-locked, so a daemon IS running: the admin URL or admin_port is
  wrong, which is a better answer than "start decdn-node";
- anything else: the previous error, plus what the disk read found.

`ReadOnlyBuyerPoolStore` takes a file path rather than a data dir, and never
creates — `open_read_only` cannot, which is what keeps #2078 closed. A
`DatabaseError::RepairAborted` gets its own `StoreError::NeedsRepair`,
because a crashed daemon's store is exactly the file that needs redb's
repair pass and a read-only open cannot run one.

Read-only and read-write loads share one decode-and-skip implementation:
`load_all_from` is generic over `redb::ReadableDatabase`, so the skip
semantics cannot fork between them.

Clearing a stopped daemon's row from `pool close` / `reclaim` is a separate
decision and is not included: it needs the write lock this type deliberately
does not take.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
)

`decdn pool list` read only the local buyer store, so it could not show a
pool whose store row was gone — which is exactly the situation an operator
runs it in. A reset `identity.data_dir` loses the only local record of a
funded `PaymentPool` deposit; the operator's first instinct is `pool list`,
and it printed nothing, because the store is the thing that was lost.

`--all` enumerates `getPools` by the keystore address and shows every pool
in every lifecycle state with its on-chain deposit, total redeemed, and
reclaim window, marking which ones the local record tracks. `close --all`
and `reclaim --all` already worked this way; `list` was the odd one out.

The `TRACKED` column distinguishes `no` from `?`: a store that could not be
read at all leaves it unknown rather than claiming every pool is untracked,
since an unreadable store is the case the flag exists for. `--all` is NOT
refused on a node's data dir — the sweep refusal covers the two commands
that write, and a node host is where this view is most needed.

`PoolListArgs` now flattens `PoolChainArgs`, as `close` and `reclaim` do, so
every `pool` subcommand shares one precedence path. `--data-dir` is
unchanged; the chain flags are new and only `--all` reads them.

The runbook section that had to be written around this gap now uses it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…#2077)

The unit tests cover the renderers; nothing covered the chain read. This
journey opens a real pool on anvil, deletes the client store — the reset a
moved volume performs — and shows that `pool list` then reports nothing
while `pool list --all` still names the pool, its escrowed deposit, and
`tracked=false`. That sequence is the issue, not a listing shape.

No node is involved: a chain read and a store read, nothing paid.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The note carried the full error chain, whose outer layer already repeats the
keystore path the note names. The innermost message is the useful part and
is what separates a wrong password from a broken file: the line now reads
`… did not open with this password: Mac Mismatch`, which is the string the
issue's repro produced as a fatal error.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Two moderate unresolved findings remain in pool listing behavior.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR fixes five CLI issues around node/client data directories, offline pool inspection, store detection, and keystore password handling.

Changes:

  • Guards escrow operations from implicit node directories.
  • Adds offline buyer.redb reads and chain-authoritative pool list --all.
  • Centralizes store-file detection and improves whoami resilience.

Two moderate findings remain in crates/cli/src/commands/pool.rs: undecodable records must remain unknown, and offline read failures must preserve connection-refusal context.

File Summary
docs/​runbook.md Documents offline and chain-authoritative pool diagnostics.
crates/​node/​src/​channel_store.rs Updates store documentation and file-set coverage.
crates/​incentive/​src/​store.rs Adds repair-needed store error handling.
crates/​incentive/​src/​buyer_pool_table.rs Shares read-only and read-write loading logic.
crates/​incentive/​src/​buyer_pool_redb.rs Adds read-only buyer-store support.
crates/​e2e/​tests/​cli_pool_list_all.rs Adds chain-listing end-to-end coverage.
crates/​common/​src/​cli/​pool.rs Adds pool list --all arguments and documentation.
crates/​cli/​tests/​pool_list.rs Tests offline and locked-store behavior.
crates/​cli/​tests/​fetch_node_dir_guard.rs Tests fetch and bundle directory guards.
crates/​cli/​src/​commands/​whoami.rs Handles differing keystore passwords.
crates/​cli/​src/​commands/​pool.rs Implements offline and chain-authoritative listings; findings remain.
crates/​cli/​src/​commands/​node.rs Exposes connection-refused classification.
crates/​cli/​src/​commands/​mod.rs Registers buyer-store helpers.
crates/​cli/​src/​commands/​fetch.rs Applies the buyer-store guard.
crates/​cli/​src/​commands/​doctor/​state.rs Uses shared store-file definitions.
crates/​cli/​src/​commands/​buyer_store.rs Centralizes buyer-store classification and opening.
crates/​cli/​src/​commands/​bundle_pull.rs Applies the buyer-store guard.
CHANGELOG.md Records the CLI fixes.
adr/​012-client.md Documents node/client data-directory asymmetry.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cli/src/commands/pool.rs Resolved
…-all (#2077)

`tracked_pool_ids` built its set from `BuyerLoad.pools` and dropped
`BuyerLoad.skipped`, so a pool whose local row exists but will not decode
rendered as `TRACKED=no` / `tracked: false`. That is a false claim with a
wrong remedy attached: `no` sends the operator to `pool close` to recover a
stranded deposit, when the store does hold a row for that pool and what it
needs is the record repaired. `pool_id` is the table's primary key, so it
survives whatever corrupted the value bytes — the id is always known.

`daemon_pool_ids` dropped `BuyerPoolsResponse.skipped` the same way. That
field crosses the admin wire precisely because the daemon cannot decode
those rows either.

`TrackedPools` now carries both sets and `verdict` answers per pool:
`Some(true)` decoded, `None` for a row that will not decode, `Some(false)`
for no row at all. `None` for the whole store still means it could not be
read, which `local_store_read` distinguishes in `--json`. The verdict is
per-pool on purpose — one bad row must not blank the column for the pools
either side of it.

`--all` also names the undecodable ids on stderr now, so it is no longer the
one listing that stays silent about a deposit stranded by an unreadable
record.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.36% (was 83.30%, ▲ +0.06%) — 84075/100861 lines

File Coverage Lines Δ
crates/cli/src/commands/bundle_pull.rs 67.58% 2099/3106 ▲ +0.42%
crates/cli/src/commands/buyer_store.rs 98.35% 179/182 new
crates/cli/src/commands/doctor/state.rs 95.58% 433/453 ▲ +0.15%
crates/cli/src/commands/fetch.rs 44.71% 1085/2427 ▲ +2.07%
crates/cli/src/commands/node.rs 77.20% 1131/1465 ● 0.00%
crates/cli/src/commands/pool.rs 66.41% 961/1447 ▼ 3.24%
crates/cli/src/commands/whoami.rs 91.64% 296/323 ▼ 0.03%
crates/incentive/src/buyer_pool_redb.rs 91.13% 226/248 ▼ 3.12%
crates/incentive/src/buyer_pool_table.rs 90.20% 819/908 ▲ +0.02%
crates/incentive/src/store.rs 84.10% 164/195 ● 0.00%
crates/node/src/admin.rs 92.25% 1142/1238 ▲ +0.11%
crates/node/src/channel_store.rs 87.60% 1102/1258 ▲ +0.80%
History
Commit Total Δ vs base
ac66052 83.37% ▲ +0.07%
f814f4f (HEAD) 83.36% ▲ +0.06%

**`pool list --all` was neither read-only nor loud.** Its TRACKED lookup
opened the client store with `RedbBuyerPoolStore::open`, which creates —
so the command documented as writing nothing manufactured the very store
it reports on, and a lost store (the condition the flag exists to surface)
became indistinguishable from one tracking nothing. Every local read on
that path now goes through `ReadOnlyBuyerPoolStore`, and an absent store is
an answer (nothing tracked), not an unknown.

Five failures were swallowed by `.ok()` behind a single `?` glyph: a
zero-length store whose own error says "restore from backup", a store
another `decdn fetch` holds, a crashed daemon's unrepaired file, a
malformed `--admin-url`, and `--timeout-ms 0`. Each now names itself on
stderr. On a node dir only `AlreadyOpen` routes to the admin RPC — that is
the one failure meaning "a daemon holds this file"; the rest are about the
file and are reported as such.

`write_chain_pools` gained `local_store=read|unreadable`. Without it the
table showed a column of `?` with no way to tell "no local answer at all"
from "these rows will not decode" — a distinction only `--json` carried,
for remedies that are opposites.

**The `AlreadyOpen` message shipped garbled.** Two missing line
continuations baked 14-space runs into the operator-facing string for the
PR's headline new diagnosis. `cargo fmt` does not touch string literals and
the test grepped for `"admin URL"`, which the pre-fix message also
contains — so the assertion now pins the claim that actually distinguishes
them.

**`StoreError` stopped prescribing a caller's remedy.** `NeedsRepair` named
`decdn-node` in a shared error type reachable from a client store; it now
states the condition and the call site names the process. New `Absent`
variant: a data dir whose store was deleted to force re-adoption is a
routine state, not an errno.

**`TrackedPools` is a map.** Two sets left disjointness to prose, and
`from_wire` dropped ids `PoolId::from_str` rejected — silently rendering a
pool the daemon is paying from as `no`, which reads as a deposit to
recover. One unparseable id now makes the whole answer unknown.
`decdn-node` pins the other half of the drift guard where the spelling is
produced.

**`BuyerStoreOwner::Client` carries its dir**, so `open_for_write` takes no
path: a verdict about one directory can no longer authorize a store in
another.

**`whoami` prints the reason before prompting.** The report is buffered, so
the retry prompt appeared with no context — and for a failure no password
can fix (a `0o644` keystore) it pointed at the password instead of the
mode. A prompt that cannot be read is annotated rather than reusing the
first attempt's note, which after a prompt reads as the password just
typed. The unused `Clone` on the secret-bearing `KeystorePassword` is gone.

**Stale docs.** Three more `lanes.redb` claims in `channel_store.rs` — one
asserting both tables share a file, which is false. Six changelog-voice
docstrings. A test docstring that had detached onto a helper, leaving its
test undocumented and asserting behavior this batch reversed. A dead match
arm. `PoolCommand::List` promised a `store=` line `--all` does not emit and
named one of four `source` values.

**Tests:** the `--all` sweep refusal must not reach `list` (nothing pinned
it); `local_store=unreadable` end to end; the wire round-trip on both
sides; a re-delete in the anvil journey so its no-creation assertion is
about `--all` rather than the plain listing that legitimately re-creates.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@thiras
thiras merged commit 730db36 into main Sep 21, 2026
25 checks passed
@thiras
thiras deleted the fix/batch-cli-issues branch September 21, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants