Skip to content

Fix day-2 cell rehydration and add record-level license default - #326

Merged
jsimonclark merged 1 commit into
mainfrom
fix/rehydration-and-license-0731
Aug 1, 2026
Merged

Fix day-2 cell rehydration and add record-level license default#326
jsimonclark merged 1 commit into
mainfrom
fix/rehydration-and-license-0731

Conversation

@jsimonclark

Copy link
Copy Markdown
Collaborator

What

Two pre-0.8 package fixes (blind-review findings 3 and 4):

  1. Day-2 workspace rehydration. In a fresh process, ws.add("test", cell="S1") now resolves a cell whose record sits in .battinfo/records/cell-instance/, instead of raising Could not resolve cell 'S1' .... The resolver lazily rehydrates the serial index from disk, and the failure message now names what was actually searched.

  2. Record-level license. New ws.license("cc-by-4.0") sets a workspace default that is persisted in .battinfo/workspace.json and stamped onto every saved record, so records carry a license by themselves (FAIR R1.1) rather than only on the Zenodo leg.

Why

  • The serial to record index was session-memory only; the resolver's "locally" branch never scanned saved records, so authoring a test the day after saving cells failed with a false error. Reproduced with a cold subprocess.
  • Served and locally saved records carried no license (two reviewers, independently): license existed only if the author took the Zenodo path, so a record dereferenced at its identifier stated no reuse terms.

How

Rehydration:

  • _resolve_cell now, on a miss, calls _rehydrate_cell_index() (a lazy, once-per-instance scan of .battinfo/records/cell-instance/, sharing the loader core with reload_cells) before falling back to the registry. Error text rewritten to name the saved-records directory and note when the registry is not configured.
  • Protocol/spec references already scan disk (_resolve_test_protocol_ref, _resolve_channel); a cold-process test pins that so it never regresses to the session-only defect the cell path had.

License:

  • ws.license(id|clear=...) mirrors ws.contributor/ws.project: setter/getter/clear, persisted in workspace.json. Known SPDX-ish ids are case-normalized; an unrecognized string is kept verbatim with a warning (never hard-rejected).
  • Stamped through the existing PR Fix [unchanged] misreport with contributors; teach vent part type #324 pre-compare _record_stamp path so byte-identical re-saves still report [unchanged]; datasets carry it on the existing dataset.license slot (leaving an explicit ws.add(license=) untouched), other record types at the record top level.
  • Emission reuses the existing dataset convention: dcterms:license in record_to_jsonld, schema:license/dcterms:license in the publication bundle. ws.zenodo/preview_jsonld fall back to the workspace default when no license= is passed.
  • Gold-standard panel: a licenseless publication emits a publication.license_missing warning (not an error) nudging ws.license(...).
  • Schemas: added a top-level license string to the cell-spec/cell-instance/test/test-protocol save gates (edited assets/schemas source of truth, re-synced the packaged mirror, ran web/scripts/sync-schemas.mjs). Datasets already accept a nested dataset.license.

Precedence (documented in the ws.zenodo and ws.add docstrings): explicit ws.zenodo(license=...) > explicit ws.add(..., license=...) > workspace default.

Public API added (for the docs agent)

  • ws.license(license: str | None = None, *, clear: bool = False) -> str | None — setter (returns normalized id), getter (no args; returns/prints current or None), clear=True to remove. Persisted in .battinfo/workspace.json under license; stamped onto every record on ws.save().
  • ws.zenodo(..., license: str | None = None) — was license: str = "cc-by-4.0"; now defaults to the workspace default, then cc-by-4.0.
  • ws.add("test", ..., license=...) — unchanged, still overrides the workspace default for that record's datasets.
  • Precedence: ws.zenodo(license=) > ws.add(license=) > ws.license() default.

Testing

  • uv run pytest — 1621 passed, 1 skipped. uv run ruff check clean on all changed files (pre-existing notebook/demo lint in docs/ and demo/ is untouched and out of territory). uv run mypy — success, 69 files.
  • New tests/test_ws_rehydration.py: cold-subprocess resolve of a cell serial saved in a prior process; fresh-instance resolve; truthful error text; cold-process protocol-reference resolve.
  • New tests/test_ws_license.py: setter/getter/persistence/clear, case-normalization, unknown-kept-verbatim-with-warning, URL verbatim, stamping into every saved record + record_to_jsonld, no-license-means-no-stamp, explicit-add-overrides-default precedence, preview bundle carries the license, ws.zenodo default resolution + explicit override, missing-license warning nudge + no-nudge-when-present.
  • Extended the PR Fix [unchanged] misreport with contributors; teach vent part type #324 stamp-order regressions in tests/test_pkg_silent_loss.py: identical re-save with license set -> [unchanged] (bytes + mtimes unchanged); changing the workspace license -> [updated].

Rehydration repro (registry_url=None), before vs after:

Before: session B (fresh process) -> ValueError: Could not resolve cell 'S1' in this session, locally, or the registry. Create it with ws.add('cell', ...), or check the serial.

After: session B (fresh process) -> resolves S1 and creates the test; an unknown serial now errors with ... in this session, the records saved under <root>\.battinfo\records (registry not configured). ....

Pre-existing flakes: none observed. Both full-suite runs (before and after adding tests) were fully green; the documented intermittent rehydrate/finalize flakes did not appear, so nothing needed diffing against main.

Resolve cell serials from .battinfo/records/ in a fresh process, and add a
workspace-default license (ws.license) stamped onto every saved record and
emitted as dcterms:license.
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
batt-info Ready Ready Preview Aug 1, 2026 12:10am

Request Review

@jsimonclark
jsimonclark merged commit 3b2f2f8 into main Aug 1, 2026
25 checks passed
@jsimonclark
jsimonclark deleted the fix/rehydration-and-license-0731 branch August 1, 2026 00:42
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