Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): move the reassign-while-training guard inside the write lock
[._.]/ Adam Eivy86aaf292a9fb
diff --git a/PLAN.md b/PLAN.mdindex f45267b0d5..18b02411d4 100644--- a/PLAN.md+++ b/PLAN.md@@ -20,8 +20,6 @@ independently.<!-- reference-watch proposals: slug-tagged, picked up by /claim later -->-- [ ] [lora-reassign-recheck-training-status-under-lock] **Re-check dataset training status inside the `patchDataset` write lock to close the reassign/train-start TOCTOU.** Deferred from the codex review of PR #1243. The new "refuse reassignment while training" guard in `server/services/loraDatasets.js` reads status from a `loraDatasetStore.loadAll()` snapshot taken before `updateDataset()` acquires the per-record write lock; if `startTrainingRun` stamps `status: 'training'` in that window, the reassignment can still slip through. The character-aware `flipDatasetAfterRun` guard already prevents the worst outcome (wrong-character flip), so this is a residual hardening, not a corruption risk. Fix: re-read `current.status` inside the `updateDataset` mutation callback when `characterChanged` and abort/throw `409 DATASET_TRAINING` there (confirm `updateDataset` propagates a thrown `ServerError` from the callback to the caller, or return a sentinel the wrapper translates). Estimated scope: small. (Single-user trust model — per CLAUDE.md this is a same-actor re-entrancy guard, which is in-scope, not a multi-actor race.)-- [ ] [ref-watch-phosphene-model-weights-integrity-repair] **Verify downloaded model weights (header/size + optional checksum) and offer one-click Repair.** From `reference-watch` review of Phosphene (commits `173d2fd5` + `80752a70`, 2026-06-12). Upstream proved that corrupt/partial safetensors (right size, *wrong bytes*) silently decode to garbled "mosaic" video output that a clean re-download fixes — a leading non-Metal cause of bad renders that hits some machines and not others, so it's cross-platform-relevant for PortOS (mac and windows). PortOS currently only sums file sizes: `server/lib/hfCache.js#inspectModelCache()` returns `{ cached, sizeBytes }` with no integrity check. Fix: add a `verifyModelCache(repoId)` to `server/lib/hfCache.js` that does a cheap structural check first (read each safetensors header length prefix and confirm the file is at least header+declared-tensor-bytes long — catches truncation without loading tensors), and an optional deep check that hashes each weight and compares against HuggingFace's published LFS sha256 (from the repo's `git lfs` pointer / `/api/models/<repo>` metadata). Surface results on `GET /api/video-gen/status` (and the imageGen status it mirrors) as a `modelIntegrity` field, add `POST /api/video-gen/models/verify` (force re-scan, threaded/on-demand) and `POST /api/video-gen/models/repair` (delete flagged files + re-download via the existing resumable HF fetch path), and show a dismissible "Repair model" banner in `client/src/pages/VideoGen.jsx` when integrity reports bad/missing files. Estimated scope: large.- [ ] [ref-watch-phosphene-runtime-fingerprint-in-status] **Surface the video runtime fingerprint (ltx-2-mlx version, MLX/Metal version, chip, OS) in video-gen status + render logs.** From `reference-watch` review of Phosphene (commits `b069e2d2` P2 + `093a9f05`, 2026-06-12). Upstream found that garbled/"mosaic" output is often a per-chip/per-runtime numerical bug, not a crash, and healthy bug reports carried no version info — so it now logs a one-line runtime fingerprint and exposes `ltx_version`/`mlx_version`/`chip`/`os` on `/status`. PortOS already resolves BYOV runtimes (`server/services/videoGen/local.js#BYOV_RUNTIME_INFO`) but `GET /api/video-gen/status` (`server/routes/videoGen.js:180`) does not report the resolved interpreter/package versions. Fix: have `generate_ltx2.py` (and the wan22/hunyuan/win helpers) emit a single `runtime | ...` fingerprint line at startup (importlib.metadata version of the runtime package + platform/processor on mac, torch+CUDA on windows), capture it in `local.js`, persist it onto the render job/history record so each render log self-documents its environment, and add a `runtime` block to the `/status` payload for the client to show. Estimated scope: medium.diff --git a/server/services/loraDatasets.js b/server/services/loraDatasets.jsindex c19ab8b678..5c01ef759d 100644--- a/server/services/loraDatasets.js+++ b/server/services/loraDatasets.js@@ -207,17 +207,8 @@ export async function patchDataset(id, { triggerWord, universeId, entryId } = {}resolveCharacterSnapshot(universeId, entryId),loraDatasetStore.loadAll(),]);- // Refuse while a run is in flight (status 'training' = a queued or running- // job exists). A queued run captured this dataset's id + old character- // snapshot; if we moved the dataset now, the run would stage the moved- // images yet register the adapter under the OLD character. Make the user- // cancel first — then reassignment is a clean draft-state operation.- const self = all.find((d) => d.id === id);- if (self?.status === 'training') {- throw new ServerError('Cannot reassign while a training run is in progress — cancel it first', {- status: 409, code: 'DATASET_TRAINING',- });- }+ // (The in-flight-run guard moved into the write lock below — a pre-write+ // status snapshot races a concurrent startTrainingRun stamping 'training'.)// Enforce the same find-or-create key createDataset uses: at most one// dataset per (universeId, entryId). Reassigning onto a character that// already owns a dataset would create a duplicate the list can't tell apart.@@ -239,6 +230,17 @@ export async function patchDataset(id, { triggerWord, universeId, entryId } = {}|| nextCharacter.universeId !== current.character.universeId|| nextCharacter.ingredientId !== current.character.ingredientId|| nextCharacter.name !== current.character.name);+ // Authoritative in-flight guard, under the per-record write lock: a+ // concurrent startTrainingRun may have stamped status:'training' since the+ // pre-write reads above. Reassigning then would move the dataset out from+ // under a queued run that captured its id + old character — and because+ // flipDatasetAfterRun skips character-mismatched runs, the dataset would be+ // left stuck in 'training'. Refuse here so the user cancels the run first.+ if (characterChanged && current.status === 'training') {+ throw new ServerError('Cannot reassign while a training run is in progress — cancel it first', {+ status: 409, code: 'DATASET_TRAINING',+ });+ }if (!triggerChanged && !characterChanged) return null;// Re-prefix every captioned image so the binding token follows a trigger// rename. Without this, computeDatasetReadiness (which gates `captioned`