Skip to content

build: fetch the corpus's big tier from an OCI image - #45

Merged
webern merged 4 commits into
mainfrom
m/deslag-blobstore
Sep 27, 2026
Merged

webern merged 4 commits into
mainfrom
m/deslag-blobstore

Conversation

@webern

@webern webern commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

deslag's lints are decided and proven on a test corpus: Markdown quoted from public repositories, each file (a fixture) with a JSON sidecar that records where it came from, its licence, and whether its git history proves it human, llm or mixed. The corpus in tests/corpus/ is already as big as the build doctrine allows for git: about 400 fixtures per label. This PR adds a second tier, the big tier, that lives outside git and can keep growing, so that a lint's rule can be checked across thousands of repositories and not just the few hundred a maintainer has read. It also writes down the corpus design in docs/design/corpus.md (Status: APPROVED) and what is built in docs/design/corpus.asbuilt.md.

The image and the lock

The big tier is one OCI image, FROM scratch, at ghcr.io/webern/deslag-blobs. Nothing runs it; it is a way to store versioned files in a registry. scripts/blobstore/blobs.lock pins it by digest. Its first line is the image, and each other line records one layer (a fingerprint of its content, the blob the registry holds for it, and its path) so that a publish can reuse unchanged layers byte for byte. blobs.sh moves the image with crane, which it downloads into .tools/crane/ at a pinned version and checks against a hash. layers.txt says where layers split: corpus/ and corpus/batches/ are listed, so each batch is its own layer and a publish uploads only the new batch.

Layout

make fetch-blobs unpacks the image into .blobs/unpacked/, which git ignores:

.blobs/unpacked/corpus/batches/
  2026-09-27-01/
    manifest.jsonl            one line per fixture this batch adds
    exclude.jsonl             one line per earlier fixture it drops: {"sha256", "reason"}
    human/nltk--nltk/README.md
    human/nltk--nltk/README.json
    llm/...  mixed/...

A manifest line repeats what a reader needs from the sidecar, so the batch can be filtered without opening every sidecar:

{"file": "human/nltk--nltk/README.md", "sha256": "ed157629...", "size_bytes": 1733, "label": "human", "host": "github.com", "repo": "nltk/nltk", "path": "README.md", "commit": "787575a4...", "sidecar_version": 2, "natural_language": "en", "kind": "readme", "ai_tools": []}

Batches are append-only. A fixture found to be wrong is dropped by a later batch's exclude.jsonl, and a later batch may add it again with a newer sidecar.

Fetching and publishing

  • make fetch-blobs unpacks the pinned image. When .blobs/stamp equals the lock, it is a file compare and nothing else.
  • make test-blobs fetches, then runs the tests in tests/blobs.rs that are marked ignored.
  • make ci now runs test-blobs after test.
  • The build never fetches. make build, make test and make check stay offline, with no login.
  • To add data: make fetch-blobs, then collect.py pack --from tests/corpus --corpus .blobs/unpacked/corpus --work DIR (or a later harvest) writes a new batch, then make test-blobs, scripts/blobstore/blobs.sh plan, make publish-blobs, and commit blobs.lock with blobs.md.
  • make clean-blobs (and make clean) removes .blobs/ and .tools/.

Since git ignores .blobs/, an edit under it that is not yet published is invisible to git status. When the lock changes (after a branch switch, pull or merge), fetch looks for such edits before it replaces the tree. If it finds any, it stops and says what they are and what to do, so a switch never silently throws away work.

Access

The package is private for now.

  • A person fetches with their own gh login, which needs read:packages. Publishing needs write:packages. blobs.sh asks gh for the token each run and stores no login.
  • With no gh login at all, fetch tries anonymously, which is all it will need once the package is public.
  • CI uses the workflow token. This works only while the package grants this repository access: Packages -> deslag-blobs -> Package settings -> Manage Actions access -> webern/deslag, Write role. That grant is in place.
  • ghcr hides a package from a token that may not read it. So a "manifest unknown" in CI means the grant is missing, not the manifest. The script's error in CI names the three things to check: GH_TOKEN on the step, packages: read on the job, and the grant.
  • While the package is private, a ghcr.io outage fails make ci.

CI

ci.yml gets packages: read, GH_TOKEN: ${{ github.token }} on the make ci step, and an actions/cache step for .blobs, keyed on blobs-<os>-<hash of blobs.lock>, with no restore keys. A cache hit restores the tree and its stamp, so fetch does nothing and crane is not even downloaded. release.yml's verify job gets the same permission and token.

What v1 holds

One batch, 2026-09-27-01: the 1200 collected fixtures of tests/corpus/, 400 each of human, llm and mixed, byte for byte with their sidecars. That is 9,694,980 bytes of Markdown and 12,034,975 bytes in all, as one compressed layer of 4,804,592 bytes. core/ is left out on purpose; it is hand-picked and has no proven label.

  • Image: ghcr.io/webern/deslag-blobs:v1@sha256:1fdc59d68fef2bc54f08f568fbd64117974c2b5203f6aba16b11b612e5803438
  • v0 in the registry was not pushed by this PR. It is a placeholder with one 116-byte layer, from when the package was set up.

v1 is the tree and nothing more. A later change will harvest more.

The loader and its tests

tests/common/blobs.rs has load_blobs, which reads the batches in name order and checks each one:

  • exclusions first, each with a reason and naming a fixture an earlier batch left in
  • the manifest and the files match one to one
  • each fixture passes the same sidecar checks as the tree
  • each manifest line equals what its sidecar says
  • no two live fixtures share a sha256, or a label, host, repository and path

These rules are checked after every batch, not only the last, because every published version ends at some batch. The sidecar checks the two loaders share moved to tests/common/fixture.rs, in their own commit.

tests/blobs.rs has five offline tests that build small batches in a temp dir:

  • a batch can drop a fixture and add it again
  • it cannot add one the tier already holds
  • an exclusion must name an earlier fixture
  • a batch holds only what its manifest names
  • a manifest line must agree with its sidecar

It also has three ignored tests that make test-blobs runs on the real image:

  • every fetched batch keeps the rules
  • every collected fixture of the tree is in the big tier with the same sidecar bytes
  • no core/ fixture is in it

collect.py gains a pack stage. It writes the tree's collected fixtures that the big tier does not hold yet into a new batch, with its manifest. It checks each fixture's bytes against its sidecar and refuses duplicates. Batches are named YYYY-MM-DD-NN and must sort after every existing batch.

Where the code came from

blobs.sh, layers.txt and blobs.md are ported from an earlier private project of mine. What changed:

  • Image name, messages and docs are deslag's.
  • Fetch works without a gh login (anonymously); publish still needs one.
  • Layers are tarred in pax format, not ustar. Nine tree fixtures have basenames over 100 bytes, and bsdtar skips those under ustar while still exiting 0. Each tar's listing is also checked against the tree before anything is pushed.
  • bsdtar is called by name, so publishing on Linux needs libarchive-tools. Fetching works with any tar.
  • The crane download uses curl only, and hashes with sha256sum when shasum is missing.
  • Each command reports every missing tool in one pass.
  • The error for a CI auth failure names what to check.

Choices worth a look

  • Origin identity is scoped to the label. The tree already holds three files twice, as a human revision from before 2022 and a later mixed revision: marko-js/htmljs-parser README.md, martinus/nanobench README.md, and mldangelo/personal-site docs/adapting-guide.md. A rule of one fixture per host, repository and path would reject one of each pair, and then "every tree fixture is in the big tier" could not hold. So pack and the loader key origin on label, host, repository and path. sha256 is still unique across all labels.
  • There is no index file above the batches. Each batch's manifest indexes what it adds, in its own layer. An index would be a derived file that changes on every publish and can drift from the sidecars.
  • Manifest lines carry ai_tools, so a reader can filter by tool without opening sidecars.
  • The batch is named for the day it was packed (2026-09-27), not the capture date in the sidecars (2026-09-23).

Left for later

  • Harvesting fixtures beyond the tree into new batches.
  • pack reads exclusions but does not write them. For now an exclusion is written by hand into a new batch.
  • publish does not refuse a tag that already exists in the registry (two publishes racing), or a published batch whose content changed. Batches are append-only by rule, not by check.
  • Making the package public, which would remove the login for fetching and the dependence on ghcr for every PR.
  • Measuring lints on the big tier.

Testing

  • make ci: exit 0, including test-blobs (fetched v1, 3 of 3 passed)
  • Fresh clone in a temp dir, with no .blobs/: make test passes (in tests/blobs.rs, 5 passed and 3 ignored)
  • Same clone: make fetch-blobs then make test-blobs, 3 of 3 passed; make clean removed .blobs/ and .tools/
  • Refusal of unpublished edits, same clone: edited a file under .blobs/unpacked/, switched to a branch whose lock differed, and make fetch-blobs refused, named the edit and left it in place
  • No login: with gh hidden, fetch fails with the message for a person; with GITHUB_ACTIONS=true, the message for CI
  • Against a local registry (crane registry serve): publish then fetch gives a byte-identical tree, long names included; a second publish reuses the first layer byte for byte; a batch holding only exclusions loads; excluding a tree fixture fails the superset test
  • Missing tools are all reported in one pass
  • crane 0.22.1: the four pinned hashes (macOS and Linux, arm64 and x86_64) match both the downloaded archives and the release's checksums.txt
  • v1 published; the package's visibility and settings are unchanged (still private)
  • cargo run -- check: the new docs lint clean within their budgets
  • CI cache: a miss on the first run (both runners, key saved) and a hit on the re-run, with the package read through the workflow token and the grant
  • Unverified: whether Dependabot PRs and PRs from forks get a token that can read the private package. If not, their make ci fails until the package is public.

References

Move the sidecar types, check_sidecar and the check that no two
fixtures share a key out of tests/common/corpus.rs into
tests/common/fixture.rs, so that a second loader of the corpus can use
them. read_fixture reads a fixture and its sidecar and checks one
against the other. A sidecar may now carry any version the loaders
know, which is still only 2.
The corpus in tests/corpus/ is at the size the build doctrine allows.
A bigger corpus now lives in one OCI image, ghcr.io/webern/deslag-blobs,
pinned by digest in scripts/blobstore/blobs.lock.

scripts/blobstore/blobs.sh is a copy of komp's blob store script. It
fetches the image into .blobs/unpacked with crane, plans a publish, and
publishes the tree as the next vN, one layer per batch. The copy now
fetches without a login when gh has none, writes pax tars so that long
names are kept, checks each tar against the tree before it is pushed,
and checks for the tools each command needs in one pass.

The build does not fetch. make test stays offline. make test-blobs
fetches the image and runs the ignored tests in tests/blobs.rs, which
load every batch and check it: each manifest line against its files
and sidecar, each exclusion against an earlier batch, no fixture twice,
every collected fixture of the tree in the big tier with the same bytes
and sidecar, and no core fixture in it. make ci runs it, and CI caches
.blobs on the hash of the lock.

collect.py gains a pack stage that writes a tree's fixtures as a new
batch with its manifest. v1 holds one batch: the 1200 collected
fixtures of the tree.
docs/design/corpus.md is the approved design of the test corpus: what
it is for, its two tiers, how a fixture earns its label, how the big
tier is laid out in batches and grows, and what may read it. A
fixture's origin is unique within its label, so a file's human
revision and its later mixed revision may both be fixtures.

docs/design/corpus.asbuilt.md says what is there today: the tree, the
sidecar, the big tier's layout, collect.py and the loaders. The corpus
parts of deslag.asbuilt.md move to it and leave a pointer.

The build doctrine, AGENTS.md and deslag.toml learn about the blob
store, test-blobs in make ci, and the new docs with their budgets.
The pin named v6.1.0 but held the v5.1.0 commit.
@webern webern added ai Primarily authored by AI (whether PR, Issue, Whatever) area/build Deals with deslag build, scripts, ci, cd. labels Sep 27, 2026
@webern
webern marked this pull request as ready for review September 27, 2026 01:53
@webern
webern merged commit 89e3669 into main Sep 27, 2026
4 checks passed
@webern
webern deleted the m/deslag-blobstore branch September 27, 2026 01:54
webern added a commit that referenced this pull request Sep 27, 2026
## Summary

`docs/design/deslag.asbuilt.md` describes the code as it is. At a2d8ea1
it is 16378 bytes of its 16384 `max_size_bytes`, and it has been within
180 bytes of that budget since #23 (16352). Each of #44, #45 and #47
made room for its new paragraphs by cutting others, and #45 moved the
corpus text out to `corpus.asbuilt.md`. The `deslag-design-docs` skill
says a budget is not raised without the owner, so every change to the
code has had to squeeze the doc.

The budget was also kept by hand: `.agents/deslag.toml` did not select
the doc. Selected at a2d8ea1, it fails `max_emphasis` (20 bold spans,
1.24% of its prose) and `density` (8 paragraphs over 500 characters).

This PR splits the doc the way `corpus.asbuilt.md` already is: one
as-built doc per subsystem, each with its own budget, and every one of
them linted.

- `deslag.asbuilt.md` is now the overview: what deslag is, a run, the
modules at directory level and what calls what, an index of the
subsystem docs, the command line and exit codes, other files, the tests
and the build. Its budget drops from 16384 to 8192, so it cannot grow
back into the place every detail goes.
- `config.asbuilt.md`: the config, glob patterns, the walk and `deslag
explain`.
- `document.asbuilt.md`: the `Document` and frontmatter. It is named for
`src/document/`, the module it holds.
- `lints.asbuilt.md`: checking, marks, one section per lint in
`Lint::ALL` order, reports and `--format`. A new lint is one new
section.

Each subsystem doc opens with its entry points and callers, then its
`src/` tree, then one section per concern. `subsystems:` in each doc's
frontmatter holds `src/` module names, each in exactly one doc: the one
with its detail.

| Doc | Bytes | Budget | `subsystems:` |
|---|---|---|---|
| `deslag.asbuilt.md` | 6786 | 8192 (was 16384) | `cli`, `instructions`
|
| `config.asbuilt.md` | 3889 | 5000 | `config`, `glob`, `explain` |
| `document.asbuilt.md` | 2194 | 3000 | `document`, `parse` |
| `lints.asbuilt.md` | 5884 | 7500 | `lint`, `output` |
| `corpus.asbuilt.md` | 5998 | 8192 | `corpus` (unchanged) |

### Where each old section went

| Section at a2d8ea1 | Now |
|---|---|
| intro, A run | `deslag.asbuilt.md`, as they were |
| Modules | `deslag.asbuilt.md` keeps the tree at directory level and
the paragraph on what calls what; each subsystem doc takes its
file-level lines |
| The document | `document.asbuilt.md`: Blocks; Tokens, sentences and
locations |
| Where a file's budget comes from | `lints.asbuilt.md`: max_size_bytes
|
| The config | `config.asbuilt.md`: The config, and Glob patterns for
the `glob::Pattern` paragraph |
| Frontmatter | `document.asbuilt.md`: Frontmatter |
| Explaining a file | `config.asbuilt.md`: Explaining a file |
| Walking the repo | `config.asbuilt.md`: Walking the repo |
| Checking and reporting | `lints.asbuilt.md`: Checking, Marks, a
section per lint, Reports, --format |
| The command line, Other files, Tests, Build | `deslag.asbuilt.md`, as
they were |

### Commits

1. `docs: split the as-built doc by subsystem`: the text moves as it
was. New text is limited to each subsystem doc's opening sentences, the
overview's index, the section headings, and short descriptions for the
directories in the overview's tree, worded after the layout in
`AGENTS.md`. `README.md` says the overview indexes the subsystem docs.
2. `docs: fix the lint findings in the as-built docs`: 8 paragraphs
split at a sentence end, and 13 of 20 bold spans un-bolded. Each doc
keeps its first two; the sentence that defines each of the others stays.
No sentence is reworded.
3. `docs: correct the as-built docs against the code`: an ellipsis,
U+2026, also ends a sentence (`src/document/sentences.rs:113`); `make
clean` also runs `cargo clean` (`Makefile:98-99`); the trees now name
`parse/mod.rs`, `ACKNOWLEDGEMENTS.md` and `.agents/skills/`; `explain`
is in `subsystems:`, where no doc named it (`src/lib.rs:27`).
4. `test: lint every as-built doc and its subsystems`:
- `.agents/deslag.toml` selects `/docs/design/*.asbuilt.md` in place of
`corpus.asbuilt.md` alone. The glob does not select `deslag.desired.md`,
which is written by hand and stays unlinted, and topic docs stay listed
one by one.
- A selected file with no budget is counted but never size-checked
(`src/lint/max_size_bytes.rs:35-38`). An override on the same glob with
`value = 4096` closes that: a frontmatter budget wins over it, and a doc
that declares none fails at 4 KB.
- `tests/asbuilt.rs` fails when a module under `src/` is named in no
as-built doc's `subsystems:`, or in more than one, so a new module gets
its doc on purpose. It finds the frontmatter with `Document` and reads
it with `serde-saphyr`; no new dependency.

### Nothing lost in the move

A script outside the repo cuts the a2d8ea1 doc into 177 units (each
sentence, code line and heading) and 166 backticked names, and looks for
each in the four new docs, with whitespace and bold markers ignored.
After each commit:

| After commit | Units missing | Names missing |
|---|---|---|
| 1 | 4 | 0 |
| 2 | 4 | 0 |
| 3 | 6 | 0 |
| 4 | 6 | 0 |

The six, each on purpose:

- Three headings, `The document`, `Where a file's budget comes from` and
`Checking and reporting`, replaced by the sections in the table above.
- "Most specific first: the `max_size_bytes` key ..." now opens "A
file's budget comes from, most specific first: ...". Its heading used to
say what it was about; the section is now named for the lint.
- The sentence rule now names the ellipsis (commit 3).
- "`make clean` removes both directories" now adds "and runs `cargo
clean`" (commit 3).

The script proves each unit is somewhere, not that it is in the right
place, so the trees were read by eye.

### Left as it was

- The overview's paragraph on what calls what does not say that
`explain` calls `config`, `glob` and `parse` too. It is not wrong, so it
was not rewritten.
- The tests stay in the overview; no doc owns them yet.
- `corpus.asbuilt.md`, `corpus.md` and their lines in
`.agents/deslag.toml` are untouched; the glob now selects
`corpus.asbuilt.md` in place of its own line.

## Testing

- [x] `make ci`: exit 0
- [x] `deslag check` on the repo: exit 0 with all five as-built docs
selected; `deslag explain docs/design/deslag.desired.md` says it is not
selected.
- [x] A 5149-byte `docs/design/nofm.asbuilt.md` with no frontmatter
fails at 4096 bytes; `deslag explain` shows the frontmatter budget
winning over the override for `lints.asbuilt.md`. File removed after.
- [x] `tests/asbuilt.rs` fails with `parse: in no doc` when `parse` is
dropped from `document.asbuilt.md`, and with `lint: in
corpus.asbuilt.md, lints.asbuilt.md` when `lint` is added to
`corpus.asbuilt.md`, which also shows it reads a YAML block list. Both
reverted.
- [x] The residue script after each commit, as above.

## References

- No issue. Related to #23, #44, #45 and #47, each of which squeezed the
old doc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Primarily authored by AI (whether PR, Issue, Whatever) area/build Deals with deslag build, scripts, ci, cd.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant