Skip to content

feat(cli,bao-range): decdn origin import — seed a cache origin (sharded blob + .obao4) (#1904) - #1905

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/issue-1904-pr-4ac8ed
Sep 2, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/issue-1904-pr-4ac8ed

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

What

Adds decdn origin import — an offline, config-free command that seeds a cache
origin store with local content, writing each blob's sharded data object
{base}/{hex[0..2]}/{hex} and its sibling pre-order bao outboard
{hex}.obao4 in the exact layout the daemon reads (ADR 037 §Origin-tier
pull-through).

decdn origin import -i <path> --to fs:<dir> [--move] [--bundle <out.json>] [--force] [--follow-symlinks] [--exclude <glob>]... [--json]

Closes #1904.

Why

Operators running a serving node with a filesystem pull-through origin had no
supported way to populate it
. The data object is a plain cp, but the
.obao4 must be a bao-tree pre-order outboard at IROH_BLOCK_SIZE (16 KiB
chunk groups) — a stock bao encode --outboard uses a different chunk group
size and produces a file the daemon rejects. The only reference implementation
was a #[cfg(test)] helper.

Behavior

  • Single file: streams once to compute the BLAKE3 root + outboard, writes
    the data object and .obao4 atomically (temp + rename into the shard).
    --move renames the source (copy+unlink across filesystems). Idempotent on a
    content-addressed path; a size mismatch is refused unless --force.
  • Directory: walks with bundle create's exact containment /
    --follow-symlinks / --exclude rules, imports every file, emits the
    canonical bundle manifest (byte-identical to bundle create), and imports
    the manifest blob itself so the whole tree is retrievable by one bundle hash.
  • --json status line mirroring bundle create.

Design

  • Backend-agnostic prep, pluggable writer. Hash + outboard + object naming
    are identical across the fs and s3 backends; only the final write differs. The
    --to <target> parser selects the writer. fs:<dir> is implemented; s3://
    is an additive follow-up (the parser already rejects s3:// and http(s)://
    with actionable errors).
  • Shared, iroh-blobs-free layout contract. The outboard encoder
    (encode_outboard) and the .obao4 layout (OBAO4_SUFFIX, shard prefix) now
    live in the bao-range leaf crate, consumed by both the cache reader
    (origin::fs / origin::s3) and the new writer — so a blob written here is
    one the daemon reads back verbatim. The CLI stays free of iroh-blobs / the AWS
    SDK (CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK) #578); verified with cargo tree -p decdn-cli -e normal -i iroh-blobs.
  • The bundle create walk + canonical serializer were extracted into a shared
    commands::manifest module so both commands emit identical manifest bytes by
    construction rather than by two copies staying in sync.

Testing

  • New crates/cli/tests/origin_import.rs proves the written outboard is
    daemon-compatible by range-serving through the real decdn-cache
    FilesystemOrigin
    (whole-blob fetch + a chunk-group-aligned verified range),
    plus idempotent re-import, --move source consumption, and directory import
    matching bundle create byte-for-byte with the manifest blob present.
  • bao-range unit test pins encode_outboard byte-identical to the in-memory
    PreOrderMemOutboard::create the cache seeds with.
  • Full local gate green: cargo build, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo nextest run (871 tests), cargo fmt --check, doc gate, cargo deny.

🤖 Generated with Claude Code

…#1904)

Operators running a serving node with a filesystem pull-through origin had
no supported way to populate it: the sharded data object is a plain `cp`,
but the sibling `{hex}.obao4` outboard must be a `bao-tree` pre-order
outboard at `IROH_BLOCK_SIZE` (16 KiB chunk groups) — a stock
`bao encode --outboard` produces a file the daemon rejects.

Add an offline, config-free `decdn origin import -i <path> --to <target>`:

- Single file: stream once to compute the BLAKE3 root and the outboard,
  write the sharded data object + `.obao4` sibling atomically. `--move`
  renames the source (copy+unlink across filesystems); idempotent on a
  content-addressed path; `--force` overwrites.
- Directory: walk (reusing `bundle create`'s containment / `--exclude` /
  `--follow-symlinks` rules), import every file, emit the canonical bundle
  manifest (byte-identical to `bundle create`), and import the manifest
  blob itself so the whole tree is retrievable by one bundle hash.
- `--json` status line, mirroring `bundle create`.

`--to fs:<dir>` is implemented; the hash + outboard prep is
backend-independent, so an `s3://` writer is an additive follow-up (the
target parser already rejects `s3://` and `http(s)://` with actionable
errors).

The outboard encoder and the `.obao4` layout contract (`OBAO4_SUFFIX`,
shard prefix) move into the iroh-blobs-free `bao-range` leaf crate, shared
by the cache reader (`origin::fs` / `origin::s3`) and the new writer, so a
blob written by `origin import` is one the daemon reads back verbatim — an
integration test proves it by range-serving through the real
`FilesystemOrigin`. The CLI stays iroh-blobs / AWS-SDK free (#578).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 2, 2026 10:19

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.

🟡 Changes recommended

origin import --move can delete source data without verifying an already-present target object/outboard matches the expected bytes, risking silent data loss and leaving stale .obao4 files in place.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a new offline CLI workflow (decdn origin import) to seed a cache origin store from local files/trees by writing both the sharded data object and its daemon-compatible {hex}.obao4 pre-order outboard, reusing shared manifest-walk/serialization logic so directory imports produce bundle manifests byte-identical to decdn bundle create.

Changes:

  • Introduces decdn origin import CLI args + dispatch and implements an fs-backed origin writer (with --move, --force, --exclude, --follow-symlinks, --bundle, --json).
  • Extracts bundle-manifest walk + canonical JSON serialization into a shared commands::manifest module used by both bundle create and origin import.
  • Moves the .obao4 layout contract and outboard encoder into the bao-range leaf crate and wires the cache fs origin to use the shared OBAO4_SUFFIX.
File summaries
File Description
crates/common/src/cli/origin.rs Defines clap args for the new decdn origin import command.
crates/common/src/cli/mod.rs Plumbs Origin into the shared CLI command enum and exports args types.
crates/cli/src/main.rs Adds runtime dispatch for Command::Origin without threading config.
crates/cli/src/commands/mod.rs Registers new manifest + origin command modules.
crates/cli/src/commands/manifest.rs Shared directory walk, exclude semantics, and canonical manifest serialization/writes.
crates/cli/src/commands/bundle.rs Refactors bundle create to use shared manifest machinery.
crates/cli/src/commands/origin.rs Implements origin import (fs target), including report output and atomic writes.
crates/cli/tests/origin_import.rs Integration coverage proving daemon-compat .obao4 via real FilesystemOrigin reads + bundle byte-identity.
crates/cli/Cargo.toml Adds decdn-bao-range dependency for the outboard/layout contract used by import.
crates/cache/src/origin/fs.rs Re-exports .obao4 suffix from decdn_bao_range to keep layout contract shared.
crates/bao-range/src/origin_seed.rs New shared outboard encoder + shard prefix + .obao4 naming contract.
crates/bao-range/src/lib.rs Exposes the new origin-seeding helpers from bao-range.
CLAUDE.md Updates crate/binary capability overview to include origin import.
Cargo.lock Updates lockfile for new dependency edge(s).
Review details

Suppressed comments (1)

crates/cli/src/commands/origin.rs:359

  • If a {hex}.obao4 sibling already exists, this treats it as valid and skips writing without checking that it matches the expected outboard bytes. That can leave a stale/foreign outboard in place, defeating the main goal of origin import (daemon-compatible range serving) while still reporting success.
    let present = std::fs::metadata(obao4_path).is_ok();
    if present && !force {
        return Ok(());
    }
  • Files reviewed: 13/14 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 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/origin.rs Resolved
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.64% (was 82.66%, ▼ 0.02%) — 71608/86648 lines

File Coverage Lines Δ
crates/bao-range/src/lib.rs 93.88% 138/147 ● 0.00%
crates/bao-range/src/origin_seed.rs 100.00% 52/52 new
crates/cache/src/origin/fs.rs 78.36% 594/758 ● 0.00%
crates/cli/src/commands/bundle.rs 83.00% 83/100 ▼ 9.43%
crates/cli/src/commands/manifest.rs 95.54% 321/336 new
crates/cli/src/commands/origin.rs 77.03% 285/370 new
crates/cli/src/main.rs 62.50% 25/40 ▼ 1.60%
crates/common/src/cli/mod.rs 100.00% 3/3 ● 0.00%
History
Commit Total Δ vs base
f8b92bd 82.64% ▼ 0.01%
3d42630 (HEAD) 82.64% ▼ 0.02%

Copilot review: `origin import --move` decided a target object was already
present using a length-only check, then deleted the source — so a same-size
but corrupt/foreign object at the content-addressed path could silently
discard the only correct copy of the data.

- `--move` now re-hashes an already-present object and refuses to delete the
  source unless it verifies (`--force` still overwrites from the source).
- Replace the length-only `.obao4` check with a content check (`ensure_obao4`):
  a stale/foreign sibling from a partial prior import is overwritten instead of
  left in place (the node rejects a mismatching `.obao4` and drops to whole-blob
  serving). A byte-identical sibling is still a no-op.

Adds regression tests: move-refuses-on-corrupt-present, move-consumes-on-
verified-present, stale-obao4-replaced.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit 0139899 into main Sep 2, 2026
27 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1904-pr-4ac8ed branch September 2, 2026 10:47
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.

decdn origin import: seed a cache origin store (sharded blob + .obao4), fs-first

2 participants