docs(lead): design self-hosted review releases and a tagging-quality gate
Some checks failed
CI / lint (push) Successful in 2m45s
CI / test (push) Successful in 4m19s
CI / notebooks-smoke (push) Successful in 2m3s
Deploy / changes (push) Successful in 17s
Infra CI / zotero (push) Successful in 30s
Infra CI / notebooks (push) Successful in 1m12s
Infra CI / docs (push) Successful in 28s
Infra CI / api (push) Successful in 22s
Infra CI / bcda (push) Successful in 20s
Infra CI / llm (push) Successful in 19s
Infra CI / mc (push) Successful in 18s
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Successful in 1m8s
Deploy / api (push) Successful in 1m36s
Deploy / bcda (push) Successful in 1m56s
Deploy / notebooks (push) Failing after 6m40s
Deploy / mc (push) Has been skipped
Deploy / llm (push) Successful in 2m17s
Deploy / report (push) Successful in 16s

OSF Projects freeze on 2027-02-19, and the LEAD living review's OSF
project holds nothing but the registration. Design: keep registration
8wq3m as the anchor, publish each review update as a BagIt bag with
RO-Crate metadata from rustfs/reach (stack lead release build/verify/
publish), and get the comment tagger back over a held-out gate before
fanning out. dev/scripts/osf_metadata.py sets tags, bepress subjects
and CC-BY 4.0 on the registration and project (dry run by default).
This commit is contained in:
kert
2026-11-11 13:52:42 -05:00
parent 893d0a1300
commit 55257bdb52
2 changed files with 313 additions and 0 deletions

134
dev/scripts/osf_metadata.py Normal file
View File

@@ -0,0 +1,134 @@
"""Set tags, subjects and license on the LEAD review's OSF records.
The OSF registration (8wq3m) and its project (bwc9n) were created bare:
no tags, no subjects, no license. Registration metadata stays editable
after OSF Projects go read-only (2027-02-19); the project is editable
until then. Dry run by default (prints the requests); --apply writes.
Needs a personal access token with osf.full_write in OSF_TOKEN (.env).
uv run python dev/scripts/osf_metadata.py # show the plan
uv run python dev/scripts/osf_metadata.py --apply # write it
"""
from __future__ import annotations
import argparse
import json
import os
import sys
import httpx
API = "https://api.osf.io/v2"
UA = {"User-Agent": "stack-osf-metadata/1.0"}
TARGETS = [("registrations", "8wq3m"), ("nodes", "bwc9n")]
TAGS = [
"LEAD model",
"ACO",
"accountable care",
"Medicare",
"CMS Innovation Center",
"living review",
"scoping review",
"systematic review",
"prognostic factors",
"health policy",
"PRISMA-ScR",
"performance year 2027",
]
LICENSE_ID = "563c1cf88c5e4a3877f9e96a" # CC-By Attribution 4.0 International
# Leaf subjects (bepress taxonomy on the OSF registration provider);
# their ancestors are added at run time, as OSF expects full paths.
LEAF_SUBJECTS = {
"584240da54be81056cecacac": "Health Services Research",
"584240da54be81056cecab1f": "Health Policy",
"584240d954be81056ceca846": "Health Economics",
}
def subject_path(client: httpx.Client, sid: str) -> list[str]:
"""``sid`` and its ancestors, root first."""
path: list[str] = []
while sid:
path.insert(0, sid)
d = client.get(f"{API}/subjects/{sid}/").raise_for_status().json()["data"]
sid = ((d["relationships"].get("parent") or {}).get("data") or {}).get("id", "")
return path
def plan(client: httpx.Client) -> dict:
subjects: list[str] = []
for sid in LEAF_SUBJECTS:
for s in subject_path(client, sid):
if s not in subjects:
subjects.append(s)
return {"tags": TAGS, "license": LICENSE_ID, "subjects": subjects}
def apply(client: httpx.Client, kind: str, guid: str, p: dict) -> None:
body = {
"data": {
"type": kind,
"id": guid,
"attributes": {"tags": p["tags"]},
"relationships": {
"license": {"data": {"type": "licenses", "id": p["license"]}}
},
}
}
client.patch(f"{API}/{kind}/{guid}/", json=body).raise_for_status()
rel = {"data": [{"type": "subjects", "id": s} for s in p["subjects"]]}
client.patch(
f"{API}/{kind}/{guid}/relationships/subjects/", json=rel
).raise_for_status()
def verify(client: httpx.Client, kind: str, guid: str) -> dict:
d = (
client.get(f"{API}/{kind}/{guid}/?embed=license")
.raise_for_status()
.json()["data"]
)
subs = (
client.get(f"{API}/{kind}/{guid}/subjects/").raise_for_status().json()["data"]
)
lic = (d.get("embeds", {}).get("license", {}).get("data") or {}).get(
"attributes", {}
)
return {
"tags": d["attributes"].get("tags"),
"license": lic.get("name"),
"subjects": sorted(s["attributes"]["text"] for s in subs),
}
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--apply", action="store_true")
args = ap.parse_args()
token = os.environ.get("OSF_TOKEN", "")
headers = dict(UA)
if token:
headers["Authorization"] = f"Bearer {token}"
with httpx.Client(headers=headers, timeout=60, follow_redirects=True) as client:
p = plan(client)
print(json.dumps(p, indent=1))
if not args.apply:
print("dry run — pass --apply to write")
return 0
if not token:
print("OSF_TOKEN is not set", file=sys.stderr)
return 2
for kind, guid in TARGETS:
apply(client, kind, guid, p)
print(kind, guid, verify(client, kind, guid))
return 0
if __name__ == "__main__":
raise SystemExit(main())

View File

@@ -0,0 +1,179 @@
# LEAD living review: self-hosted releases (BagIt + RO-Crate) and tagging quality
Date: 2026-11-11. Status: design, for review.
## Why now
COS is retiring OSF Projects. No new Projects or Components after
2026-11-15; existing Projects go read-only on 2027-02-19 (the FAQ also
says 02-18); many API GET/POST calls are deprecated from 2026-11-16.
Registrations and Preprints continue, registration metadata stays
editable, and public Registrations are backed up to the Internet
Archive (help.osf.io/article/725-faqs, updated 2026-11-06).
Our OSF footprint is small. Registration `8wq3m` (DOI
10.17605/OSF.IO/8WQ3M, "Generalized Systematic Review Registration",
2026-11-01) holds the protocol as form responses. Its source Project
`bwc9n` has no files, no wiki, no components, no tags, no subjects and
no license. Everything else in the review already lives in this stack:
the `lead` module (target registry, evidence ledger in DuckDB, claims,
gates), the PRISMA screening workflow (`stack prisma`), the bib/Zotero
corpus, and the public explorer at lead/reach.fhirworx.io.
A *living* review needs a place to post each update. After 2027-02-19
the OSF Project cannot take one. So the review's home moves into the
stack, and OSF keeps the frozen, citable protocol.
## Decisions
1. **Do not run OSF ourselves.** The osf.io docker-compose is a
development setup (develop-branch quay images, CAS, WaterButler, MFR,
Elasticsearch, RabbitMQ, Ember), there is no supported self-hosting
guide, and the product we would host is the one COS is retiring.
2. **The OSF registration stays the anchor.** It is the pre-screening
protocol record. We fill its metadata (tags, subjects, CC-BY 4.0)
with `dev/scripts/osf_metadata.py`, which also covers the Project
while it is still editable.
3. **Each review update is a release: one BagIt bag with RO-Crate
metadata inside.** BagIt gives fixity (checksummed manifests) and a
transfer format archives accept. RO-Crate gives a machine-readable
description (what each file is, how it was made, what it cites).
4. **Releases live in rustfs and are served read-only from reach.**
A Gitea release tag and a bib item (synced to Zotero) point at each.
A DOI per release via Zenodo is optional and outward-facing, so it
needs a yes each time.
## Release contents
```
lead-review-v<MAJOR.MINOR>/ BagIt 1.0, sha512 manifests
bagit.txt bag-info.txt manifest-sha512.txt tagmanifest-sha512.txt
data/
ro-crate-metadata.json RO-Crate 1.2 (see below)
protocol/registration-8wq3m.json OSF registration_responses, verbatim
protocol/protocol.md rendered, with amendments log
protocol/amendments.md dated changes since 8wq3m
search/ query strings + run logs per database (prisma)
screening/decisions.parquet per-record, per-pass decisions + reasons
screening/prisma-flow.json PRISMA 2020 / PRISMA-ScR flow counts
ledger/*.parquet evidence ledger tables (claims, gates, targets)
bibliography/included.csl.json included works (CSL-JSON from bib)
bibliography/screened.csl.json all screened records
tags/vocab-v<N>.yaml theme vocabulary used for tagging
tags/assignments.parquet item_key, theme, confidence, model, vocab version
code/stack-<sha>.tar.gz `git archive` of the commit that built it
mirror/manifest.json public-data mirror manifest the explorer serves
```
`bag-info.txt`: `Source-Organization`, `External-Identifier:
doi:10.17605/OSF.IO/8WQ3M`, `Bag-Group-Identifier: lead-living-review`,
`Bagging-Date`, `Bag-Size`, `Payload-Oxum`, `Version`, `Git-Commit`,
`Internal-Sender-Description` (one line on what changed).
Licensed works do not go in a bag: no NLM/UMLS release files, no
paywalled full texts. The bibliography carries identifiers, not PDFs.
### RO-Crate
Root `Dataset`: name, description, `version`, `datePublished`,
`license` (CC-BY-4.0), `keywords` (the OSF tags), `about` (MeSH
descriptors, see Tagging), `isBasedOn` (the registration DOI),
`hasPart` (one `File` entity per payload file with `encodingFormat`,
`contentSize`, `sha256`). A `CreateAction` records the build: the
`stack lead release build` command, the git commit, tool versions, and
the inputs (DuckDB tables, bib query). `mentions` lists cited works by
DOI or bib key.
## Commands
`stack lead release` (new subcommand group in the lead CLI):
- `build --version X.Y` writes the bag under `data/lead/releases/` from
the live ledger, prisma state and bib, using the `bagit` and `rocrate`
Python libraries. It is deterministic for a given commit and inputs.
- `verify PATH` runs BagIt validation (manifests, Payload-Oxum) and
RO-Crate checks (every payload file described, every described file
present, checksums match).
- `publish PATH` uploads to rustfs bucket `lead-releases` (one prefix
per version, never overwritten), writes the `releases/index.json` the
reach page lists, creates the Gitea release `lead-review-vX.Y`, adds a
bib `dataset` item (synced to Zotero), and re-runs `osf_metadata.py`
so the registration's metadata stays current. `--zenodo` deposits the
bag for a DOI and only runs when asked.
Fixity: a monthly systemd user timer runs `verify` on every stored
release and files a Gitea issue on any mismatch (the client now
reaches Gitea from the host).
## Tagging the record
The same controlled vocabulary drives the OSF tags, the RO-Crate
`keywords`, and the comment tagger:
- P35 themes (`src/llm/vocab/themes.yaml`, 57 slugs) are the working
vocabulary.
- Each theme gets a MeSH mapping through the local UMLS release
(`stack nlm`), stored in the vocab file; RO-Crate `about` uses the
MeSH descriptors so outside tools can read the subject.
- OSF subjects use the bepress taxonomy (Health Services Research,
Health Policy, Health Economics, with their parents).
## Tagging quality plan (comment tagger)
Where it stands (2026-11-11): 314,848 of 337,792 comments tagged on
vocab v2 / qwen2.5:14b. The golden gate now fails: micro-F1 0.68
(P 0.64, R 0.73) against the 0.70 bar, down from 0.73 on 2026-09-22.
New false positives are concentrated in shared-savings-program,
work-rvu, evaluation-management, caregiver-training and
practice-expense. 30.2% of tagged comments got no tag (5% on the golden
set). Eight dockets (about 23k comments, mostly CMS-2025-0242) were
never tagged. The golden set is 39 comments from one docket, and the
thresholds were tuned on it.
1. **Golden v2, held out.** About 25 comments from each of eight
dockets across PFS, OPPS, IPPS, DMEPOS and the non-PFS dockets, about
200 in all, labelled in a small review page modelled on the LEAD
review page. Split 50/50 into tune and held-out; the gate reads only
the held-out half.
2. **Precision fixes.** The judge prompt gets each theme's definition
plus negative examples ("mentions the conversion factor in passing"
is not about it), and it must quote the sentence that decides. Each
change is re-scored on the tune half.
3. **Abstentions.** Sample zero-tag comments per docket and sort them:
no usable body (attachment not yet extracted), form letter, or a
topic outside the vocabulary. Off-vocabulary clusters become vocab v3
themes (OPPS, IPPS and DMEPOS families); empty bodies go back to
backfill instead of the tagger.
4. **Judge model.** The rig now serves qwen2.5:32b. Score 14b and 32b
on the held-out half. If 32b clears the gate by a clear margin,
switching is a config change (the tagger is pinned to
`instruct_model` as of 735f0dc) plus a full re-tag, scheduled on the
rig with the rate measured first.
5. **Thresholds.** Per-theme minimum confidence from held-out
precision/recall curves; the three-tag cap stays.
6. **New gate.** Held-out micro-F1 ≥ 0.75; no theme with support ≥ 5
under 0.6 precision; corpus abstain rate ≤ 15% on a stratified
sample. Fan-out to the eight untouched dockets (embed first with
`stack llm index --collection comments --docket ...`) waits for it.
7. **Snapshots in releases.** Each release bag carries the vocab and the
tag assignments it was built with, so a tag on a published claim can
be traced to the model, vocab version and evidence chunk.
## Phasing
1. OSF metadata on 8wq3m and bwc9n (script ready; needs `OSF_TOKEN`).
Before 2027-02-19 for the Project.
2. `stack lead release build/verify` with the protocol, screening,
ledger and bibliography; v0.1 built and verified locally.
3. `publish`: rustfs bucket, reach `/releases/` page, Gitea release,
bib item, fixity timer.
4. Golden v2 and the held-out gate (tagging steps 1–2), then steps 3–6.
5. Optional Zenodo deposit per release.
## Open questions
- CC-BY 4.0 for the record and releases (chosen here; CC0 is the
alternative for data-only payloads).
- Zenodo DOIs per release, or the OSF DOI plus versioned URLs on reach.
- Whether reach should require SSO for `/releases/` (the bags hold only
public-data derivatives, so this design serves them publicly).