Skip to content

seed: write installed layers to a directory another store installs from (REQ-SEED-001) - #354

Merged
avrabe merged 14 commits into
mainfrom
feat/seed
Nov 12, 2026
Merged

avrabe merged 14 commits into
mainfrom
feat/seed

Conversation

@avrabe

@avrabe avrabe commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds varve seed <DIR> for REQ-SEED-001. It writes the layers this store has installed into a directory that another store can install from, with no network and no registry credential. Each layer gets its own OCI layout under DIR, in the form a realm's mirrors entry accepts.

The case: a container's store is a separate store from its host's. After a pin change the container refetched a composed layer from the registry and needed the credential, although the host store already held every byte.

What it does

  • Which layers: by default the pinned layer and every layer it composes, transitively. A composed layer that is not installed here refuses and names that layer; it does not produce a smaller seed. --layer <id> --digest sha256:… seeds one installed layer and the layers it composes.

  • What it copies: bytes, never re-encoded:

    • the retained signed envelope;
    • payloads, re-hashed against the signed digests;
    • the cached baseline status;
    • the cached signed line index;
    • carried attestations.

    Shims and the env script are never read.

  • Where it writes:

    • DIR must be absolute, not a symlink, and new, empty or a previous seed (marked by a file).
    • Every layer is written into a staging directory inside DIR and moved into place only when all of them succeeded. A refusal in any layer leaves DIR as it was. An existing layer directory is removed and replaced, never written into; a symlink in its place is removed, not followed.
    • A realm that requires a signed index refuses a store that holds none, before any write.
  • The far store verifies everything against its own realm root, unchanged.

  • One platform per seed: a seed holds the payloads this store installed, for one platform.

Requirement change (maintainer decision, 2026-11-11)

Clause 2 of REQ-SEED-001 now covers "a store that has installed this line from this realm before". The first-contact rule stays. A store that has never installed from a realm makes first contact through the primary, and --from covers a non-composed pin's root layer. cmd-seed.md states this limit for composed pins.

Tests

  • crates/varve/tests/seed.rs covers end to end:
    • seed, mirror, then install with the registry unreachable;
    • each refusal, asserting exit code 1, or 2 for a usage error;
    • the first-contact refusal.
  • The clause-3 scan requires a file of the source store to carry its path. Shims are links to the varve binary, so on their own they proved nothing.
  • New lineindex test: mutation testing of IndexCache::envelope_bytes, which seed reads, found its NotFound guard unkilled. Without that guard, a seed for a signed-index realm could be written without the index it needs. A lineindex test now asserts that an unreadable cached index is an error, not an absent one.

Review

A fresh-context review of 3ba3c42 confirmed that a seed with one tampered byte is refused by the far store, and that the foreign-directory and missing-index refusals go red when broken. It found:

Finding Fix Red before the fix
MEDIUM: a re-seed followed symlinks planted in a previous seed and overwrote a file outside DIR f3817ba staging, never write into an existing layer directory the victim file held the layout's index.json
MEDIUM/LOW: a refusal in a later layer left earlier layers written f3817ba, tests in e0e2c6c a failed seed left ["2026.08.0-…", "varve-seed.json"]
MEDIUM: the requirement said "from this realm"; first contact is per line 19ac8d0 wording
LOW: the composed-layer signed-index check had no test 74d9746 hard-coded false: "Unexpected success"
LOW: a missing composed layer under --layer/--digest had no test (exit 0, one layer seeded, when broken) 8929662 no-op missing.push: "Unexpected success"
LOW: a malformed realms file skipped the signed-index check f233b2c exit 0 before the fix

The seed logic moved from main.rs into varve_core::seed::write_seed, so the seed mutation shard now covers it.

CI's mutation run on f88f64b missed 4 mutants that my local run had reported caught:

  • What happened locally: one mutant made claim_destination create relative/seed in cargo-mutants' scratch copy. That directory persisted, and a_relative_destination_is_refused_and_names_why then failed for every later mutant, whatever it mutated.
  • The fixes:
    • 1af0efc makes that test clean up after itself.
    • 0429ff7 adds four lib tests, one per mutant, that need no file permissions.
  • Checked on the new run: each of the four mutants' logs now names its own new test as the one that failed.
  • This was added to Gate potency at v0.47.0: four gates bypassable by a specific edit, one fail-open path #352 as a gate-potency finding.

Limits, documented in cmd-seed.md (f88f64b):

  • The final moves are not one atomic step.
  • A process killed mid-seed into a new DIR leaves a staging directory, and the next run then refuses DIR as not a seed.

Local gates, on f88f64b (tests and mutants re-run on 0429ff7)

Gate Exit
cargo fmt --check 0
clippy -D warnings 0
cargo test --workspace --no-fail-fast 0 (2237 passed, 0 failed on 0429ff7)
rivet validate, rivet check verification-evidence 0
trace-gate, claim-check, tracepack-check, review-check 0
tools unittest, tools/systest/install-shadow.sh 0
cargo deny check 0
tools/check-py-floor.py (Python 3.9.6), shellcheck 0.11.0 -S warning 0

Mutants: full shards, CI's command, -j 2.

Shard Tested Caught Unviable Timeout Missed
varve-core (seed), new in this PR, on 0429ff7 32 29 3 0 0
varve-serve (agent context), varvecmds.rs changed, on 3ba3c42 (its files unchanged since) 384 362 21 1 0
  • Not in any shard: main.rs and lineindex.rs, both excused in mutation-scope.toml. The CLI paths are covered by tests/seed.rs.

🤖 Generated with Claude Code

https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu

avrabe and others added 12 commits November 11, 2026 05:14
…om (REQ-SEED-001)

varve seed <DIR> copies the pin's layer and every layer it composes into one
OCI layout per layer under DIR, each usable as a realm mirrors entry. Bytes are
copied, never re-encoded: the retained signed envelope, payloads re-hashed
against the signed digests, the cached baseline status, the cached signed line
index and carried attestations. Shims and the env script are never read. DIR
must be absolute and new, empty or a previous seed (marker file); a realm
requiring a signed index refuses a store that holds none, before any write.
The far store verifies everything against its own realm root, unchanged.

seed.rs gets its own mutants shard; docs topic and agent command table updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
…the docs

The clause-3 scan now requires a FILE of the source store to carry its path
(shims are links to the varve binary and proved nothing). Every refusal asserts
exit code 1 and usage 2. A never-installed store taking a seed through mirrors
is pinned as the first-contact refusal it is, and cmd-seed.md states that limit
for composed pins and that signed-index is only refused where the realm is known.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
…bsent one

Mutation testing of IndexCache::envelope_bytes (which seed reads) found the
NotFound guard unkilled; a seed for a signed-index realm could otherwise be
written without the index it needs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
…he realm before

Maintainer decision 2026-11-11: keep the first-contact rule. A store that
has never installed from the realm makes first contact through the
primary; --from covers a non-composed pin's root layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
A re-seed exported with force into the existing <layer>-<hex> directory, and
write_oci_layout follows symlinks, so a symlinked layout dir, index.json or
blob planted in a previous seed made varve overwrite files outside DIR.

Layers are now exported into a fresh staging directory (create_dir) inside DIR
and moved into place afterwards, removing any existing entry without following
a symlink. A DIR that is itself a symlink is refused. The logic moves from
main.rs into varve_core::seed::write_seed so it is mutation-tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
The staging in the previous commit makes the main.rs claim true: tests tamper
the composed layer's installed payload (written second) and assert a new DIR
is not created at all and a previous good seed is unchanged after a failed
re-seed. The command's doc comment now says what is refused up front and what
staging covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
…forces it (F3)

Clause 2 said "a store that has installed from this realm before"; the rule
(FirstContactNeedsPrimary { line }) is per line. Same maintainer decision,
stated precisely; cmd-seed.md reworded to agree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
…d (F4)

Names the root by --layer/--digest so only the include's realm decides; hardcoding
signed_index to false for it turns this test red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
…igest (F5)

The default pin path was refused earlier by resolve, so dropping missing.push
went unnoticed; this path reaches it. Removing the push turns the test red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
resolve_realm(..).ok() turned a malformed or unreadable varve-realms.toml into
"realm unknown" and skipped the signed-index check. NoRealmsFile and Undefined
still mean no obligation; every other realm error refuses and names the file.
The decision lives in seed::realm_obligation so it is mutation-tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
…omic final moves

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
avrabe and others added 2 commits November 12, 2026 11:07
A mutant that let claim_destination accept a relative path created
relative/seed in the crate dir of cargo-mutants' scratch copy; it persisted
and failed this test for every later mutant, masking real misses. A Drop
guard now removes what the probe may have created, on pass, fail or panic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
…ions

check_destination on a regular file, remove_entry beneath a regular file
(ENOTDIR), and write_seed's cleanup of a destination it created versus one
that was already there, each driven by a layer whose payload was tampered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
@avrabe
avrabe merged commit 8ea62d4 into main Nov 12, 2026
53 checks passed
@avrabe
avrabe deleted the feat/seed branch November 12, 2026 14:38
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.

1 participant