Skip to content

fix(cli,client): refuse to replace a file no record vouches for in a default destination - #2476

Merged
thiras merged 3 commits into
mainfrom
fix/get-foreign-source-refusal
Oct 16, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/get-foreign-source-refusal

Conversation

@thiras

@thiras thiras commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Without -o, decdn get decdn:<h>/text_encoder/config.json lands at ./config.json, and the skip-cache recorded that file only under its landing name. A later decdn get decdn:<h>/tokenizer/config.json found a recorded file, passed the #2466 default-destination check, and fetched over it. Two bundles pulled into . with a same-named file hit the same bug.

Each .decdn-manifest.json record now names its source: the manifest hash and the entry's manifest path. A pull without -o refuses a path unless a record vouches for it. A record vouches for a path when the file still has the recorded size and mtime, and the record names the same entry or holds the same bytes. The error says why it refuses:

  • no decdn get wrote the file;
  • it changed after a decdn get wrote it from <uri>;
  • a decdn get wrote it from another entry, <uri>;
  • the skip-cache cannot be used, with the cause (e.g. has version 1; this build reads version 2).

-o (including -o .) and --overwrite still let the pull replace the file. Without -o, a new version of a bundle that changes a file is refused; -o . updates it in place, replacing the changed files and skipping the rest.

Closes #2472

Reviewer notes

  • Read first: foreign_paths / ForeignReason in crates/client/src/bundle.rs, and SavedSource / load_checked in crates/client/src/bundle/skip_cache.rs.
  • BundleManifest keeps its blob hash, which parse takes from the bytes, and new now takes the hash. ManifestEntry::land_at moves an entry to its landing name and keeps the manifest path. The engine passes the hash as [u8; 32] down to record_one.
  • plan_slots and foreign_paths share one writable_dest check, so a path the pull keeps its own state in fails that one entry instead of refusing the whole run.
  • Breaking, pre-mainnet with no migration: the skip-cache schema is now version 2. In a directory an older build pulled into, the first pull without -o refuses the existing files and names the version mismatch. -o . once clears it.
  • decdn-client public API: foreign_paths / ForeignPath / ForeignReason replace unrecorded_paths, plus BundleManifest::hash, ManifestEntry::land_at and manifest_path. The snapshot is regenerated.
  • Left for a follow-up:
    • make ManifestEntry::path private (misusing it today only causes a refusal);
    • limit BundleManifest::new to tests;
    • the source URI in the error drops ?ns=.

Verification

  • cargo fmt -- --check (pre-commit)
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: exit 0
  • cargo nextest run: not the whole workspace. I ran -p decdn-client -p decdn-cli -p decdn-common (2213 passed) and the anvil e2e bundle binaries -p decdn-e2e --features anvil-e2e -E 'binary(/bundle/)' (10 passed, after cargo build --bin decdn-node --bin decdn).
  • cargo nextest run -p decdn-client --features public-api-test --test public_api: passed
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items: exit 0
  • The new e2e source assertion fails when record_one records a wrong bundle hash (checked by mutating it, then reverting).
  • User-visible change: the CHANGELOG.md feat(cli): make decdn get -o optional with per-target defaults #2466 entry is amended in place (all entries are Unreleased).
  • Design change: adr/appendix-bundles.md § Output directory updated.

🤖 Generated with Claude Code

thiras and others added 2 commits October 16, 2026 13:54
… destination

Without -o, an entry URI lands at ./<name>, and the skip-cache recorded
that file under its flattened name only. A second entry with the same
name (decdn:<h>/tokenizer/config.json after decdn:<h>/text_encoder/
config.json), or a second bundle pulled into . with a same-named file,
found a recorded file, passed the default-destination check, and
fetched over it.

Each skip-cache record now names its source: the manifest hash and the
entry's manifest path. BundleManifest keeps its blob hash (parse takes
it from the bytes), and ManifestEntry::land_at moves an entry to its
landing name while it keeps the manifest path. A pull without -o
refuses a path whose record names another source, and the error names
that source as a decdn: URI. -o and --overwrite still pass. The
skip-cache schema is version 2; a version 1 file reads as empty.

decdn_client::bundle::foreign_paths replaces unrecorded_paths.

Closes #2472

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… wrongly replace

Review fixes to the #2472 refusal. A skip-cache record now vouches for a
path only when the file still has the recorded size and mtime, and the
record names the same entry or holds the same bytes. So:

- a new version of a bundle pulled into . replaces only the files it
  changes, and two entries with identical bytes no longer refuse each
  other;
- a file the user edited after a pull wrote it is refused ("it changed
  after an earlier `decdn get` wrote it from <uri>"), where the pull
  replaced it before;
- a skip-cache that is there but cannot be used (another version,
  corrupt, unreadable) is refused naming the cause, instead of claiming
  no `decdn get` wrote the files;
- a path the pull reserves for its own state is left to the engine,
  which fails that one entry; plan_slots and foreign_paths share one
  writable_dest predicate.

ForeignPath carries a ForeignReason in place of written_from. The
engine threads the manifest hash as [u8; 32] and SavedSource::new
builds the record's source. Stale docs that named only the unrecorded
rule, or called the skip-cache key bundle-relative, are fixed. The
range-dedup e2e checks each record's source, and the unit tests cover
every reason, land_at twice, and the dry run against another source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 11:31
@thiras thiras self-assigned this Oct 16, 2026

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.

🟢 Approval recommended

Only a non-blocking documentation clarification remains; no functional blockers were identified.

1 open finding
What changed in this PR

Protects default decdn get destinations from replacing files written by another bundle entry or modified locally.

Changes:

  • Records source manifests and entry paths in skip-cache version 2.
  • Adds source-aware refusal checks and explanatory errors.
  • Updates tests, public API snapshots, and documentation.
File Description
README.md Describes default-destination protection.
crates/​e2e/​tests/​cli_bundle_pull_range_dedup.rs Checks recorded source identity.
crates/​common/​src/​cli/​get.rs Updates CLI help.
crates/​client/​tests/​snapshots/​public_api__public_api.snap Captures API changes.
crates/​client/​src/​bundle/​skip_cache/​tests.rs Tests source records and schema errors.
crates/​client/​src/​bundle/​skip_cache.rs Adds source tracking and checked loading.
crates/​client/​src/​bundle/​engine/​tests.rs Tests refusal and source preservation.
crates/​client/​src/​bundle/​engine.rs Records sources and shares destination validation.
crates/​client/​src/​bundle.rs Adds source-aware foreign-path checks.
crates/​cli/​src/​commands/​get.rs Updates command documentation.
crates/​cli/​src/​commands/​gateway/​tests.rs Adapts manifest construction.
crates/​cli/​src/​commands/​bundle_pull/​tests.rs Tests refusal behavior and diagnostics.
crates/​cli/​src/​commands/​bundle_pull.rs Integrates checks into live and dry runs.
CHANGELOG.md Documents protection and schema changes.
adr/​appendix-bundles.md Defines source-aware replacement rules.

🧠 Review effort: Balanced


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

Comment thread README.md Resolved
Without -o, a new version of a bundle that changes a file is refused:
the changed file matches neither its record's manifest hash nor its
file hash. The README and CHANGELOG said such a pull replaces only the
changed files, which holds only with -o .. They now say -o . updates a
bundle in place and --overwrite fetches every file again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 75d8b1a fix/get-foreign-sour... 95944fd +/-
75% 75% 0%
View coverage of the 8 most impacted files.
File main 75d8b1a fix/get-foreign-sour... 95944fd +/-
crates/node/src/dht/publish.rs 80% 78% -2%
crates/client/src/lib.rs 89% 88% -1%
crates/client/s...e/skip_cache.rs 100% 99% -1%
crates/client/s...undle/engine.rs 61% 61% 0%
crates/cli/src/.../bundle_pull.rs 55% 55% 0%
crates/node/src...gin/pull_leg.rs 85% 85% 0%
crates/node/src...s/client/mod.rs 89% 90% +1%
crates/client/src/bundle.rs 22% 28% +6%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@thiras
thiras merged commit 4675390 into main Oct 16, 2026
31 checks passed
@thiras
thiras deleted the fix/get-foreign-source-refusal branch October 16, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: flattened entry pulls without -o replace each other on a shared file name

2 participants