Archive 4 checkpoints (1-4)
Browse files- paper-releases/pbisc-diffusion/updates/20260929T062828Z-manuscript-relocation/diffusion/dataset/server_1/maintenance/26f3248763a2f99b/POLICY.md +60 -0
- paper-releases/pbisc-diffusion/updates/20260929T062828Z-manuscript-relocation/diffusion/dataset/server_1/maintenance/38e4c628399ccf84/update.py +772 -0
- paper-releases/pbisc-diffusion/updates/20260929T062828Z-manuscript-relocation/diffusion/dataset/server_1/maintenance/8f31479db9f9cb1d/SCOPE.json +0 -0
- paper-releases/pbisc-diffusion/updates/20260929T062828Z-manuscript-relocation/diffusion/dataset/server_1/manuscript/AGENTS.md +20 -0
paper-releases/pbisc-diffusion/updates/20260929T062828Z-manuscript-relocation/diffusion/dataset/server_1/maintenance/26f3248763a2f99b/POLICY.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PBISC-Diffusion paper archive maintenance
|
| 2 |
+
|
| 3 |
+
Project ID: **`pbisc-diffusion`**. User standing instruction, 2026-09-28: keep this paper archive updated across **Codex and Claude Code**, and do not mix in any other paper.
|
| 4 |
+
|
| 5 |
+
## Scope gate — apply this before doing anything
|
| 6 |
+
|
| 7 |
+
This policy applies only to work explicitly for the PBISC-Diffusion paper:
|
| 8 |
+
|
| 9 |
+
- Model 8 source, training/fine-tuning, inference, evaluation, figures and reproducibility: `/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion/`.
|
| 10 |
+
- Its named manuscript: `/home/sj_server_1/PBISC/paper-release-20260928/manuscript/` (a Git working tree of `junidude/PBISC-diffusion-overleaf`, whose README identifies PBISC-Diffusion). It was moved there from `/home/sj_server_1/PBISC/immun-pbmc-fm/bulk2sc-paper/nature-communications-overleaf/` on 2026-09-29 at the user's request; its superseded drafts are in the sibling `archived-analyses/`, which is not an archive payload root.
|
| 11 |
+
- Exact shared dependencies listed in `SCOPE.json`, with a documented relationship to this paper. A shared dependency does not bring its directory, its other uses, or another paper into scope. New external dependencies require evidence of the Model 8/manuscript relationship and a deliberate exact-path scope addition.
|
| 12 |
+
|
| 13 |
+
Do **not** treat all PBISC work as this paper. VAE/BIBM papers, independent Model 7 work, historical `model/diffusion` / coalescent, other `bulk2sc-paper` subdirectories, transcriptome/FM papers and unrelated datalake analyses are outside scope. A generic PBISC mention is not enough to infer the paper. The old archived-diffusion wording concerns the historical coalescent branch, not the active Model 8 paper.
|
| 14 |
+
|
| 15 |
+
## Shared start/end contract for both agents
|
| 16 |
+
|
| 17 |
+
At the start of an in-scope task, read this policy, `SCOPE.json`, and `../LATEST.json` if present; otherwise use `BASELINE_REFERENCE.json`. Consult `../CURRENT.md` and the current model/inference catalogs before retrieving results. Check source host as well as absolute path: identical paths exist on both servers.
|
| 18 |
+
|
| 19 |
+
Before finishing an in-scope task that changes paper evidence or reusable assets:
|
| 20 |
+
|
| 21 |
+
1. Identify exact new or changed checkpoints, data/preprocessing inputs, splits/QC/masks/units, evaluation references, scripts/configs, score tables, figures or manuscript files. Include provenance tying them to this paper. Do not glob the whole workspace.
|
| 22 |
+
2. Write a request using `request.example.json`. Use `project_id: pbisc-diffusion`; name each source host/path, artifact kind and actual state. Register training/inference that is still running as a location/status observation; do not publish actively changing payload files as completed. Immutable stopped/intermediate checkpoints may be archived with that state retained.
|
| 23 |
+
3. Record **new inference output locations**, recorded output/checkpoint/input hashes and receipt paths. Preserve the distinction between presence-only, running, failed and completed evidence. Normally keep large inference arrays in their existing locations; do not rerun inference for bookkeeping or erase/overwrite earlier paper outputs.
|
| 24 |
+
4. Prepare and publish the versioned delta with the shared CLI. This is a standing user-authorized maintenance step for this paper's completed assets. Continue it within the task; do not merely promise a later upload. Keep cohort/sample metadata and paper-support files in private `junidude14/PBISC-data`; eligible Model 8 checkpoint weights use the existing gated `junidude14/PBISC` repository.
|
| 25 |
+
5. Check the verified receipt, refreshed current catalogs and latest pointer before claiming the archive is current. If a file is still changing, a transfer/verification fails, or a dependency is unresolved, retain the pending update and report the exact gap. Never advance latest or claim completion from a dry preflight.
|
| 26 |
+
|
| 27 |
+
A read-only discussion with no changed assets requires no duplicate upload. Explicitly report “no archive delta” when relevant. Manuscript evidence/figures are not automatically changed merely because a checkpoint was saved; only preserve actually revised, supported content. No automatic GitHub push or Overleaf synchronization is implied.
|
| 28 |
+
|
| 29 |
+
## One archive, immutable history, current views
|
| 30 |
+
|
| 31 |
+
- Coordinator and small local records: `spark-fa6b:/home/sj_server_1/PBISC/paper-release-20260928/`.
|
| 32 |
+
- Independent physical archive: `spark-0110:/home/sj_server_2/PBISC/paper-release-20260928/`.
|
| 33 |
+
- Frozen initial snapshot: existing root manifests, receipts, `README.md`, `RELEASE_LOCK.json`, `FINAL_VERIFICATION.json`, and HF tag **`paper-20260928`**. Keep them intact; do not rerun the date-specific preparation/finalization scripts to update the paper.
|
| 34 |
+
- Later versions: `updates/<UTC-id>/`. New HF paths are under **`paper-releases/pbisc-diffusion/updates/<id>/diffusion/`**. Previous objects and tags remain unchanged.
|
| 35 |
+
- `LATEST.json` and current catalogs are live navigation. Latest advances only after independent archive and pinned HF verification. A delta refers back to its parent and the initial baseline; it is not a complete replacement of all earlier payloads.
|
| 36 |
+
|
| 37 |
+
## Commands and cross-server coordination
|
| 38 |
+
|
| 39 |
+
Only server_1 publishes; the common writer lock prevents Codex and Claude from publishing simultaneously. Keep credentials on server_1. The request is ordinary JSON without tokens.
|
| 40 |
+
|
| 41 |
+
On server_1:
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
/home/sj_server_1/miniforge3/bin/python /home/sj_server_1/PBISC/paper-release-20260928/maintenance/update.py status
|
| 45 |
+
/home/sj_server_1/miniforge3/bin/python /home/sj_server_1/PBISC/paper-release-20260928/maintenance/update.py prepare --request /path/to/request.json --id 20260929T010000Z-result-name
|
| 46 |
+
/home/sj_server_1/miniforge3/bin/python /home/sj_server_1/PBISC/paper-release-20260928/maintenance/update.py publish 20260929T010000Z-result-name --execute
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
For work on server_2, submit the request to the coordinator through standard input:
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
ssh spark-fa6b '/home/sj_server_1/miniforge3/bin/python /home/sj_server_1/PBISC/paper-release-20260928/maintenance/update.py prepare --request - --id 20260929T010000Z-result-name' < request.json
|
| 53 |
+
ssh spark-fa6b '/home/sj_server_1/miniforge3/bin/python /home/sj_server_1/PBISC/paper-release-20260928/maintenance/update.py publish 20260929T010000Z-result-name --execute'
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
Use an actual UTC timestamp and a descriptive slug, not the example ID. Mark remote sources `host: server_2`; their working tree may still start with `/home/sj_server_1/PBISC/`. The SSH path was verified in both directions when installing this workflow. If connectivity fails, preserve a pending request and report it; do not copy authentication tokens or invent a successful sync.
|
| 57 |
+
|
| 58 |
+
Hashing/copying is CPU-only. Follow the mandatory host GPU/UMA policy for any substantial-memory launch, and run sustained transfer work with bounded user-systemd memory, zero swap and no automatic restart. Do not initialize CUDA, launch training/inference, interrupt another job, delete originals or replace existing results for archive maintenance.
|
| 59 |
+
|
| 60 |
+
This is a **task-end maintenance workflow**, not an unattended periodic upload daemon. A future timer may detect candidates, but cannot decide that unrelated or unfinished work belongs to this paper.
|
paper-releases/pbisc-diffusion/updates/20260929T062828Z-manuscript-relocation/diffusion/dataset/server_1/maintenance/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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Scoped, CPU-only incremental PBISC-diffusion publication.
|
| 3 |
+
|
| 4 |
+
Prepare is local (server_2 source metadata requires SSH). Publish is explicit and
|
| 5 |
+
uses the frozen paper publisher in a fresh process. No GPU work is started.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import argparse
|
| 10 |
+
import fcntl
|
| 11 |
+
import hashlib
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
from pathlib import Path, PurePosixPath
|
| 15 |
+
import re
|
| 16 |
+
import shlex
|
| 17 |
+
import stat
|
| 18 |
+
import subprocess
|
| 19 |
+
import sys
|
| 20 |
+
import tempfile
|
| 21 |
+
from typing import Any, Callable
|
| 22 |
+
|
| 23 |
+
ROOT = Path(__file__).resolve().parent.parent
|
| 24 |
+
CORE_ROOTS = {
|
| 25 |
+
'model8': Path('/home/sj_server_1/PBISC/immun-pbmc-fm/model_8_sparse_data_diffusion'),
|
| 26 |
+
'manuscript': Path('/home/sj_server_1/PBISC/paper-release-20260928/manuscript'),
|
| 27 |
+
}
|
| 28 |
+
REMOTE = 'spark-0110'
|
| 29 |
+
REMOTE_ROOT = '/home/sj_server_2/PBISC/paper-release-20260928'
|
| 30 |
+
PREFIX = 'paper-releases/pbisc-diffusion'
|
| 31 |
+
ID_RE = re.compile(r'[0-9]{8}T[0-9]{6}Z-[a-z0-9-]+\Z')
|
| 32 |
+
SHA_RE = re.compile(r'[0-9a-f]{64}\Z')
|
| 33 |
+
STATES = {'completed', 'final', 'intermediate', 'stopped'}
|
| 34 |
+
LOCATOR_STATES = STATES | {'running', 'planned', 'failed', 'presence_only'}
|
| 35 |
+
FORBIDDEN = {'.git', '.venv', 'venv', 'runtime_env', '__pycache__', 'node_modules', 'Rlib', '.cache'}
|
| 36 |
+
NON_PAYLOAD_KINDS = {'output', 'outputs', 'generated', 'inference', 'sample', 'samples', 'prediction', 'predictions'}
|
| 37 |
+
ALLOWED_KINDS = {'checkpoint', 'condition', 'code', 'manuscript', 'data', 'metadata',
|
| 38 |
+
'report', 'figure', 'table', 'log', 'provenance', 'maintenance',
|
| 39 |
+
'policy', 'config', 'test', 'document'}
|
| 40 |
+
MAINTENANCE_FILES = {'POLICY.md', 'SCOPE.json', 'update.py', 'test_update.py',
|
| 41 |
+
'catalog.py', 'test_catalog.py', 'CURRENT.md', 'request.example.json'}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class UpdateError(Exception):
|
| 45 |
+
pass
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _json(path: Path) -> Any:
|
| 49 |
+
return json.loads(path.read_text(encoding='utf-8'))
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def _bytes(value: Any) -> bytes:
|
| 53 |
+
return (json.dumps(value, sort_keys=True, indent=2, ensure_ascii=False) + '\n').encode()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _atomic(path: Path, data: bytes) -> None:
|
| 57 |
+
if path.is_symlink() or path.parent.is_symlink():
|
| 58 |
+
raise UpdateError('unsafe_output_path')
|
| 59 |
+
path.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
| 60 |
+
with tempfile.NamedTemporaryFile(dir=path.parent, prefix='.owned-', delete=False) as stream:
|
| 61 |
+
temporary = Path(stream.name)
|
| 62 |
+
stream.write(data)
|
| 63 |
+
stream.flush()
|
| 64 |
+
os.fsync(stream.fileno())
|
| 65 |
+
try:
|
| 66 |
+
os.replace(temporary, path)
|
| 67 |
+
finally:
|
| 68 |
+
temporary.unlink(missing_ok=True)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def _path(value: Any, host: str) -> Path:
|
| 72 |
+
if not isinstance(value, str) or not value.startswith('/') or '\\' in value or any(ord(c) < 32 for c in value):
|
| 73 |
+
raise UpdateError('invalid_source_path')
|
| 74 |
+
path = PurePosixPath(value)
|
| 75 |
+
if str(path) != value or any(part in ('.', '..') for part in path.parts):
|
| 76 |
+
raise UpdateError('invalid_source_path')
|
| 77 |
+
allowed_homes = ('/home/sj_server_1/',) if host == 'server_1' else ('/home/sj_server_1/', '/home/sj_server_2/')
|
| 78 |
+
if not value.startswith(allowed_homes):
|
| 79 |
+
raise UpdateError('wrong_source_host')
|
| 80 |
+
return Path(value)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _safe_local(path: Path) -> None:
|
| 84 |
+
current = Path('/')
|
| 85 |
+
for part in path.parts[1:]:
|
| 86 |
+
current /= part
|
| 87 |
+
if current.is_symlink():
|
| 88 |
+
raise UpdateError('source_symlink_refused')
|
| 89 |
+
st = path.lstat()
|
| 90 |
+
if not stat.S_ISREG(st.st_mode):
|
| 91 |
+
raise UpdateError('source_not_regular')
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def _scope(root: Path) -> dict[str, Any]:
|
| 95 |
+
maintenance = root / 'maintenance'
|
| 96 |
+
if maintenance.is_symlink() or maintenance.resolve() != maintenance:
|
| 97 |
+
raise UpdateError('unsafe_maintenance_root')
|
| 98 |
+
if (maintenance / 'SCOPE.json').is_symlink():
|
| 99 |
+
raise UpdateError('unsafe_scope_file')
|
| 100 |
+
scope = _json(maintenance / 'SCOPE.json')
|
| 101 |
+
if not isinstance(scope, dict) or scope.get('project_id') != 'pbisc-diffusion':
|
| 102 |
+
raise UpdateError('wrong_project_scope')
|
| 103 |
+
if scope.get('core_roots') != {k: str(v) for k, v in CORE_ROOTS.items()}:
|
| 104 |
+
raise UpdateError('wrong_core_roots')
|
| 105 |
+
if scope.get('maintenance_root') != str(maintenance):
|
| 106 |
+
raise UpdateError('wrong_maintenance_root')
|
| 107 |
+
forbidden = scope.get('forbidden_components')
|
| 108 |
+
if not isinstance(forbidden, list) or not FORBIDDEN.issubset(set(forbidden)):
|
| 109 |
+
raise UpdateError('missing_forbidden_components')
|
| 110 |
+
dependencies = scope.get('external_dependencies')
|
| 111 |
+
if not isinstance(dependencies, list):
|
| 112 |
+
raise UpdateError('invalid_dependencies')
|
| 113 |
+
for item in dependencies:
|
| 114 |
+
if (not isinstance(item, dict) or item.get('host') not in ('server_1', 'server_2')
|
| 115 |
+
or not isinstance(item.get('reason'), str) or not item['reason'].strip()):
|
| 116 |
+
raise UpdateError('invalid_dependency')
|
| 117 |
+
_path(item.get('source'), item['host'])
|
| 118 |
+
return scope
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def _allow(path: Path, host: str, scope: dict[str, Any], *, internal: Path | None = None) -> str:
|
| 122 |
+
if any(part in set(scope['forbidden_components']) for part in path.parts):
|
| 123 |
+
raise UpdateError('forbidden_component')
|
| 124 |
+
if internal is not None and host == 'server_1' and path.is_relative_to(internal):
|
| 125 |
+
return 'internal'
|
| 126 |
+
if host == 'server_1' and path.parent == Path(scope['maintenance_root']) and path.name in MAINTENANCE_FILES:
|
| 127 |
+
return 'maintenance'
|
| 128 |
+
for name, root in CORE_ROOTS.items():
|
| 129 |
+
if path.is_relative_to(root) and path != root:
|
| 130 |
+
return name
|
| 131 |
+
if any(item['host'] == host and item['source'] == str(path)
|
| 132 |
+
for item in scope['external_dependencies']):
|
| 133 |
+
return 'dependency'
|
| 134 |
+
raise UpdateError('source_outside_project_scope')
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def _publisher():
|
| 138 |
+
sys.path.insert(0, str(ROOT / 'tools'))
|
| 139 |
+
import publish_paper_assets as paper
|
| 140 |
+
return paper
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def _remote_stat(path: Path) -> dict[str, int]:
|
| 144 |
+
code = '''import json,os,stat,sys
|
| 145 |
+
p=sys.argv[1]; q='/'
|
| 146 |
+
for part in p.strip('/').split('/'):
|
| 147 |
+
q=os.path.join(q,part)
|
| 148 |
+
if os.path.islink(q): raise SystemExit(2)
|
| 149 |
+
s=os.lstat(p)
|
| 150 |
+
if not stat.S_ISREG(s.st_mode): raise SystemExit(2)
|
| 151 |
+
print(json.dumps(dict(dev=s.st_dev,ino=s.st_ino,size=s.st_size,mtime_ns=s.st_mtime_ns)))'''
|
| 152 |
+
result = subprocess.run(['ssh', '-o', 'BatchMode=yes', REMOTE,
|
| 153 |
+
shlex.join(['python3', '-B', '-c', code, str(path)])],
|
| 154 |
+
capture_output=True, text=True, check=False)
|
| 155 |
+
if result.returncode:
|
| 156 |
+
raise UpdateError('remote_source_unavailable')
|
| 157 |
+
return json.loads(result.stdout)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _locator_stat(path: Path, host: str) -> dict[str, Any]:
|
| 161 |
+
"""Observe a locator without hashing large generated outputs."""
|
| 162 |
+
if host == 'server_1':
|
| 163 |
+
current = Path('/')
|
| 164 |
+
for part in path.parts[1:]:
|
| 165 |
+
current /= part
|
| 166 |
+
if current.is_symlink():
|
| 167 |
+
raise UpdateError('locator_symlink_refused')
|
| 168 |
+
if not current.exists():
|
| 169 |
+
return {'presence': 'missing_unverified'}
|
| 170 |
+
st = path.lstat()
|
| 171 |
+
return {'presence': 'observed', 'kind': 'file' if stat.S_ISREG(st.st_mode) else 'directory' if stat.S_ISDIR(st.st_mode) else 'other',
|
| 172 |
+
'stat': {'dev': st.st_dev, 'ino': st.st_ino, 'size': st.st_size, 'mtime_ns': st.st_mtime_ns}}
|
| 173 |
+
code = '''import json,os,stat,sys
|
| 174 |
+
p=sys.argv[1]; q='/'
|
| 175 |
+
for part in p.strip('/').split('/'):
|
| 176 |
+
q=os.path.join(q,part)
|
| 177 |
+
if os.path.islink(q): raise SystemExit(2)
|
| 178 |
+
if not os.path.exists(q):
|
| 179 |
+
print(json.dumps({'presence':'missing_unverified'})); raise SystemExit(0)
|
| 180 |
+
s=os.lstat(p)
|
| 181 |
+
k='file' if stat.S_ISREG(s.st_mode) else 'directory' if stat.S_ISDIR(s.st_mode) else 'other'
|
| 182 |
+
print(json.dumps({'presence':'observed','kind':k,'stat':dict(dev=s.st_dev,ino=s.st_ino,size=s.st_size,mtime_ns=s.st_mtime_ns)}))'''
|
| 183 |
+
result = subprocess.run(['ssh', '-o', 'BatchMode=yes', REMOTE,
|
| 184 |
+
shlex.join(['python3', '-B', '-c', code, str(path)])],
|
| 185 |
+
capture_output=True, text=True, check=False)
|
| 186 |
+
if result.returncode:
|
| 187 |
+
raise UpdateError('remote_locator_unavailable')
|
| 188 |
+
return json.loads(result.stdout)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def _row(host: str, path: Path, kind: str, identifier: str, scope: dict[str, Any]) -> dict[str, Any]:
|
| 192 |
+
area = _allow(path, host, scope)
|
| 193 |
+
if host == 'server_1':
|
| 194 |
+
_safe_local(path)
|
| 195 |
+
snap = _publisher().base.snapshot(path.lstat()) if host == 'server_1' else _remote_stat(path)
|
| 196 |
+
if kind == 'checkpoint' and area != 'model8':
|
| 197 |
+
raise UpdateError('checkpoint_outside_model8')
|
| 198 |
+
if kind == 'checkpoint' and path.suffix.lower() not in {'.pt', '.pth', '.safetensors'}:
|
| 199 |
+
raise UpdateError('checkpoint_extension_refused')
|
| 200 |
+
if kind == 'condition' and path.suffix.lower() != '.npz':
|
| 201 |
+
raise UpdateError('condition_requires_npz')
|
| 202 |
+
if kind not in ALLOWED_KINDS:
|
| 203 |
+
raise UpdateError('generated_payload_refused')
|
| 204 |
+
if (area == 'maintenance') != (kind == 'maintenance'):
|
| 205 |
+
raise UpdateError('maintenance_kind_scope')
|
| 206 |
+
if kind not in {'checkpoint', 'condition'} and any(part.lower() in NON_PAYLOAD_KINDS for part in path.parts):
|
| 207 |
+
raise UpdateError('generated_payload_refused')
|
| 208 |
+
root = CORE_ROOTS.get(area)
|
| 209 |
+
relative = path.relative_to(root) if root is not None else Path(hashlib.sha256(str(path).encode()).hexdigest()[:16]) / path.name
|
| 210 |
+
bundle = PurePosixPath('updates') / identifier / 'diffusion' / ('model' if kind == 'checkpoint' else 'dataset') / host / area / PurePosixPath(*relative.parts)
|
| 211 |
+
repo_type = 'model' if kind == 'checkpoint' else 'dataset'
|
| 212 |
+
repo_id = 'junidude14/PBISC' if repo_type == 'model' else 'junidude14/PBISC-data'
|
| 213 |
+
row = {'host': host, 'source': str(path), 'bundle_path': str(bundle), 'repo_type': repo_type,
|
| 214 |
+
'repo_id': repo_id, 'remote_path': str(PurePosixPath(PREFIX) / bundle),
|
| 215 |
+
'bytes': snap['size'], 'expected_stat': snap, 'category': kind}
|
| 216 |
+
row['sha256'] = _publisher().source_digest(row)
|
| 217 |
+
return row
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def _history(root: Path) -> dict[tuple[str, str], str]:
|
| 221 |
+
seen = {}
|
| 222 |
+
baseline = root / 'COMBINED_ASSET_INDEX.json'
|
| 223 |
+
if baseline.exists():
|
| 224 |
+
for row in _json(baseline).get('assets', []):
|
| 225 |
+
seen[row['host'], row['source']] = row['sha256']
|
| 226 |
+
pointer = _latest(root)
|
| 227 |
+
chain = []
|
| 228 |
+
visited = set()
|
| 229 |
+
while pointer is not None:
|
| 230 |
+
identifier = pointer.get('id') if isinstance(pointer, dict) else None
|
| 231 |
+
if not isinstance(identifier, str) or not ID_RE.fullmatch(identifier) or identifier in visited:
|
| 232 |
+
raise UpdateError('invalid_latest_chain')
|
| 233 |
+
visited.add(identifier)
|
| 234 |
+
path = root / 'maintenance' / 'updates' / identifier / 'UPDATE_VERIFIED.json'
|
| 235 |
+
if path.is_symlink():
|
| 236 |
+
raise UpdateError('unsafe_verified_receipt')
|
| 237 |
+
verified = _json(path)
|
| 238 |
+
if (verified.get('status') != 'PASS' or verified.get('update_id') != identifier
|
| 239 |
+
or pointer.get('verified_receipt_sha256') != hashlib.sha256(path.read_bytes()).hexdigest()):
|
| 240 |
+
raise UpdateError('invalid_latest_chain')
|
| 241 |
+
chain.append(verified)
|
| 242 |
+
pointer = verified.get('parent_latest')
|
| 243 |
+
for verified in reversed(chain):
|
| 244 |
+
for row in verified.get('assets', []):
|
| 245 |
+
seen[row['host'], row['source']] = row['sha256']
|
| 246 |
+
return seen
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def _latest(root: Path) -> dict[str, Any] | None:
|
| 250 |
+
path = root / 'LATEST.json'
|
| 251 |
+
if path.is_symlink():
|
| 252 |
+
raise UpdateError('unsafe_latest_pointer')
|
| 253 |
+
return _json(path) if path.exists() else None
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def _metadata_row(path: Path, identifier: str, name: str) -> dict[str, Any]:
|
| 257 |
+
_safe_local(path)
|
| 258 |
+
paper = _publisher()
|
| 259 |
+
snap = paper.base.snapshot(path.lstat())
|
| 260 |
+
with paper.base.open_source(path, snap) as stream:
|
| 261 |
+
digest = paper.base.hash_source(path, stream, snap)
|
| 262 |
+
bundle = str(PurePosixPath('updates') / identifier / 'diffusion' / 'metadata' / name)
|
| 263 |
+
return dict(host='server_1', source=str(path), bundle_path=bundle,
|
| 264 |
+
repo_type='dataset', repo_id='junidude14/PBISC-data',
|
| 265 |
+
remote_path=str(PurePosixPath(PREFIX) / bundle), bytes=snap['size'],
|
| 266 |
+
expected_stat=snap, sha256=digest['sha256'], category='update_metadata')
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def prepare(root: Path, request: dict[str, Any], identifier: str) -> Path:
|
| 270 |
+
root = root.absolute()
|
| 271 |
+
if not ID_RE.fullmatch(identifier):
|
| 272 |
+
raise UpdateError('invalid_update_id')
|
| 273 |
+
scope = _scope(root)
|
| 274 |
+
if not isinstance(request, dict) or request.get('project_id') != 'pbisc-diffusion':
|
| 275 |
+
raise UpdateError('wrong_request_project')
|
| 276 |
+
summary = request.get('summary')
|
| 277 |
+
if not isinstance(summary, str) or not summary.strip():
|
| 278 |
+
raise UpdateError('summary_required')
|
| 279 |
+
assets, locations = request.get('assets'), request.get('inference_locations')
|
| 280 |
+
if not isinstance(assets, list) or not isinstance(locations, list):
|
| 281 |
+
raise UpdateError('invalid_request_lists')
|
| 282 |
+
parent = _latest(root)
|
| 283 |
+
rows = []
|
| 284 |
+
observed = _history(root)
|
| 285 |
+
seen_sources = set()
|
| 286 |
+
for item in assets:
|
| 287 |
+
if not isinstance(item, dict) or item.get('host') not in ('server_1', 'server_2'):
|
| 288 |
+
raise UpdateError('invalid_asset')
|
| 289 |
+
if item.get('state') not in STATES:
|
| 290 |
+
raise UpdateError('payload_state_refused')
|
| 291 |
+
host, kind = item['host'], item.get('kind')
|
| 292 |
+
if not isinstance(kind, str):
|
| 293 |
+
raise UpdateError('invalid_kind')
|
| 294 |
+
path = _path(item.get('source'), host)
|
| 295 |
+
if (host, str(path)) in seen_sources:
|
| 296 |
+
raise UpdateError('duplicate_source')
|
| 297 |
+
seen_sources.add((host, str(path)))
|
| 298 |
+
row = _row(host, path, kind, identifier, scope)
|
| 299 |
+
if observed.get((host, str(path))) != row['sha256']:
|
| 300 |
+
row['state'] = item['state']
|
| 301 |
+
rows.append(row)
|
| 302 |
+
checked_locations = []
|
| 303 |
+
for item in locations:
|
| 304 |
+
if not isinstance(item, dict) or item.get('host') not in ('server_1', 'server_2'):
|
| 305 |
+
raise UpdateError('invalid_inference_location')
|
| 306 |
+
if item.get('state') not in LOCATOR_STATES:
|
| 307 |
+
raise UpdateError('invalid_inference_state')
|
| 308 |
+
host = item['host']
|
| 309 |
+
path = _path(item.get('path'), host)
|
| 310 |
+
_allow(path, host, scope)
|
| 311 |
+
receipt = item.get('receipt')
|
| 312 |
+
output_observation = _locator_stat(path, host)
|
| 313 |
+
receipt_observation = None
|
| 314 |
+
if receipt is not None:
|
| 315 |
+
receipt_path = _path(receipt, host)
|
| 316 |
+
_allow(receipt_path, host, scope)
|
| 317 |
+
receipt_observation = _locator_stat(receipt_path, host)
|
| 318 |
+
if item['state'] in {'completed', 'final'}:
|
| 319 |
+
if (output_observation.get('kind') != 'file' or receipt_observation is None
|
| 320 |
+
or receipt_observation.get('kind') != 'file'):
|
| 321 |
+
raise UpdateError('completed_locator_evidence_missing')
|
| 322 |
+
sha = item.get('sha256')
|
| 323 |
+
if sha is not None and (not isinstance(sha, str) or not SHA_RE.fullmatch(sha)):
|
| 324 |
+
raise UpdateError('invalid_locator_sha256')
|
| 325 |
+
basis = 'existing_receipt' if receipt_observation and receipt_observation.get('kind') == 'file' else 'presence_unverified'
|
| 326 |
+
checked_locations.append(dict(item, observed_output=output_observation,
|
| 327 |
+
observed_receipt=receipt_observation,
|
| 328 |
+
sha_basis=basis, sha256_basis=basis))
|
| 329 |
+
if not rows and not checked_locations:
|
| 330 |
+
raise UpdateError('no_changed_assets')
|
| 331 |
+
updates_root = root / 'maintenance' / 'updates'
|
| 332 |
+
if updates_root.is_symlink():
|
| 333 |
+
raise UpdateError('unsafe_updates_root')
|
| 334 |
+
folder = updates_root / identifier
|
| 335 |
+
if folder.exists():
|
| 336 |
+
raise UpdateError('update_id_exists')
|
| 337 |
+
folder.mkdir(mode=0o700, parents=True)
|
| 338 |
+
_atomic(folder / 'request.json', _bytes(request))
|
| 339 |
+
_atomic(folder / 'inference_locations.json', _bytes({'project_id': 'pbisc-diffusion',
|
| 340 |
+
'update_id': identifier, 'locations': checked_locations}))
|
| 341 |
+
note = f'# PBISC-diffusion update {identifier}\n\n{summary.strip()}\n\nPayload states are recorded as supplied. Inference locations are pointers, not archived generated outputs.\n'
|
| 342 |
+
_atomic(folder / 'NOTE.md', note.encode())
|
| 343 |
+
rows.extend([_metadata_row(folder / 'request.json', identifier, 'request.json'),
|
| 344 |
+
_metadata_row(folder / 'inference_locations.json', identifier, 'inference_locations.json'),
|
| 345 |
+
_metadata_row(folder / 'NOTE.md', identifier, 'NOTE.md')])
|
| 346 |
+
if len({r['bundle_path'] for r in rows}) != len(rows):
|
| 347 |
+
raise UpdateError('duplicate_bundle_path')
|
| 348 |
+
manifest = {'schema': 'pbisc.diffusion.update-manifest.v1', 'project_id': 'pbisc-diffusion',
|
| 349 |
+
'update_id': identifier, 'parent_latest': parent, 'assets': rows}
|
| 350 |
+
_atomic(folder / 'manifest.json', _bytes(manifest))
|
| 351 |
+
_atomic(folder / 'STATUS.json', _bytes({'phase': 'prepared', 'update_id': identifier}))
|
| 352 |
+
return folder
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def _run_publisher(root: Path, identifier: str, manifest: Path, work: Path) -> int:
|
| 356 |
+
code = ("import sys; from pathlib import Path; "
|
| 357 |
+
"sys.path.insert(0,str(Path(sys.argv[1]))); import publish_paper_assets as p; "
|
| 358 |
+
"p.PREFIX=sys.argv[2]; sys.exit(p.main([sys.argv[3],'--phase','all',"
|
| 359 |
+
"'--work-dir',sys.argv[4],'--execute']))")
|
| 360 |
+
prefix = str(PurePosixPath(PREFIX) / 'updates' / identifier)
|
| 361 |
+
result = subprocess.run([sys.executable, '-B', '-c', code, str(root / 'tools'), prefix,
|
| 362 |
+
str(manifest), str(work)], check=False)
|
| 363 |
+
return result.returncode
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def _remote_latest(value: dict[str, Any] | None = None,
|
| 367 |
+
expected: dict[str, Any] | None = None) -> dict[str, Any] | None:
|
| 368 |
+
code = '''import fcntl,json,os,sys,tempfile
|
| 369 |
+
from pathlib import Path
|
| 370 |
+
p=Path('/home/sj_server_2/PBISC/paper-release-20260928/LATEST.json')
|
| 371 |
+
if len(sys.argv)==1:
|
| 372 |
+
print(p.read_text() if p.exists() else 'null')
|
| 373 |
+
else:
|
| 374 |
+
if p.is_symlink() or not p.parent.is_dir(): raise SystemExit(2)
|
| 375 |
+
request=json.load(sys.stdin)
|
| 376 |
+
lock=p.parent/'.latest.writer.lock'
|
| 377 |
+
if lock.is_symlink(): raise SystemExit(2)
|
| 378 |
+
with lock.open('a') as guard:
|
| 379 |
+
fcntl.flock(guard,fcntl.LOCK_EX)
|
| 380 |
+
current=json.loads(p.read_text()) if p.exists() else None
|
| 381 |
+
if current!=request['expected'] and current!=request['value']: raise SystemExit(3)
|
| 382 |
+
if current!=request['value']:
|
| 383 |
+
with tempfile.NamedTemporaryFile(mode='w',dir=p.parent,prefix='.latest-',delete=False) as f:
|
| 384 |
+
json.dump(request['value'],f,sort_keys=True); f.write('\\n'); f.flush(); os.fsync(f.fileno()); name=f.name
|
| 385 |
+
os.replace(name,p)
|
| 386 |
+
print('ok')'''
|
| 387 |
+
command = shlex.join(['python3', '-B', '-c', code] + (['write'] if value is not None else []))
|
| 388 |
+
result = subprocess.run(['ssh', '-o', 'BatchMode=yes', REMOTE, command],
|
| 389 |
+
input=_bytes({'expected': expected, 'value': value}).decode() if value is not None else None,
|
| 390 |
+
capture_output=True, text=True, check=False)
|
| 391 |
+
if result.returncode:
|
| 392 |
+
raise UpdateError('remote_latest_failed')
|
| 393 |
+
return None if value is not None else json.loads(result.stdout)
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
def _hf_api():
|
| 397 |
+
os.environ['HF_HUB_ENABLE_HF_TRANSFER'] = '0'
|
| 398 |
+
os.environ['HF_HUB_DISABLE_XET'] = '1'
|
| 399 |
+
from huggingface_hub import HfApi, get_token
|
| 400 |
+
from huggingface_hub import constants
|
| 401 |
+
constants.HF_HUB_ENABLE_HF_TRANSFER = False
|
| 402 |
+
constants.HF_HUB_DISABLE_XET = True
|
| 403 |
+
if not get_token():
|
| 404 |
+
raise UpdateError('existing_hf_auth_missing')
|
| 405 |
+
return HfApi(token=True)
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def _hf_latest(api: Any) -> dict[str, Any] | None:
|
| 409 |
+
from huggingface_hub import hf_hub_download
|
| 410 |
+
path = PREFIX + '/LATEST.json'
|
| 411 |
+
head = api.repo_info(repo_id='junidude14/PBISC-data', repo_type='dataset', revision='main').sha
|
| 412 |
+
try:
|
| 413 |
+
file = hf_hub_download(repo_id='junidude14/PBISC-data', repo_type='dataset',
|
| 414 |
+
filename=path, revision=head, token=True)
|
| 415 |
+
except Exception as exc:
|
| 416 |
+
# Absence is allowed only when the path is absent in the pinned tree.
|
| 417 |
+
if _publisher().base.remote_file(api, 'junidude14/PBISC-data', 'dataset', path, head) is None:
|
| 418 |
+
return None
|
| 419 |
+
raise UpdateError('hf_latest_read_failed') from exc
|
| 420 |
+
return json.loads(Path(file).read_text(encoding='utf-8'))
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
def _hf_upload_verified(api: Any, path: Path, remote_path: str, *,
|
| 424 |
+
mutable: bool = False, expected_parent: dict[str, Any] | None = None) -> str:
|
| 425 |
+
digest = hashlib.sha256(path.read_bytes()).hexdigest()
|
| 426 |
+
from huggingface_hub import CommitOperationAdd, hf_hub_download
|
| 427 |
+
repo = 'junidude14/PBISC-data'
|
| 428 |
+
head = api.repo_info(repo_id=repo, repo_type='dataset', revision='main').sha
|
| 429 |
+
found = _publisher().base.remote_file(api, repo, 'dataset', remote_path, head)
|
| 430 |
+
if found is not None:
|
| 431 |
+
existing = hf_hub_download(repo_id=repo, repo_type='dataset', filename=remote_path,
|
| 432 |
+
revision=head, token=True)
|
| 433 |
+
existing_bytes = Path(existing).read_bytes()
|
| 434 |
+
if hashlib.sha256(existing_bytes).hexdigest() == digest:
|
| 435 |
+
return head
|
| 436 |
+
if not mutable:
|
| 437 |
+
raise UpdateError('immutable_hf_record_conflict')
|
| 438 |
+
if json.loads(existing_bytes) != expected_parent:
|
| 439 |
+
raise UpdateError('hf_latest_parent_changed')
|
| 440 |
+
elif mutable and expected_parent is not None:
|
| 441 |
+
raise UpdateError('hf_latest_parent_changed')
|
| 442 |
+
result = api.create_commit(repo_id=repo, repo_type='dataset',
|
| 443 |
+
operations=[CommitOperationAdd(path_in_repo=remote_path,
|
| 444 |
+
path_or_fileobj=str(path))],
|
| 445 |
+
commit_message='Publish PBISC-diffusion maintenance record',
|
| 446 |
+
parent_commit=head)
|
| 447 |
+
revision = result.oid
|
| 448 |
+
downloaded = hf_hub_download(repo_id='junidude14/PBISC-data', repo_type='dataset',
|
| 449 |
+
filename=remote_path, revision=revision, token=True)
|
| 450 |
+
if hashlib.sha256(Path(downloaded).read_bytes()).hexdigest() != digest:
|
| 451 |
+
raise UpdateError('hf_record_digest_mismatch')
|
| 452 |
+
return revision
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
def _verify_rows(root: Path, identifier: str, rows: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
| 456 |
+
paper = _publisher()
|
| 457 |
+
api = _hf_api()
|
| 458 |
+
revisions = {}
|
| 459 |
+
for repo_type, repo_id in {(r['repo_type'], r['repo_id']) for r in rows}:
|
| 460 |
+
paper.check_visibility(api, repo_id, repo_type)
|
| 461 |
+
revisions[repo_type] = api.repo_info(repo_id=repo_id, repo_type=repo_type, revision='main').sha
|
| 462 |
+
verified = []
|
| 463 |
+
from huggingface_hub import hf_hub_download
|
| 464 |
+
for row in rows:
|
| 465 |
+
if not row['bundle_path'].startswith('updates/' + identifier + '/'):
|
| 466 |
+
raise UpdateError('bundle_outside_update')
|
| 467 |
+
if paper.source_digest(row) != row['sha256']:
|
| 468 |
+
raise UpdateError('source_changed')
|
| 469 |
+
inspected = paper.remote_call(paper.archive_request(row, row['sha256'], 'inspect'))
|
| 470 |
+
if inspected.get('event') != 'verified_existing' or not isinstance(inspected.get('stat'), dict):
|
| 471 |
+
raise UpdateError('archive_not_verified')
|
| 472 |
+
revision = revisions[row['repo_type']]
|
| 473 |
+
info = paper.base.remote_file(api, row['repo_id'], row['repo_type'], row['remote_path'], revision)
|
| 474 |
+
if info is None or paper.base.attr(info, 'size') != row['bytes']:
|
| 475 |
+
raise UpdateError('hf_payload_missing')
|
| 476 |
+
lfs = paper.base.attr(info, 'lfs')
|
| 477 |
+
if lfs is not None:
|
| 478 |
+
if paper.base.attr(lfs, 'sha256') != row['sha256']:
|
| 479 |
+
raise UpdateError('hf_payload_digest_mismatch')
|
| 480 |
+
else:
|
| 481 |
+
local = hf_hub_download(repo_id=row['repo_id'], repo_type=row['repo_type'],
|
| 482 |
+
filename=row['remote_path'], revision=revision, token=True)
|
| 483 |
+
if hashlib.sha256(Path(local).read_bytes()).hexdigest() != row['sha256']:
|
| 484 |
+
raise UpdateError('hf_payload_digest_mismatch')
|
| 485 |
+
verified.append(dict(row, archive_stat=inspected['stat'], hf_revision=revision))
|
| 486 |
+
return verified
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def _refresh_catalog(root: Path) -> None:
|
| 490 |
+
import importlib.util
|
| 491 |
+
module_path = root / 'maintenance' / 'catalog.py'
|
| 492 |
+
if not module_path.is_file():
|
| 493 |
+
raise UpdateError('catalog_module_missing')
|
| 494 |
+
spec = importlib.util.spec_from_file_location('pbisc_diffusion_catalog', module_path)
|
| 495 |
+
if spec is None or spec.loader is None:
|
| 496 |
+
raise UpdateError('catalog_module_invalid')
|
| 497 |
+
module = importlib.util.module_from_spec(spec)
|
| 498 |
+
spec.loader.exec_module(module)
|
| 499 |
+
module.refresh(root)
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
def _archive_control(root: Path, identifier: str, folder: Path) -> list[dict[str, Any]]:
|
| 503 |
+
"""Keep independent server_2 copies of the post-publish proof and receipts."""
|
| 504 |
+
paper = _publisher()
|
| 505 |
+
required = [folder / 'manifest.json', folder / 'work' / 'receipts.jsonl',
|
| 506 |
+
folder / 'work' / 'status.json', folder / 'UPDATE_VERIFIED.json']
|
| 507 |
+
archived = []
|
| 508 |
+
for source in required:
|
| 509 |
+
_safe_local(source)
|
| 510 |
+
snap = paper.base.snapshot(source.lstat())
|
| 511 |
+
with paper.base.open_source(source, snap) as stream:
|
| 512 |
+
digest = paper.base.hash_source(source, stream, snap)
|
| 513 |
+
bundle = str(PurePosixPath('updates') / identifier / 'control' / source.name)
|
| 514 |
+
row = {'host': 'server_1', 'source': str(source), 'bundle_path': bundle,
|
| 515 |
+
'bytes': snap['size'], 'expected_stat': snap, 'sha256': digest['sha256'],
|
| 516 |
+
'repo_type': None, 'repo_id': None, 'remote_path': None}
|
| 517 |
+
result = paper.archive_asset(row, digest['sha256'], True)
|
| 518 |
+
if result.get('event') not in ('verified_existing', 'archived'):
|
| 519 |
+
raise UpdateError('control_archive_failed')
|
| 520 |
+
inspection = paper.remote_call(paper.archive_request(row, digest['sha256'], 'inspect'))
|
| 521 |
+
if inspection.get('event') != 'verified_existing':
|
| 522 |
+
raise UpdateError('control_archive_failed')
|
| 523 |
+
archived.append({'bundle_path': bundle, 'sha256': digest['sha256'],
|
| 524 |
+
'bytes': snap['size'], 'archive_stat': inspection.get('stat')})
|
| 525 |
+
return archived
|
| 526 |
+
|
| 527 |
+
|
| 528 |
+
def _check_publisher_receipts(folder: Path, rows: list[dict[str, Any]]) -> None:
|
| 529 |
+
receipts = folder / 'work' / 'receipts.jsonl'
|
| 530 |
+
state = folder / 'work' / 'status.json'
|
| 531 |
+
_safe_local(receipts)
|
| 532 |
+
_safe_local(state)
|
| 533 |
+
if _json(state).get('phase') != 'complete' or _json(state).get('execute') is not True:
|
| 534 |
+
raise UpdateError('publisher_status_incomplete')
|
| 535 |
+
events = [json.loads(line) for line in receipts.read_text(encoding='utf-8').splitlines() if line.strip()]
|
| 536 |
+
for row in rows:
|
| 537 |
+
archived = any(event.get('event') in ('archived', 'verified_existing')
|
| 538 |
+
and event.get('bundle_path') == row['bundle_path']
|
| 539 |
+
and event.get('source') == row['source']
|
| 540 |
+
and event.get('sha256') == row['sha256'] for event in events)
|
| 541 |
+
uploaded = any(event.get('event') in ('verified_uploaded', 'verified_existing')
|
| 542 |
+
and event.get('remote_path') == row['remote_path']
|
| 543 |
+
and event.get('repo_id') == row['repo_id']
|
| 544 |
+
and (event.get('sha256') == row['sha256']
|
| 545 |
+
or event.get('digest', {}).get('sha256') == row['sha256'])
|
| 546 |
+
for event in events)
|
| 547 |
+
if not archived or not uploaded:
|
| 548 |
+
raise UpdateError('publisher_receipt_missing')
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
def _compare_receipt(manifest: dict[str, Any], receipt: dict[str, Any],
|
| 552 |
+
current_rows: list[dict[str, Any]], manifest_bytes: bytes) -> None:
|
| 553 |
+
if (receipt.get('status') != 'PASS' or receipt.get('project_id') != 'pbisc-diffusion'
|
| 554 |
+
or receipt.get('update_id') != manifest.get('update_id')
|
| 555 |
+
or receipt.get('parent_latest') != manifest.get('parent_latest')
|
| 556 |
+
or receipt.get('manifest_sha256') != hashlib.sha256(manifest_bytes).hexdigest()
|
| 557 |
+
or len(receipt.get('assets', [])) != len(current_rows)):
|
| 558 |
+
raise UpdateError('verified_receipt_mismatch')
|
| 559 |
+
for declared, verified, current in zip(manifest['assets'], receipt['assets'], current_rows):
|
| 560 |
+
if (any(verified.get(key) != value for key, value in declared.items())
|
| 561 |
+
or any(verified.get(key) != value for key, value in current.items() if key != 'hf_revision')):
|
| 562 |
+
raise UpdateError('verified_receipt_mismatch')
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
def _parent_ref(parent: dict[str, Any] | None) -> dict[str, Any] | None:
|
| 566 |
+
if parent is None:
|
| 567 |
+
return None
|
| 568 |
+
return {key: parent[key] for key in ('id', 'verified_receipt_sha256', 'receipt_revision')}
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def _validate_manifest_rows(root: Path, folder: Path, manifest: dict[str, Any],
|
| 572 |
+
scope: dict[str, Any], already_latest: bool) -> None:
|
| 573 |
+
request = _json(folder / 'request.json')
|
| 574 |
+
if request.get('project_id') != 'pbisc-diffusion' or not isinstance(request.get('assets'), list):
|
| 575 |
+
raise UpdateError('prepared_request_invalid')
|
| 576 |
+
identifier = manifest['update_id']
|
| 577 |
+
declared = manifest['assets']
|
| 578 |
+
selected = {(row['host'], row['source']) for row in declared
|
| 579 |
+
if row.get('category') != 'update_metadata'}
|
| 580 |
+
if len(selected) != len([row for row in declared if row.get('category') != 'update_metadata']):
|
| 581 |
+
raise UpdateError('manifest_duplicate_source')
|
| 582 |
+
history = {} if already_latest else _history(root)
|
| 583 |
+
expected = []
|
| 584 |
+
seen = set()
|
| 585 |
+
for item in request['assets']:
|
| 586 |
+
if not isinstance(item, dict) or item.get('host') not in ('server_1', 'server_2') or item.get('state') not in STATES:
|
| 587 |
+
raise UpdateError('prepared_request_invalid')
|
| 588 |
+
host = item['host']
|
| 589 |
+
path = _path(item.get('source'), host)
|
| 590 |
+
key = (host, str(path))
|
| 591 |
+
if key in seen:
|
| 592 |
+
raise UpdateError('prepared_request_duplicate')
|
| 593 |
+
seen.add(key)
|
| 594 |
+
kind = item.get('kind')
|
| 595 |
+
if not isinstance(kind, str):
|
| 596 |
+
raise UpdateError('prepared_request_invalid')
|
| 597 |
+
row = _row(host, path, kind, identifier, scope)
|
| 598 |
+
include = key in selected if already_latest else history.get(key) != row['sha256']
|
| 599 |
+
if include:
|
| 600 |
+
row['state'] = item['state']
|
| 601 |
+
expected.append(row)
|
| 602 |
+
expected.extend([_metadata_row(folder / 'request.json', identifier, 'request.json'),
|
| 603 |
+
_metadata_row(folder / 'inference_locations.json', identifier, 'inference_locations.json'),
|
| 604 |
+
_metadata_row(folder / 'NOTE.md', identifier, 'NOTE.md')])
|
| 605 |
+
if declared != expected:
|
| 606 |
+
raise UpdateError('manifest_row_scope_mismatch')
|
| 607 |
+
|
| 608 |
+
|
| 609 |
+
def publish(root: Path, identifier: str, *, execute: bool,
|
| 610 |
+
publisher: Callable[[Path, str, Path, Path], int] = _run_publisher) -> dict[str, Any]:
|
| 611 |
+
root = root.absolute()
|
| 612 |
+
if not ID_RE.fullmatch(identifier):
|
| 613 |
+
raise UpdateError('invalid_update_id')
|
| 614 |
+
if not execute:
|
| 615 |
+
raise UpdateError('publish_requires_execute')
|
| 616 |
+
scope = _scope(root)
|
| 617 |
+
folder = root / 'maintenance' / 'updates' / identifier
|
| 618 |
+
if (folder.parent.is_symlink() or folder.is_symlink()
|
| 619 |
+
or (folder / 'manifest.json').is_symlink()):
|
| 620 |
+
raise UpdateError('unsafe_update_folder')
|
| 621 |
+
manifest = _json(folder / 'manifest.json')
|
| 622 |
+
manifest_bytes = (folder / 'manifest.json').read_bytes()
|
| 623 |
+
if manifest.get('project_id') != 'pbisc-diffusion' or manifest.get('update_id') != identifier:
|
| 624 |
+
raise UpdateError('manifest_identity_mismatch')
|
| 625 |
+
rows = manifest['assets']
|
| 626 |
+
if not rows or any(not r.get('bundle_path', '').startswith('updates/' + identifier + '/diffusion/') for r in rows):
|
| 627 |
+
raise UpdateError('manifest_bundle_scope')
|
| 628 |
+
# Revalidate every source and repository mapping before calling the broad frozen publisher.
|
| 629 |
+
for row in rows:
|
| 630 |
+
host, path = row['host'], _path(row['source'], row['host'])
|
| 631 |
+
area = _allow(path, host, scope, internal=folder)
|
| 632 |
+
if area == 'internal' and path not in {folder / 'request.json', folder / 'inference_locations.json', folder / 'NOTE.md'}:
|
| 633 |
+
raise UpdateError('unsafe_internal_source')
|
| 634 |
+
if area != 'internal' and row['repo_type'] == 'model' and area != 'model8':
|
| 635 |
+
raise UpdateError('checkpoint_outside_model8')
|
| 636 |
+
expected_repo = 'junidude14/PBISC' if row['repo_type'] == 'model' else 'junidude14/PBISC-data'
|
| 637 |
+
if row['repo_id'] != expected_repo or row['remote_path'] != PREFIX + '/' + row['bundle_path']:
|
| 638 |
+
raise UpdateError('manifest_repository_scope')
|
| 639 |
+
if host == 'server_1':
|
| 640 |
+
_safe_local(path)
|
| 641 |
+
lock_path = root / 'maintenance' / '.writer.lock'
|
| 642 |
+
if lock_path.is_symlink():
|
| 643 |
+
raise UpdateError('unsafe_writer_lock')
|
| 644 |
+
with lock_path.open('a', encoding='utf-8') as lock:
|
| 645 |
+
try:
|
| 646 |
+
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
| 647 |
+
except BlockingIOError as exc:
|
| 648 |
+
raise UpdateError('writer_busy') from exc
|
| 649 |
+
verified_path = folder / 'UPDATE_VERIFIED.json'
|
| 650 |
+
current = _latest(root)
|
| 651 |
+
already_latest = isinstance(current, dict) and current.get('id') == identifier
|
| 652 |
+
if current != manifest.get('parent_latest') and not already_latest:
|
| 653 |
+
raise UpdateError('parent_changed')
|
| 654 |
+
_validate_manifest_rows(root, folder, manifest, scope, already_latest)
|
| 655 |
+
status = folder / 'STATUS.json'
|
| 656 |
+
if already_latest:
|
| 657 |
+
if (not verified_path.exists()
|
| 658 |
+
or current.get('verified_receipt_sha256') != hashlib.sha256(verified_path.read_bytes()).hexdigest()):
|
| 659 |
+
raise UpdateError('latest_without_verified_receipt')
|
| 660 |
+
_check_publisher_receipts(folder, rows)
|
| 661 |
+
_compare_receipt(manifest, _json(verified_path), _verify_rows(root, identifier, rows), manifest_bytes)
|
| 662 |
+
api = _hf_api()
|
| 663 |
+
if _remote_latest() != current or _hf_latest(api) != current:
|
| 664 |
+
raise UpdateError('latest_replica_disagreement')
|
| 665 |
+
try:
|
| 666 |
+
_refresh_catalog(root)
|
| 667 |
+
except Exception as exc:
|
| 668 |
+
_atomic(status, _bytes({'phase': 'catalog_pending', 'update_id': identifier}))
|
| 669 |
+
raise UpdateError('catalog_refresh_failed') from exc
|
| 670 |
+
_atomic(status, _bytes({'phase': 'verified', 'update_id': identifier}))
|
| 671 |
+
return current
|
| 672 |
+
_atomic(status, _bytes({'phase': 'publishing', 'update_id': identifier}))
|
| 673 |
+
try:
|
| 674 |
+
if not verified_path.exists():
|
| 675 |
+
if publisher(root, identifier, folder / 'manifest.json', folder / 'work') != 0:
|
| 676 |
+
raise UpdateError('publisher_failed')
|
| 677 |
+
_check_publisher_receipts(folder, rows)
|
| 678 |
+
verified_rows = _verify_rows(root, identifier, rows)
|
| 679 |
+
receipt = {'schema': 'pbisc.diffusion.update-verified.v1', 'status': 'PASS',
|
| 680 |
+
'project_id': 'pbisc-diffusion', 'update_id': identifier,
|
| 681 |
+
'parent_latest': manifest.get('parent_latest'),
|
| 682 |
+
'manifest_sha256': hashlib.sha256(manifest_bytes).hexdigest(),
|
| 683 |
+
'assets': verified_rows}
|
| 684 |
+
_atomic(verified_path, _bytes(receipt))
|
| 685 |
+
else:
|
| 686 |
+
_check_publisher_receipts(folder, rows)
|
| 687 |
+
_compare_receipt(manifest, _json(verified_path),
|
| 688 |
+
_verify_rows(root, identifier, rows), manifest_bytes)
|
| 689 |
+
archived_control = _archive_control(root, identifier, folder)
|
| 690 |
+
api = _hf_api()
|
| 691 |
+
remote_latest, hf_latest = _remote_latest(), _hf_latest(api)
|
| 692 |
+
if (remote_latest not in (manifest.get('parent_latest'), _json(folder / 'LATEST.json') if (folder / 'LATEST.json').exists() else None)
|
| 693 |
+
or hf_latest not in (manifest.get('parent_latest'), _json(folder / 'LATEST.json') if (folder / 'LATEST.json').exists() else None)):
|
| 694 |
+
raise UpdateError('parent_changed_remote')
|
| 695 |
+
pointer_path = folder / 'LATEST.json'
|
| 696 |
+
if pointer_path.exists():
|
| 697 |
+
pointer = _json(pointer_path)
|
| 698 |
+
if (pointer.get('id') != identifier or pointer.get('parent') != _parent_ref(manifest.get('parent_latest'))
|
| 699 |
+
or pointer.get('verified_receipt_sha256') != hashlib.sha256(verified_path.read_bytes()).hexdigest()):
|
| 700 |
+
raise UpdateError('prepared_pointer_conflict')
|
| 701 |
+
else:
|
| 702 |
+
receipt_revision = _hf_upload_verified(api, verified_path,
|
| 703 |
+
PREFIX + '/updates/' + identifier + '/UPDATE_VERIFIED.json')
|
| 704 |
+
pointer = {'schema': 'pbisc.diffusion.latest.v1', 'project_id': 'pbisc-diffusion',
|
| 705 |
+
'id': identifier, 'parent': _parent_ref(manifest.get('parent_latest')),
|
| 706 |
+
'verified_receipt_path': PREFIX + '/updates/' + identifier + '/UPDATE_VERIFIED.json',
|
| 707 |
+
'verified_receipt_sha256': hashlib.sha256(verified_path.read_bytes()).hexdigest(),
|
| 708 |
+
'receipt_revision': receipt_revision, 'control_archive': archived_control}
|
| 709 |
+
_atomic(pointer_path, _bytes(pointer))
|
| 710 |
+
_remote_latest(pointer, expected=manifest.get('parent_latest'))
|
| 711 |
+
_hf_upload_verified(api, pointer_path, PREFIX + '/LATEST.json',
|
| 712 |
+
mutable=True, expected_parent=manifest.get('parent_latest'))
|
| 713 |
+
if _remote_latest() != pointer or _hf_latest(api) != pointer:
|
| 714 |
+
raise UpdateError('latest_replica_disagreement')
|
| 715 |
+
_atomic(root / 'LATEST.json', _bytes(pointer))
|
| 716 |
+
try:
|
| 717 |
+
_refresh_catalog(root)
|
| 718 |
+
except Exception as exc:
|
| 719 |
+
_atomic(status, _bytes({'phase': 'catalog_pending', 'update_id': identifier}))
|
| 720 |
+
raise UpdateError('catalog_refresh_failed') from exc
|
| 721 |
+
_atomic(status, _bytes({'phase': 'verified', 'update_id': identifier}))
|
| 722 |
+
return pointer
|
| 723 |
+
except Exception as exc:
|
| 724 |
+
if not status.exists() or _json(status).get('phase') != 'catalog_pending':
|
| 725 |
+
_atomic(status, _bytes({'phase': 'error', 'update_id': identifier,
|
| 726 |
+
'error_code': str(exc) if isinstance(exc, UpdateError) else 'update_failed'}))
|
| 727 |
+
raise
|
| 728 |
+
|
| 729 |
+
|
| 730 |
+
def status(root: Path) -> dict[str, Any]:
|
| 731 |
+
_scope(root.absolute())
|
| 732 |
+
updates = []
|
| 733 |
+
updates_root = root / 'maintenance' / 'updates'
|
| 734 |
+
if updates_root.is_symlink():
|
| 735 |
+
raise UpdateError('unsafe_updates_root')
|
| 736 |
+
for folder in sorted(updates_root.glob('*')) if updates_root.exists() else []:
|
| 737 |
+
if folder.is_dir() and not folder.is_symlink() and ID_RE.fullmatch(folder.name):
|
| 738 |
+
state = _json(folder / 'STATUS.json') if (folder / 'STATUS.json').exists() else {'phase': 'unknown'}
|
| 739 |
+
updates.append({'id': folder.name, 'phase': state['phase']})
|
| 740 |
+
baseline = root / 'maintenance' / 'BASELINE_REFERENCE.json'
|
| 741 |
+
return {'project_id': 'pbisc-diffusion', 'latest': _latest(root),
|
| 742 |
+
'baseline': _json(baseline) if baseline.exists() else None, 'updates': updates}
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
def main(argv: list[str] | None = None) -> int:
|
| 746 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 747 |
+
sub = parser.add_subparsers(dest='command', required=True)
|
| 748 |
+
prep = sub.add_parser('prepare')
|
| 749 |
+
prep.add_argument('--request', required=True, type=Path)
|
| 750 |
+
prep.add_argument('--id', required=True)
|
| 751 |
+
pub = sub.add_parser('publish')
|
| 752 |
+
pub.add_argument('id')
|
| 753 |
+
pub.add_argument('--execute', action='store_true')
|
| 754 |
+
sub.add_parser('status')
|
| 755 |
+
args = parser.parse_args(argv)
|
| 756 |
+
try:
|
| 757 |
+
if args.command == 'prepare':
|
| 758 |
+
request = json.load(sys.stdin) if str(args.request) == '-' else _json(args.request)
|
| 759 |
+
result = {'prepared': str(prepare(ROOT, request, args.id))}
|
| 760 |
+
elif args.command == 'publish':
|
| 761 |
+
result = publish(ROOT, args.id, execute=args.execute)
|
| 762 |
+
else:
|
| 763 |
+
result = status(ROOT)
|
| 764 |
+
print(json.dumps(result, sort_keys=True))
|
| 765 |
+
return 0
|
| 766 |
+
except Exception as exc:
|
| 767 |
+
print(json.dumps({'error_code': str(exc) if isinstance(exc, UpdateError) else 'update_failed'}), file=sys.stderr)
|
| 768 |
+
return 1
|
| 769 |
+
|
| 770 |
+
|
| 771 |
+
if __name__ == '__main__':
|
| 772 |
+
raise SystemExit(main())
|
paper-releases/pbisc-diffusion/updates/20260929T062828Z-manuscript-relocation/diffusion/dataset/server_1/maintenance/8f31479db9f9cb1d/SCOPE.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
paper-releases/pbisc-diffusion/updates/20260929T062828Z-manuscript-relocation/diffusion/dataset/server_1/manuscript/AGENTS.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PBISC-Diffusion manuscript maintenance
|
| 2 |
+
|
| 3 |
+
The README names this manuscript as the PBISC-Diffusion Nature Communications
|
| 4 |
+
draft. It is the `pbisc-diffusion` paper covered by
|
| 5 |
+
`../maintenance/POLICY.md`. Read that policy and
|
| 6 |
+
the README at the start of a related task, in addition to parent instructions.
|
| 7 |
+
|
| 8 |
+
At the end of a task that changes this paper's manuscript, figures, source
|
| 9 |
+
data, references, or evidence, follow the policy's versioned update workflow
|
| 10 |
+
for the exact changed assets. From the release root, use
|
| 11 |
+
`maintenance/update.py prepare --request FILE --id ID`, inspect the prepared
|
| 12 |
+
update, then run `maintenance/update.py publish ID --execute` and
|
| 13 |
+
`maintenance/update.py status` under the policy. Record a no-op or
|
| 14 |
+
pending status when no asset changed or publication failed; never describe
|
| 15 |
+
that as an upload. Preserve the frozen 2026-09-28 release, its root manifests,
|
| 16 |
+
and the HF `paper-20260928` revision. Keep the dataset private.
|
| 17 |
+
|
| 18 |
+
Do not enroll other papers merely because they are under `bulk2sc-paper/`.
|
| 19 |
+
Manuscript claims must remain tied to their actual evidence, and updating the
|
| 20 |
+
archive does not itself establish scientific validity.
|