Metadata-Version: 2.5
Name: attestation-schema
Version: 0.1.0
Summary: The attestation core run record (attestation.run/1, frozen): schema, canonical writer, strict reader, run-directory layout, job state file and job-backend interface. Standard library only.
Project-URL: Repository, https://github.com/mgoldey/attestation
Author: Matthew Goldey
License-Expression: MIT
License-File: LICENSE
Keywords: experiment-tracking,provenance,reproducibility,run-record
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# attestation-schema

The core run record that experiment producers write and
[attestation](https://github.com/mgoldey/attestation) reads:
`attestation.run/1`, **frozen 2026-11-19**: a record valid today stays valid,
and any change -- an additive optional field included -- is a new version
(`attestation.run/2`) that readers dispatch on. Standard library only.

```python
from attestation_schema import (
    RunRecord, Producer, CodeIdentity, Metric, HistoryWriter, write, read, read_history,
)

run_dir = "runs/run-3f2a9c01b7de"
with HistoryWriter(run_dir) as hist:            # streams attestation/history.jsonl
    loss = hist.series("loss", split="eval")
    for step, value in [(0, 0.9), (500, 0.4), (1000, 0.25)]:
        hist.point(loss, step, value)           # at=format_timestamp(...) if known

record = RunRecord(
    run_id="run-3f2a9c01b7de", family="lr-sweep", arm="lr=1e-3", status="complete",
    started_at="2026-11-19T10:00:00Z", finished_at="2026-11-19T10:42:13Z",
    producer=Producer(name="train.py", version=None),
    code=CodeIdentity(git_sha=None, dirty=None, repo=None, version=None,
                      provenance="unknown", evidence=None),
    config={"lr": 0.001}, data=[],
    metrics=[Metric(name="loss", value=0.25, direction="min", step=1000, split="eval",
                    unit=None, labels={})],
    history=hist.ref,      # {path, sha256, series, points}; None = no curve recorded
    seeds={"python": 0},
    dependencies=None,     # None = could not observe the environment; [] = observed, none
    ext={},
)
write(record, run_dir)     # -> runs/run-3f2a9c01b7de/attestation/run.json
assert read(run_dir) == record          # never opens history.jsonl
curves = read_history(run_dir)          # verifies the sha256, then parses
```

- `dumps`/`write` are the only sanctioned writers: validate, then RFC 8785
  canonical JSON, so the same record is always the same bytes.
- `loads`/`read` refuse anything non-conforming with a `RecordError` naming
  the path (`metrics[2].direction`); nothing is coerced or defaulted. They
  dispatch on `schema`, so later versions can still read older records.
- **Curves never go in `run.json`.** `metrics` holds final values; logged
  curves go to the sidecar `attestation/history.jsonl` (`attestation.history/1`:
  JSON Lines, one canonical line per series declaration or point, streamable
  and deterministic), written with `HistoryWriter` (incrementally, finalized
  atomically on close) or `write_history(run_dir, series)`, and bound to the
  record by sha256. `read_history` raises `HistoryMissingError`,
  `HistoryDigestError` or `HistoryFormatError` (all `RecordError`). Write
  order: outputs and history -> `layout.write_manifest` -> `write`.
- `ext.<namespace>` carries producer data the core does not model, untouched.
- `attestation_schema.layout` fixes the run directory (`attestation/run.json`,
  `attestation/state.json`, `attestation/digests.json`,
  `attestation/history.jsonl`, `steps/NN-<name>/`, `logs/`);
  `attestation_schema.jobs` is the job-backend `Protocol`, and
  `attestation_schema.state` is what every backend shares: `state.json`
  (`attestation.state/1`: `read_state`, `init_state`, `transition`), its
  cross-process lock (`state_lock`, POSIX `flock`; refused on Windows), and
  `settle` -- end a job exactly once, an existing record deciding, writing
  `terminal_record` for a job that died without one. A job's record carries
  its `JobSpec`'s `run_id`, `family`, `arm`, `config` and `ext` verbatim.
- `attestation_schema/schemas/run-1.schema.json` (the record),
  `history-1.schema.json` (one sidecar line) and `state-1.schema.json`
  (`state.json`) are JSON Schemas for other languages: necessary, not
  sufficient — the Python reader is the reference. They are frozen and
  pinned by digest.
- Package version 0.1.0: the formats are frozen; the Python API may still
  change in a 0.x minor release until the job-state API has a consumer.
 
## Releasing

Tag `schema-v<version>` (the version in this package's `pyproject.toml`, which
the workflow checks), independent of attestation's `v<version>` tags:

```
git tag schema-v0.1.0 && git push origin schema-v0.1.0
```

`.github/workflows/release.yml` builds the sdist and wheel, runs this
package's tests on CPython 3.11 against the wheel, and publishes to PyPI
through trusted publishing (environment `pypi`, no token). Release it before
an attestation release whose `attestation-schema>=X` floor is new.

Design: `docs/superpowers/specs/2026-11-19-core-run-record-design.md` in the
attestation repository.
