Skip to content

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

address review (codex): scope reassignment run-ownership to the full (universeId, entryId) key

[._.]/ Adam Eivy71aafe4b1adc
diff --git a/PLAN.md b/PLAN.md
index c70d64c405..f45267b0d5 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -20,8 +20,6 @@ independently.
<!-- reference-watch proposals: slug-tagged, picked up by /claim later -->
-- [ ] [lora-reassign-filter-stale-runs-by-character] **After a dataset is reassigned to a new character, stop showing the old character's training runs (and their checkpoint picker) under the new character.** Deferred from the codex review of PR #1243 (gated-repo + dataset-reassignment). `patchDataset` now resets a reassigned dataset to draft and `flipDatasetAfterRun` is character-guarded, so an old run can no longer flip the new character's status — but `TrainingPanel` (`client/src/components/loraTraining/TrainingPanel.jsx`) still lists runs purely by `datasetId` (`listLoraTrainingRuns({ datasetId })`), so after reassigning A→B, B's workbench shows A's completed run and offers its CheckpointPicker. Promoting A's checkpoint then registers a LoRA for A (correct, via `run.character`) while B's dataset stays draft — confusing "nothing happened" UX. Fix: filter the runs `TrainingPanel` displays/promotes to those whose `run.character.entryId` matches the dataset's current character (runs carry their character snapshot), or scope the runs query by current character. Server `listRuns` already accepts `characterId`. Estimated scope: small.
-
- [ ] [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.
diff --git a/client/src/components/loraTraining/TrainingPanel.jsx b/client/src/components/loraTraining/TrainingPanel.jsx
index e1e338b5b9..4e73e9b264 100644
--- a/client/src/components/loraTraining/TrainingPanel.jsx
+++ b/client/src/components/loraTraining/TrainingPanel.jsx
@@ -47,13 +47,22 @@ export default function TrainingPanel({ dataset, readiness, triggerSaving, onRun
}).catch(() => setModels([]));
}, []);
+ // A reassigned dataset keeps its id but its old runs belong to the previous
+ // character. Re-fetch (and re-filter) whenever the character identity moves,
+ // not just the id, and show only runs matching the current (universeId,
+ // entryId) so the panel + checkpoint picker can't surface/promote a stale
+ // run from the prior character.
+ const charEntryId = dataset.character?.entryId;
+ const charUniverseId = dataset.character?.universeId;
const refreshRuns = useCallback(() => {
listLoraTrainingRuns({ datasetId: dataset.id, limit: 5 }).then((runs) => {
- const active = runs.find(isActive) || null;
- setActiveRun(active);
- setLastRun(runs.find((r) => !isActive(r)) || null);
+ const own = (Array.isArray(runs) ? runs : []).filter(
+ (r) => r.character?.entryId === charEntryId && r.character?.universeId === charUniverseId,
+ );
+ setActiveRun(own.find(isActive) || null);
+ setLastRun(own.find((r) => !isActive(r)) || null);
}).catch(() => {});
- }, [dataset.id]);
+ }, [dataset.id, charEntryId, charUniverseId]);
useEffect(() => { refreshRuns(); }, [refreshRuns]);
const sseUrl = activeRun ? `/api/lora-training/runs/${activeRun.id}/events` : null;
diff --git a/server/services/loraTraining/index.js b/server/services/loraTraining/index.js
index 2909272b33..5ae6461958 100644
--- a/server/services/loraTraining/index.js
+++ b/server/services/loraTraining/index.js
@@ -185,11 +185,19 @@ const flipDatasetAfterRun = (run, { trained, loraFilename = null }) => {
// different character mid-run (patchDataset resets it to draft); flipping
// it here would otherwise mark the NEW character trained with the OLD
// character's adapter, or clobber a fresh run's 'training' status. Skip the
- // flip when the dataset has moved on. Pre-reassignment runs predate the
- // `character` snapshot guarantee, so a missing entryId falls through (flip).
+ // flip when the dataset has moved on. Match on the full (universeId,
+ // entryId) key the dataset store uses — a different universe can reuse the
+ // same entryId, so entryId alone would falsely re-own a moved dataset.
+ // Pre-reassignment runs predate the `character` snapshot guarantee, so a
+ // missing entryId falls through (flip).
const runEntryId = run?.character?.entryId || null;
+ const runUniverseId = run?.character?.universeId || null;
return updateDataset(datasetId, (current) => {
- if (runEntryId && current.character?.entryId !== runEntryId) return null;
+ const mismatch = runEntryId && (
+ current.character?.entryId !== runEntryId
+ || (runUniverseId && current.character?.universeId !== runUniverseId)
+ );
+ if (mismatch) return null;
return {
...current,
status: trained ? 'trained' : 'draft',