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): version-gate the chiptune track fields, cap loop duration, fix the provider-pin race and chiptune remix seeding

[._.]/ Adam Eivy82f2f0788daf
diff --git a/client/src/components/music/ChiptunePanel.jsx b/client/src/components/music/ChiptunePanel.jsx
index e837feebe5..f8632363c3 100644
--- a/client/src/components/music/ChiptunePanel.jsx
+++ b/client/src/components/music/ChiptunePanel.jsx
@@ -25,7 +25,7 @@ import {
const slugify = (s) => String(s || '').toLowerCase().trim().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 64);
const DEFAULT_SUBDIR = 'game/assets/music';
-export default function ChiptunePanel({ track, onTrackUpdate }) {
+export default function ChiptunePanel({ track, onTrackUpdate, remix }) {
const [prompt, setPrompt] = useState(track?.chiptunePrompt || '');
const [fresh, setFresh] = useState(false);
const [generating, setGenerating] = useState(false);
@@ -38,13 +38,17 @@ export default function ChiptunePanel({ track, onTrackUpdate }) {
const [publishSubdir, setPublishSubdir] = useState(DEFAULT_SUBDIR);
const [publishSlug, setPublishSlug] = useState('');
const [publishedFiles, setPublishedFiles] = useState(null);
+ // Saved provider/model pin, held until the provider list has loaded — the
+ // hook auto-selects a default when its list arrives, so applying the pin
+ // immediately would race that load and be nondeterministically overwritten.
+ const [savedPin, setSavedPin] = useState(null);
const musicSettingsRef = useRef({});
const mountedRef = useRef(true);
useEffect(() => () => { mountedRef.current = false; }, []);
const {
providers, selectedProviderId, selectedModel, availableModels,
- setSelectedProviderId, setSelectedModel,
+ setSelectedProviderId, setSelectedModel, loading: providersLoading,
} = useProviderModels({ silent: true });
const score = track?.chiptuneScore || null;
@@ -68,22 +72,38 @@ export default function ChiptunePanel({ track, onTrackUpdate }) {
setPublishSlug(slugify(track?.title));
}, [track?.id]);
- // Load saved prefs (provider pin + publish target) once. The provider pin is
- // applied when the provider list has loaded; a stale saved id degrades to the
- // hook's default selection.
+ // Remix from a chiptune take: seed the panel prompt with the take's prompt.
+ // Keyed on the nonce so re-remixing the same take re-applies.
+ useEffect(() => {
+ if (remix?.prompt) setPrompt(remix.prompt);
+ }, [remix?.nonce, remix?.prompt]);
+
+ // Load saved prefs once. Publish prefs apply immediately; the provider pin
+ // is parked in `savedPin` and applied by the effect below only after the
+ // provider list has loaded.
useEffect(() => {
getSettings({ silent: true }).then((settings) => {
if (!mountedRef.current) return;
const music = settings?.music || {};
musicSettingsRef.current = music;
const saved = music.chiptune || {};
- if (saved.providerId) setSelectedProviderId(saved.providerId);
- if (saved.model) setSelectedModel(saved.model);
+ if (saved.providerId) setSavedPin({ providerId: saved.providerId, model: saved.model || '' });
if (saved.publishAppId) setPublishAppId(saved.publishAppId);
if (saved.publishSubdir) setPublishSubdir(saved.publishSubdir);
}).catch(() => {});
}, []);
+ // Apply the saved provider pin once providers are loaded (a stale saved id
+ // that no longer exists degrades to the hook's own default selection).
+ useEffect(() => {
+ if (!savedPin || providersLoading || !providers.length) return;
+ if (providers.some((p) => p.id === savedPin.providerId)) {
+ setSelectedProviderId(savedPin.providerId);
+ if (savedPin.model) setSelectedModel(savedPin.model);
+ }
+ setSavedPin(null); // apply once
+ }, [savedPin, providersLoading, providers, setSelectedProviderId, setSelectedModel]);
+
const summary = useMemo(() => {
if (!score) return null;
const { totalSec } = buildChiptuneSchedule(score);
diff --git a/client/src/components/music/TracksManager.jsx b/client/src/components/music/TracksManager.jsx
index 87c8f637c2..5e252bd2c6 100644
--- a/client/src/components/music/TracksManager.jsx
+++ b/client/src/components/music/TracksManager.jsx
@@ -78,6 +78,7 @@ export default function TracksManager() {
// re-applies). See remixRender below.
const [modalRender, setModalRender] = useState(null);
const [remix, setRemix] = useState(null);
+ const [chiptuneRemix, setChiptuneRemix] = useState(null);
// Music Video projects, for the MIDI read-through: MuScriptor transcriptions
// are stored on the MV project that links a track, not on the track itself.
const [mvProjects, setMvProjects] = useState([]);
@@ -126,6 +127,7 @@ export default function TracksManager() {
setLibraryOpen(false);
setModalRender(null);
setRemix(null);
+ setChiptuneRemix(null);
};
const selectTrack = (t) => navigate(`/music/tracks/${encodeURIComponent(t.id)}`);
@@ -297,15 +299,20 @@ export default function TracksManager() {
// model/duration, and close the modal so the panel is in view.
const remixRender = (render) => {
setModalRender(null);
- // A chiptune take remixes in the chiptune panel; everything else seeds the
- // audio-model panel below.
- setGenMode(render.engine === 'chiptune' ? 'chiptune' : 'audio');
+ remixNonceRef.current += 1;
+ // A chiptune take remixes in the chiptune panel: seed ITS prompt (not the
+ // audio-model form's prompt — that field belongs to the diffusion engines).
+ if (render.engine === 'chiptune') {
+ setGenMode('chiptune');
+ setChiptuneRemix({ prompt: render.prompt || '', nonce: remixNonceRef.current });
+ return;
+ }
+ setGenMode('audio');
setForm((f) => ({
...f,
...(render.prompt ? { prompt: render.prompt } : {}),
...(render.lyrics ? { lyrics: render.lyrics } : {}),
}));
- remixNonceRef.current += 1;
setRemix({ engineId: render.engine, modelId: render.modelId, durationSec: render.durationSec, nonce: remixNonceRef.current });
};
@@ -440,6 +447,7 @@ export default function TracksManager() {
{genMode === 'chiptune' ? (
<ChiptunePanel
track={persisted}
+ remix={chiptuneRemix}
onTrackUpdate={(updated) => {
upsertLocal(updated); // list update is id-keyed → always safe
if (selectedIdRef.current === updated.id) {
diff --git a/server/lib/chiptuneScore.js b/server/lib/chiptuneScore.js
index d7e8a90091..6cdfc8632a 100644
--- a/server/lib/chiptuneScore.js
+++ b/server/lib/chiptuneScore.js
@@ -32,6 +32,12 @@ export const CHIPTUNE_LIMITS = Object.freeze({
ORDER_MAX: 32,
NOTES_PER_CHANNEL_MAX: 512,
TOTAL_STEPS_MAX: 8192,
+ // Wall-clock cap on the loop. Steps alone don't bound duration (40 BPM at
+ // 1 step/beat = 1.5s per step), and the offline renderer allocates
+ // ~176 KB/sec of PCM — an unbounded schema-valid score could demand
+ // gigabytes from one errant LLM response. 3 minutes is far beyond any
+ // sane background loop.
+ MAX_LOOP_SEC: 180,
TITLE_MAX: 120,
});
@@ -112,6 +118,10 @@ export const chiptuneScoreSchema = z.object({
if (totalSteps > CHIPTUNE_LIMITS.TOTAL_STEPS_MAX) {
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['order'], message: `loop is too long (${totalSteps} steps > ${CHIPTUNE_LIMITS.TOTAL_STEPS_MAX})` });
}
+ const totalSec = totalSteps * (60 / (score.bpm * score.stepsPerBeat));
+ if (totalSec > CHIPTUNE_LIMITS.MAX_LOOP_SEC) {
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['order'], message: `loop is too long (${Math.round(totalSec)}s > ${CHIPTUNE_LIMITS.MAX_LOOP_SEC}s)` });
+ }
});
/**
diff --git a/server/lib/chiptuneScore.test.js b/server/lib/chiptuneScore.test.js
index 50b8ef6228..1f6b5f8694 100644
--- a/server/lib/chiptuneScore.test.js
+++ b/server/lib/chiptuneScore.test.js
@@ -53,15 +53,29 @@ describe('chiptuneScoreSchema', () => {
expect(chiptuneScoreSchema.safeParse(score).success).toBe(false);
});
- it('rejects a loop that exceeds the total-step cap', () => {
+ it('accepts a long-but-bounded loop and rejects one past the caps', () => {
const score = validScore();
+ score.bpm = 240; // stepSec 0.0625 — keeps a long order under the duration cap
score.patterns.A.bars = 16; // 256 steps per order entry
- score.order = Array(CHIPTUNE_LIMITS.ORDER_MAX).fill('A'); // 8192... exactly at cap
+ score.order = Array(11).fill('A'); // 2816 steps ≈ 176s — inside both caps
expect(chiptuneScoreSchema.safeParse(score).success).toBe(true);
- score.stepsPerBeat = 5; // push past the cap
+ score.order = Array(CHIPTUNE_LIMITS.ORDER_MAX).fill('A'); // 8192 steps / 512s — past both
expect(chiptuneScoreSchema.safeParse(score).success).toBe(false);
});
+ it('rejects a schema-valid-shape score whose loop exceeds the duration cap', () => {
+ // 40 BPM at 1 step/beat = 1.5s/step: 16 bars × 4 steps/bar × 3 order
+ // entries = 192 steps = 288s — well under the step cap but over 180s.
+ const score = validScore();
+ score.bpm = 40;
+ score.stepsPerBeat = 1;
+ score.patterns.A.bars = 16;
+ score.order = ['A', 'A', 'A'];
+ const r = chiptuneScoreSchema.safeParse(score);
+ expect(r.success).toBe(false);
+ expect(JSON.stringify(r.error.issues)).toContain('loop is too long');
+ });
+
it('rejects a wrong version and non-integer steps', () => {
expect(chiptuneScoreSchema.safeParse({ ...validScore(), version: 2 }).success).toBe(false);
const score = validScore();
diff --git a/server/lib/schemaVersions.js b/server/lib/schemaVersions.js
index e5e6408dc0..862e88b104 100644
--- a/server/lib/schemaVersions.js
+++ b/server/lib/schemaVersions.js
@@ -224,7 +224,13 @@ export const PORTOS_SCHEMA_VERSIONS = Object.freeze({
// only track sync pauses with old peers; artists/albums keep flowing. The
// backfill itself needs no migration — `sanitizeTrack` synthesizes a render
// from the legacy active pointer on read (see services/tracks/logic.js).
- tracks: 2,
+ // tracks v3 = `track.chiptuneScore`/`chiptunePrompt` (#2911, the LLM-composed
+ // looping 8-bit score). Version-gated for the identical strip-and-push-back
+ // reason as v2: a ≤v2 peer re-sanitizing through its chiptune-unaware
+ // `sanitizeTrack` would silently drop the score and LWW the loss back onto
+ // the composing peer. (The fields are also excluded from the conflict-journal
+ // content hash — see lib/conflictJournal.js HASH_EXCLUDED_FIELDS.)
+ tracks: 3,
// v1 = creative ingredients catalog (Postgres tables: catalog_scraps,
// catalog_ingredients, catalog_ingredient_sources, catalog_ingredient_refs).
// v2 = `catalog_ingredients.search_tsv` expanded to also index the
diff --git a/server/services/chiptune.js b/server/services/chiptune.js
index 67ce26caa7..c21fd0472a 100644
--- a/server/services/chiptune.js
+++ b/server/services/chiptune.js
@@ -78,7 +78,7 @@ Rules:
- pulse1 carries melody, pulse2 harmony/counter-melody, triangle the bassline, noise the drums.
- Tonal pitches are scientific notation ("C5", "F#3", "Bb2"). Noise pitches are ONLY: ${CHIPTUNE_NOISE_PRESETS.join(', ')}.
- "step" is the note's onset within its pattern (0-indexed, stepsPerBeat × beatsPerBar × bars steps per pattern); "len" is its length in steps. Notes must fit inside their pattern.
-- 1-${CHIPTUNE_LIMITS.PATTERNS_MAX} patterns, order length 1-${CHIPTUNE_LIMITS.ORDER_MAX}. Aim for a 15-40 second loop that ends back where it starts musically (the playback loops the whole order seamlessly).
+- 1-${CHIPTUNE_LIMITS.PATTERNS_MAX} patterns, order length 1-${CHIPTUNE_LIMITS.ORDER_MAX}, total loop under ${CHIPTUNE_LIMITS.MAX_LOOP_SEC}s. Aim for a 15-40 second loop that ends back where it starts musically (the playback loops the whole order seamlessly).
- Write real music: a memorable melody, movement in the bass, drums that groove. Vary velocity for feel.`;
}