Skip to content

The ledger snapshot digests every Active resource, twice per run: a discovered directory boundary such as ~ is Merkle-walked (1.7M files) at the end of every deploy, silently, and the walk is discarded #904

Closed

Description

@David-Noble-at-work

Ledger (placed by the owner 2026-09-22).

Measured, 2026-09-21, darwin/arm64

writ deploy common on this machine: 169 seconds, no output until the final line. The units -- 166 links -- take
seconds. A sample of the process at 15 s shows one thread in crypto/sha256.block with openat/read/fdopendir
beneath it: a directory walk, hashing every file, inside writ, in Go. No git child. Nothing narrates.

Mechanism

Three correct rulings compose into hashing the home directory:

  1. ResourceCatalog.Snapshot() (pkg/op/resource_catalog.go:572) calls Etag() and Digest() on every Active
    entry, unconditionally, to record the ledger.
  2. file.Directory.Digest() (pkg/op/provider/file/directory.go:187) is a Merkle root of the whole tree -- "no
    gitignore filtering and no .git skip", ruling 5d -- written for a directory that is a product.
  3. findClosestExistingDir discovers each write's creation boundary as a Directory resource: ~/Library/Fonts for
    the 42 planned fonts, ~/.config, and ~ itself for the twelve root dotfiles. Discovered, never produced,
    and Active once verified.

So the capture Merkle-walks ~ -- 1,687,960 files under ~/Library alone -- until an entry it cannot hash stops it,
and the error is dropped (if err == nil): ~170 s to record nothing. And it runs twice: Run captures the
ledger in its defer (graph_executor.go:320) so a trace can be projected, then deploy.go:237 calls
executor.Trace(), which snapshots again (graph_executor.go:487).

directory.Etag's own comment states the rule the snapshot never applies: "the catalog treats a changed Etag as
the trigger for the full Digest comparison". Every kind's Etag() is one lstat.

The fix, ruled 2026-09-21: compare, then recompute only if needed

  1. Snapshot() takes the prior snapshot. Per Active entry it computes the Etag; when the prior holds the same ID
    with the same Etag, the prior's Digest is carried forward; only a changed or absent Etag calls Digest().
  2. Trace() passes e.ledgerSnapshot, the defer's capture, as the prior: between the two nothing moved, so the
    second capture is 166 lstats and no hashing.
  3. A discovered directory -- a boundary nobody produced, ProducerID empty -- records its Etag and no
    Digest: its identity is its path, not its content. That removes the first walk too.

Acceptance

Epic: ResourceModel · Ledger

Plan and design documents

Kind Document
Plan docs/plans/fix/904-ledger-snapshot.md
Design docs/architecture/4-resource-management.md

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions