Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions coordination/sessions/M21-C001/CLAUDE_PEER_REVIEW_PL0516_V02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CLAUDE_PEER_REVIEW PL-0516 V02 (PR #108, round 2)
Reviewer: independent Claude reviewer subagent (not implementer). Base e55fb6ea -> head 84491d3dad98f7ab9c7a4d560d4956c717f228e4.
Verdict: PASS_WITH_FIXES — M1 must be fixed before merge (CHANGES_REQUIRED for round-1 item 1); items 2-7 PASS.
Evidence (run by reviewer in an isolated worktree, since removed):
- pytest tests/server: 81 passed; tests/tools/test_install_update.py + tests/tools/test_sbom.py + tests/server/test_backup.py: 18 passed, 0 skipped (junction-based link tests really executed).
- ruff check core apps server tools tests: pass. mypy --no-incremental core apps server tools: 0 issues / 348 files.
- Not run: GitHub Actions, full suite.
Findings:
- MEDIUM M1 tools/release/sbom.py:43 — entries without `version` and without a parsable /tree/<version> (commit pins, tag refs like openssl-3.0.16) are accepted, so a licence attaches to any locked version. Today 5 components (cadquery-ocp-novtk, cadquery-ocp-proxy, pyside6-addons, pyside6-essentials, shiboken6) are licensed only via this path; a PySide6 bump would silently keep LGPL-3.0-only. Fix: `match is not None and match.group(1) == locked`; add "version" (6.11.2 for pyside6/pyside6-addons/pyside6-essentials/shiboken6, 7.9.3.1.1 for cadquery-ocp-novtk/-proxy — the versions the registry already records in license_file / source_evidence); update test_sbom.py:84 and the docs SBOM sentence. Reviewer trial: same 11 licensed components, inventory and engine-bundle tests pass.
- LOW L1 tools/release/install_update.py:133-136 — non-string state values (e.g. "previous": 7) pass validation; rollback then raises uncaught TypeError (reproduced). Require isinstance str.
- LOW L2 server/src/packlab_server/backup.py:97 — create checks the object store for symlinks only; also refuse junctions.
- LOW L3 install_update.py:59-60 — root-is-link refusal has no test.
Round-1 items 2 (docs config backup), 3 (backup link refusal), 4 (tests), 5 (state/version checks), 6 (is not None), 7 (src close) verified PASS.
Limits: no physical/factory evidence involved; review covers source, diff and local test runs only.

Fixes: 742754606ea553d120d46f4915aacac8aff198de

## Addendum: fix verification (head 7b321aab8a438874570ab422582165cc650bcf6f, fix 742754606ea553d120d46f4915aacac8aff198de)
Verdict: PASS — M1, L1, L2, L3 resolved; no open findings from rounds 1-2.
- M1: sbom.py rule `match is not None and match.group(1) == locked`; registry `version` added (6.11.2 for pyside6/pyside6-addons/pyside6-essentials/shiboken6, 7.9.3.1.1 for cadquery-ocp-novtk/-proxy). Real SBOM still licenses the same 11 components.
- L1: read_state rejects non-str state values (InstallError, exit 2). L2: backup.create refuses junctions in the object store. L3: payload-root link test added.
- Reviewer evidence (isolated worktree, PYTHONPATH=".;core/src;server/src;apps/windows-studio/src", imports confirmed from the worktree): tests/server 81 passed; test_install_update + test_sbom + test_windows_redistribution_inventory + test_engine_bundle 35 passed, 0 skipped; ruff pass; mypy 0 issues/348 files.
- Mutation checks: reverting each of the root-link refusal, the state type check and the SBOM rule makes its corresponding test fail (tests are not tautological).
- Info: no direct test for the backup.create junction refusal (one-line change mirroring tested logic). Actions not run by reviewer.
178 changes: 178 additions & 0 deletions docs/ecosystem/PL-0516_OPERATIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# PL-0516: Operations — backup/restore, update/rollback, GitHub-blocked operation, SBOM, private registry

Status: local, testable parts implemented 2026-12-03. **Public builds stay blocked by the licence
gate** (`tools/packaging/windows_component_license_registry.json`,
`docs/architecture/DEPENDENCY_LICENSE_REGISTER.md`: OpenMVS AGPL-3.0, OCP/OCCT native notices,
OpenCV/FFmpeg). Real installer signing, a signed Windows installer, the company artifact
registry and factory-LAN deployment are **external gates**: none is claimed here. Nothing below
was run against real company infrastructure; all evidence is local temp-directory tests.

| Part | Code | Tests |
|---|---|---|
| Server backup/verify/restore | `server/src/packlab_server/backup.py` | `tests/server/test_backup.py` |
| Studio side-by-side update/rollback | `tools/release/install_update.py` | `tests/tools/test_install_update.py` |
| CycloneDX SBOM from `uv.lock` | `tools/release/sbom.py` | `tests/tools/test_sbom.py` |

All three are stdlib-only (no new dependency) and exit 0 PASS, 1 verification failed,
2 refused precondition.

## 1. PackLab Server backup / restore runbook

A backup is a directory with `library.sqlite3`, the content-addressed `objects/aa/bb/<sha256>`
files and `manifest.json` (SHA-256 + size of every file).

- The database is copied with the **SQLite online backup API** (`sqlite3.Connection.backup`),
not a file copy, so it is a consistent snapshot while the server keeps serving. It is
taken *before* the objects; objects are immutable and never deleted by the store, so every
object the snapshot references exists when the object copy runs. `verify` re-checks this
(every `revisions.assets` hash must be in the backup).
- In-progress resumable uploads (`uploads/`) are not backed up; clients resume or restart them.
- **Server configuration is not in the backup.** The `--tokens` file, the `--oidc` config and
any `jwks_file` it names live outside `--data` and hold credentials/trust anchors. Back them
up separately into protected (access-controlled, encrypted) storage, never next to the data
backup on shared media and never in Git; a restore needs them to start the server.
- A symlink or junction anywhere in a backup (the root, any directory or file) is refused.
- Object files are checked against their content address while copying.

```
python -m packlab_server.backup create D:\packlab-data E:\backups\2026-12-03
# -> BACKUP_CREATED manifest_sha256=<hex> record this hex off-band (work record / ticket)
python -m packlab_server.backup verify E:\backups\2026-12-03 --expect-manifest-sha256 <hex>
python -m packlab_server.backup restore E:\backups\2026-12-03 D:\packlab-data-restored --expect-manifest-sha256 <hex>
```

(`PYTHONPATH=server/src` when running from a source checkout.)

Restore rules: the backup is verified, copied into a sibling temp directory, the copy is verified
again, then renamed into place. The target must not exist or must be an empty directory, so a
live data directory is never overwritten. To put a restored copy into service: stop the server,
rename the old data directory aside (keep it until the restore is accepted), rename the restored
directory to the configured `--data` path, start the server. Clients see the feed
`high_watermark` below their cursor and resync (existing PL-0503 behaviour).

The manifest self-check catches corruption. A deliberate rewrite of a file *and* the manifest is
caught only by `--expect-manifest-sha256`, so keep that value outside the backup medium.
Encryption at rest, off-site/cloud copy and retention schedule belong to the deployment
(POVU handoff: LAN primary + encrypted cloud DR); they are not implemented here.

## 2. Studio update / rollback runbook

Generalizes the OwnerDev `releases/` + `current`/`previous` pattern
(`tools/dev/update_owner_dev_runtime.ps1`, `update_owner_dev_current_runtime.ps1`; those scripts
and the owner's OwnerDev folder are unchanged and untouched by the tests).

Layout: `INSTALL_ROOT\releases\<version>\` (immutable, with `install-manifest.json`) and
`INSTALL_ROOT\state.json` = `{"current": "<v>", "previous": "<v>"}`. A launcher starts
`releases\<current>`. Switching is a single atomic `os.replace` of `state.json`.

```
# build side, on the payload that will ship
python -m tools.release.install_update manifest build\PackLab-1.2.0 --version 1.2.0 # -> sha256
# target machine
python -m tools.release.install_update stage C:\PackLab \\share\PackLab-1.2.0 --expect-manifest-sha256 <hex>
python -m tools.release.install_update activate C:\PackLab 1.2.0
python -m tools.release.install_update rollback C:\PackLab # one step back
python -m tools.release.install_update status C:\PackLab
```

- `stage` verifies the payload, copies it side by side, verifies the copy, then renames it into
`releases\<version>`; an existing version is refused, links/junctions are refused.
- `activate` / `rollback` re-verify the release they switch to, including that its manifest
version equals its directory name; on failure `state.json` is unchanged. A corrupt
`state.json` is refused (exit 2), not guessed at.
- After `activate` only `current` and `previous` are kept. A release staged but not yet
activated is pruned by the next `activate` of a different version: stage and activate one
version at a time. Files locked by a still-running old version are left and reported.
- Close Studio before `activate`/`rollback`; the tool does not stop processes.
- Data is never inside a release directory (projects and the sync cache live in user data), so
rollback does not roll back data. A data format change must stay additive/readable by the
previous version or ship with its own migration and backup step.
- The `--expect-manifest-sha256` value is the integrity anchor until real code signing exists;
it must come from the release record, not from the same share as the payload.

## 3. GitHub-blocked operation

Production must run, install, update and recover with GitHub (and public PyPI) unreachable.

**At runtime nothing is downloaded.** The Studio, the server and the sync agent make no calls to
GitHub, raw URLs or package indexes; updates arrive as staged payloads (section 2).

**Offline wheelhouse from `uv.lock`** (on a connected build host, then carried in):

```
uv export --frozen --no-emit-project --format requirements-txt -o requirements.lock.txt
python -m pip download --require-hashes --only-binary=:all: --platform win_amd64 \
--python-version 3.12 -r requirements.lock.txt -d wheelhouse
# on the isolated host
uv venv --python 3.12 .venv
uv pip sync --offline --no-index --find-links wheelhouse --require-hashes requirements.lock.txt
```

`uv export --frozen` was run locally for this task (hashes come from `uv.lock`); the download and
offline sync were **not** executed here (no network test was done). Hashes in the exported file
pin every wheel, so a tampered wheelhouse fails the install.

**Non-Python inputs the build pulls from GitHub today** (`.github/workflows/windows-studio-build.yml`)
must be mirrored into the private artifact store with their recorded SHA-256 before GitHub can be
dropped: OCP `OCP_src_stubs_Windows.zip` 7.9.3.1.1, OCCT source archive
`a016080bf6738d6aeae020badee4e888ad1540a5`, Inno Setup 6.7.3, plus the controlled OCP/COLMAP/OpenMVS
inputs pinned in `tools/packaging/*.json`.

**Verifying a CI-less build** (GitHub Actions unavailable):

1. Clean checkout of the exact commit; `uv sync --locked` from the wheelhouse/private index.
2. Run the same gates locally: `ruff format --check`, `ruff check core apps server tools tests`,
`mypy --no-incremental core apps server tools`, `pytest`,
`python -m tools.ci.ci_data_safety --repository . --check-signing-secrets` and
`--tracked --check-workflows --check-environment`.
3. Build, then `install_update manifest` the payload and record commit SHA, `uv.lock` SHA-256,
SBOM and manifest SHA-256 in the release record (`tools/release/offline_release_manifest.py`
stays `NOT_RELEASE_AUTHORIZED` until the licence and signing gates clear).

## 4. SBOM

```
python -m tools.release.sbom --output packlab.cdx.json
```

CycloneDX 1.5 JSON with every `uv.lock` package: name, version, `pkg:pypi` purl, dependency graph,
scope `required` (runtime closure of the project dependencies) or `excluded` (dev/workflow
tools). A licence is stated only where the licence registry records one for the locked version
(registry `version`, or a version in `upstream_reference` `.../tree/<version>`, must equal the
lock; entries with neither, such as commit pins or tag refs, are not tied to a version and
count as unreviewed); all others carry
`packlab:licence_status=UNREVIEWED`. Output is byte-identical for the same lock and registry
(no timestamp; serial number derived from the `uv.lock` SHA-256). Scope: Python packages only —
native payloads (OCCT, Qt DLLs inside wheels, COLMAP/OpenMVS, MSVC runtime) are covered by the
PL-0350 native inventory, not this SBOM. The SBOM is evidence, not licence clearance.

## 5. Private registry migration plan

Target: company-hosted, S3-compatible-backed artifact service (e.g. a PyPI-compatible proxy such
as devpi/Nexus/Artifactory, chosen at commissioning; no provider is selected or purchased now).

1. **Mirror**: populate a private PyPI-compatible index from the wheelhouse above (all hashes from
`uv.lock`), and a raw artifact area for the native/tool inputs listed in section 3.
2. **Point uv at it**: add an `[[tool.uv.index]]` (name `packlab-private`, `default = true`) in
`pyproject.toml`, credentials only through environment/keyring (`UV_INDEX_PACKLAB_PRIVATE_USERNAME`
/ `_PASSWORD`), never in Git. Re-lock with `uv lock`; the **package hashes must be identical**
to the current lock (only the `source.registry` URL changes) — diff the lock and refuse any
hash change.
3. **Workflows**: replace `Invoke-WebRequest https://github.com/...` inputs with the private
artifact URLs, keeping the same SHA-256 checks. Do not weaken the licence/public-build gates
while doing so.
4. **Releases**: staged payloads + `install-manifest.json` + SBOM published to the private
artifact store; clients update with `install_update stage/activate` from there.
5. **Source/history export**: `git bundle create packlab.bundle --all`, verified with
`git bundle verify`, stored in the private store; repository visibility/deletion is an owner
decision, not part of this task.
6. **Cutover check**: on a host with GitHub and pypi.org blocked at the firewall, run section 3
step 1-3 end to end, a server backup/restore and an update + rollback. That real-infra run is
the acceptance evidence still outstanding.

## Limits

- No signing, no installer build, no public build, no network service added.
- Backup encryption, retention, off-site copy and scheduling are deployment work.
- The update tool is not wired into the OwnerDev launcher or the Inno Setup installer yet.
- Offline wheelhouse and private-registry steps are documented, not executed on real infrastructure.
Loading