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 (claude): test object/place prompt builder, drop unused export

[._.]/ Adam Eivy447557c12002
diff --git a/PLAN.md b/PLAN.md
index 2d8571a0cf..f64c9bb7e4 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -26,6 +26,8 @@ independently.
- [ ] [lora-training-default-base-tier-too-heavy] **Reconsider the LoRA-training memory tier + default steps — unquantized 9B is ~25× slower than 4B on a 128GB box for a character LoRA.** Surfaced 2026-06-14 training Freydis (dataset `90043893`). `deriveMfluxMemoryConfig` (`server/services/loraTraining/runtimes.js`) maps ≥96GB → `{quantize:null}` (full bf16). On the M5 Max 128GB, a `flux2-klein-9b` bf16 run at 768px/600 steps **failed to complete a single real training step in 14 min** (the 32GB base materialized for the fused `value_and_grad` forward+backward hits memory/swap pressure), whereas `flux2-klein-4b` ran steady at **~3.5s/step → ~35min total** (run `d36562a0`). The base-model size dominated; `TRAINING_DEFAULTS.steps` 600→400 was minor. Proposed: (a) for single-character LoRAs default to the 4B base (or 9B-8bit) rather than unquantized 9B even when RAM allows it — speed/fidelity tradeoff strongly favors the lighter base; (b) revisit `TRAINING_DEFAULTS.steps` (600 may be 1.5-2× more than needed for 25-image faces — the checkpoint picker lets the user grab an earlier checkpoint); (c) re-measure whether `low_ram:true` is still warranted on a 128GB box once the base is lighter (the in-RAM-cache rejection was decided during the swap-thrash that coincided with the panics). Expose base-quant/low_ram as request params (currently only steps/rank/lr/resolution/checkpointEvery/sampleEvery are in `loraTrainingParamsSchema`) so a run can opt into a heavier base without a code change. Validate fidelity: confirm a 4B Freydis LoRA is acceptable before changing the default. Estimated scope: medium.
+- [ ] [lora-dataset-object-place-variation-chips] **Let the generate-batch dialog tune object/place variation axes — surface the kind axes so the "Lighting"/"Settings" chips actually render.** Deferred from PR #1267 review (claude, 2026-06-14): the object/place LoRA feature is functional (server-side `deriveVariationAxes` applies kind-appropriate lighting/setting defaults in `generateDatasetImages`), but `LoraDatasetDetail.jsx`'s `expressionOptions`/`outfitOptions` are hard-coded to `[]` for non-character kinds (`client/src/pages/LoraDatasetDetail.jsx:~355`), so `GenerateBatchDialog`'s `expressionOptions.length > 0` / `outfitOptions.length > 0` guards are always false and the per-kind relabeled chip lists ("Lighting"/"Settings", added in `GenerateBatchDialog.jsx`) never render — users can't override the object/place axes, only the server defaults are ever used, and the relabel logic is currently dead for non-characters. Fix: have the dataset/subject payload carry the kind axes (or expose `deriveVariationAxes` output via the dataset detail endpoint) so the client can seed `expressionOptions`/`outfitOptions` from the server vocab instead of mirroring it client-side (avoid duplicating the server axis vocab in the client — that's the cross-module-constants-by-copy anti-pattern). Then the "Lighting"/"Settings" chip lists render and overrides flow through the existing `views`/`expressions`/`outfits` generate params. Estimated scope: small.
+
- [ ] [lora-checkpoint-picker-dedupe-and-hide-untrained-step0] **LoRA checkpoint picker: dedupe by step and don't offer the untrained step-0 checkpoint as deployable.** Surfaced 2026-06-14 from run `90043893` showing 3 checkpoint cards all at "step 0" with identical previews. Two real bugs in `server/services/loraTraining/checkpoints.js#listRunCheckpoints` (NOT caused by the segmentation PR — pre-existing): (1) mflux saves a `0000000_checkpoint.zip` from its `num_iterations==0` monitoring block (the *untrained* initial adapter, identical base-model preview every time) and `listRunCheckpoints` lists it as a deployable "Use this" option — deploying it is a no-op; filter step 0 out of the deployable list (or clearly mark it non-deployable), since the LoRA has zero training at step 0. (2) `run.artifacts.checkpoints` accumulates duplicate entries across MANUAL resume attempts — each resume is a fresh job/wrapper/watcher with an empty `seen` set, so it re-emits the already-existing checkpoint(s), and `listRunCheckpoints` does no dedup → N identical cards. Dedupe by `step` (keep the entry with a non-null loss / latest). Add field-level tests on `listRunCheckpoints` output (dedup + step-0 exclusion). Note: the new segmented-training path does NOT add duplicates (one watcher with a persistent `seen` set spans all segments), so this is purely a manual-resume + step-0 artifact. Estimated scope: small.
- [ ] [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/server/services/loraDatasetGenerate.test.js b/server/services/loraDatasetGenerate.test.js
new file mode 100644
index 0000000000..ae390829a8
--- /dev/null
+++ b/server/services/loraDatasetGenerate.test.js
@@ -0,0 +1,108 @@
+import { describe, it, expect } from 'vitest';
+import { buildDatasetImagePrompt, deriveVariationAxes } from './loraDatasetGenerate.js';
+
+// Pure-function coverage for the kind-aware prompt builder + variation axes.
+// These are the highest-risk new logic in the object/place feature: a
+// regression in the subject block or negative-prompt selection would ship
+// silently because the renders themselves are non-deterministic.
+
+const UNIVERSE = { artStyle: 'gritty ink-and-wash fantasy' };
+
+describe('buildDatasetImagePrompt', () => {
+ it('renders a single-figure character prompt (default kind)', () => {
+ const { prompt, negativePrompt } = buildDatasetImagePrompt(
+ UNIVERSE,
+ { name: 'Kessa', role: 'ranger' },
+ {},
+ );
+ expect(prompt).toContain('Character: Kessa.');
+ expect(prompt).toContain('Solo subject');
+ expect(prompt).toContain('full body in frame');
+ expect(negativePrompt).toContain('distorted anatomy');
+ // Character branch never emits the object/location subject markers.
+ expect(prompt).not.toContain('Single object only');
+ expect(prompt).not.toContain('Single location focus');
+ });
+
+ it('renders a single-object prompt with the object negative prompt', () => {
+ const subject = {
+ name: 'Northwind Truthbreaker',
+ description: 'A rune-bitten greataxe.',
+ tags: ['weapon', 'relic'],
+ };
+ const { prompt, negativePrompt } = buildDatasetImagePrompt(UNIVERSE, subject, {}, 'objects');
+ expect(prompt).toContain('Object: Northwind Truthbreaker.');
+ expect(prompt).toContain('Description: A rune-bitten greataxe.');
+ expect(prompt).toContain('Tags: weapon, relic.');
+ expect(prompt).toContain('Single object only');
+ expect(prompt).toContain('full object in frame');
+ expect(negativePrompt).toContain('multiple objects');
+ expect(negativePrompt).toContain('hands covering the object');
+ expect(prompt).not.toContain('Character:');
+ });
+
+ it('renders a single-location prompt with the place negative prompt', () => {
+ const subject = { name: 'Moonsea Shore', description: 'Black water under cold stars.' };
+ const { prompt, negativePrompt } = buildDatasetImagePrompt(UNIVERSE, subject, {}, 'places');
+ expect(prompt).toContain('Place: Moonsea Shore.');
+ expect(prompt).toContain('Single location focus');
+ expect(prompt).toContain('no prominent characters');
+ expect(negativePrompt).toContain('prominent character');
+ expect(negativePrompt).toContain('distorted perspective');
+ expect(prompt).not.toContain('Single object only');
+ });
+
+ it('falls back to slugline + Unnamed and tolerates absent canon fields', () => {
+ const { prompt } = buildDatasetImagePrompt(UNIVERSE, { slugline: 'INT. CRYPT' }, {}, 'places');
+ expect(prompt).toContain('Place: INT. CRYPT.');
+ const empty = buildDatasetImagePrompt(UNIVERSE, {}, {}, 'objects');
+ expect(empty.prompt).toContain('Object: Unnamed.');
+ });
+
+ it('applies variation overrides to the object subject block', () => {
+ const { prompt } = buildDatasetImagePrompt(
+ UNIVERSE,
+ { name: 'Truthbreaker' },
+ { view: 'top-down view', expression: 'warm firelight', outfit: 'weathered wooden table' },
+ 'objects',
+ );
+ expect(prompt).toContain('top-down view');
+ expect(prompt).toContain('warm firelight');
+ expect(prompt).toContain('setting: weathered wooden table');
+ });
+
+ it('treats an unknown kind as characters', () => {
+ const { negativePrompt } = buildDatasetImagePrompt(UNIVERSE, { name: 'X' }, {}, 'bogus');
+ expect(negativePrompt).toContain('distorted anatomy');
+ });
+});
+
+describe('deriveVariationAxes', () => {
+ it('returns lighting/setting axes for objects', () => {
+ const axes = deriveVariationAxes({ entryKind: 'objects' });
+ expect(axes.expressions).toContain('soft studio lighting');
+ expect(axes.outfits).toContain('plain studio plinth');
+ });
+
+ it('returns lighting/setting axes for places', () => {
+ const axes = deriveVariationAxes({ entryKind: 'places' });
+ expect(axes.expressions).toContain('clear daylight');
+ expect(axes.outfits).toContain('signature environment');
+ });
+
+ it('derives character axes from canon expressions/wardrobes', () => {
+ const axes = deriveVariationAxes({
+ entryKind: 'characters',
+ expressions: [{ name: 'smiling' }, { name: 'scowling' }],
+ wardrobes: [{ name: 'battle armor' }],
+ });
+ expect(axes.expressions).toEqual(['smiling', 'scowling']);
+ expect(axes.outfits).toEqual(['battle armor']);
+ });
+
+ it('falls back to default character axes when canon is empty', () => {
+ const axes = deriveVariationAxes({});
+ expect(axes.expressions.length).toBeGreaterThan(0);
+ expect(axes.outfits).toEqual(['signature outfit']);
+ });
+});
diff --git a/server/services/loraDatasets.js b/server/services/loraDatasets.js
index f64ebc1421..b953db10ba 100644
--- a/server/services/loraDatasets.js
+++ b/server/services/loraDatasets.js
@@ -130,7 +130,7 @@ export async function getDataset(id) {
* can't drift between the two write paths. Returns `{ subject, snapshot }`
* (the live canon entry plus the persisted shape).
*/
-export async function resolveDatasetSubjectSnapshot(universeId, entryId, entryKind = 'characters') {
+async function resolveDatasetSubjectSnapshot(universeId, entryId, entryKind = 'characters') {
const normalizedKind = normalizeEntryKind(entryKind);
const universe = await getUniverse(universeId);
const subjects = Array.isArray(universe[normalizedKind]) ? universe[normalizedKind] : [];