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 round 3): reject silent/over-dense scores, remix as fresh composition, reset playback state on audio-start failure
[._.]/ Adam Eivye0c8814a493c
diff --git a/client/src/components/music/ChiptunePanel.jsx b/client/src/components/music/ChiptunePanel.jsxindex bd59fea7a5..09c87e4a88 100644--- a/client/src/components/music/ChiptunePanel.jsx+++ b/client/src/components/music/ChiptunePanel.jsx@@ -75,10 +75,16 @@ export default function ChiptunePanel({ track, onTrackUpdate, remix }) {setPublishSlug(slugify(track?.title));}, [track?.id]);- // 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.+ // Remix from a chiptune take: seed the panel prompt with the take's prompt+ // and default to a FRESH composition — renders don't snapshot their score,+ // so iterating would revise the track's LATEST score, not the selected take.+ // The visible "start fresh" checkbox makes the choice overridable. Keyed on+ // the nonce so re-remixing the same take re-applies.useEffect(() => {- if (remix?.prompt) setPrompt(remix.prompt);+ if (remix?.prompt) {+ setPrompt(remix.prompt);+ setFresh(true);+ }}, [remix?.nonce, remix?.prompt]);// Load saved prefs once. Publish prefs apply immediately; the provider pin@@ -160,7 +166,12 @@ export default function ChiptunePanel({ track, onTrackUpdate, remix }) {return;}setPlaying(true);- await playerRef.current.play();+ // A blocked/interrupted AudioContext.resume() rejects — swallow it so the+ // state correction below still runs (otherwise the button wedges on+ // "Stop" with an idle transport).+ await playerRef.current.play().catch((err) => {+ console.error(`🎹 Chiptune preview failed to start: ${err.message}`);+ });if (mountedRef.current && !playerRef.current.isPlaying()) setPlaying(false);};diff --git a/server/lib/chiptuneScore.js b/server/lib/chiptuneScore.jsindex f622843d0b..6b72179c7f 100644--- a/server/lib/chiptuneScore.js+++ b/server/lib/chiptuneScore.js@@ -46,6 +46,12 @@ export const CHIPTUNE_LIMITS = Object.freeze({// is the physical ceiling of distinct-channel audio; anything past it is// pure overdraw.NOTE_SECONDS_MAX: 720,+ // Event-density ceiling (notes per second across the whole loop). The+ // browser preview creates 1-2 AudioNodes per note per loop pass — a+ // schema-valid quarter-second loop stuffed with 2 000 notes would mint+ // thousands of nodes per second and freeze the Music studio. Real chiptune+ // rarely exceeds ~20 notes/sec across four channels.+ EVENTS_PER_SEC_MAX: 64,TITLE_MAX: 120,});@@ -146,22 +152,43 @@ export const chiptuneScoreSchema = z.object({}// Bound the aggregate VOICED time the renderer will synthesize (see// NOTE_SECONDS_MAX) — the duration cap alone doesn't bound overlapping-note- // render work. Mirrors buildScoreEvents' clamp semantics (len clamped to the- // pattern end; out-of-pattern notes contribute nothing).+ // render work — plus event density (see EVENTS_PER_SEC_MAX, the browser+ // preview's AudioNode budget) and require at least one AUDIBLE event, so an+ // all-rests / all-unparseable / all-muted response triggers the runner's+ // schema retry instead of persisting a silent "successful" composition.+ // Mirrors buildScoreEvents' semantics (len clamped to the pattern end;+ // out-of-pattern notes contribute nothing; a tonal pitch must parse, a+ // noise pitch must be a known preset).+ const channelById = new Map(score.channels.map((c) => [c.id, c]));let voicedSteps = 0;+ let eventCount = 0;+ let audible = 0;for (const name of score.order) {const pattern = score.patterns[name];const steps = pattern.bars * score.beatsPerBar * score.stepsPerBeat;- for (const notes of Object.values(pattern.notes || {})) {+ for (const [channelId, notes] of Object.entries(pattern.notes || {})) {+ const channel = channelById.get(channelId);for (const note of notes) {if (note.step >= steps) continue;voicedSteps += Math.min(note.len, steps - note.step);+ eventCount += 1;+ if (!channel || (channel.gain ?? 0.5) === 0 || (note.vel ?? 0.8) === 0) continue;+ const sounds = channel.wave === 'noise'+ ? CHIPTUNE_NOISE_PRESETS.includes(note.pitch)+ : pitchToMidi(note.pitch) != null;+ if (sounds) audible += 1;}}}if (voicedSteps * stepSec > CHIPTUNE_LIMITS.NOTE_SECONDS_MAX) {ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['patterns'], message: `too much voiced audio (${Math.round(voicedSteps * stepSec)}s of notes > ${CHIPTUNE_LIMITS.NOTE_SECONDS_MAX}s)` });}+ if (totalSec > 0 && eventCount / totalSec > CHIPTUNE_LIMITS.EVENTS_PER_SEC_MAX) {+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['patterns'], message: `too many notes for the loop length (${Math.round(eventCount / totalSec)}/s > ${CHIPTUNE_LIMITS.EVENTS_PER_SEC_MAX}/s)` });+ }+ if (audible === 0) {+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['patterns'], message: 'score has no audible notes (every note is out of range, unparseable, or muted)' });+ }});/**diff --git a/server/lib/chiptuneScore.test.js b/server/lib/chiptuneScore.test.jsindex 8ac2ea0f65..0fe2d8b704 100644--- a/server/lib/chiptuneScore.test.js+++ b/server/lib/chiptuneScore.test.js@@ -78,6 +78,26 @@ describe('chiptuneScoreSchema', () => {expect(JSON.stringify(r.error.issues)).toContain('too much voiced audio');});+ it('rejects a score with no audible notes (all rests/unparseable/muted)', () => {+ const silent = validScore();+ silent.patterns.A.notes = { pulse1: [{ step: 0, pitch: 'nonsense', len: 4 }] };+ const r = chiptuneScoreSchema.safeParse(silent);+ expect(r.success).toBe(false);+ expect(JSON.stringify(r.error.issues)).toContain('no audible notes');+ const muted = validScore();+ muted.patterns.A.notes = { pulse1: [{ step: 0, pitch: 'C5', len: 4, vel: 0 }] };+ expect(chiptuneScoreSchema.safeParse(muted).success).toBe(false);+ });++ it('rejects an event density that would freeze the preview', () => {+ // 16-step / 2s loop with 512 notes on one channel = 256 events/sec.+ const score = validScore();+ score.patterns.A.notes.pulse1 = Array.from({ length: 512 }, (_, i) => ({ step: i % 16, pitch: 'C5', len: 1 }));+ const r = chiptuneScoreSchema.safeParse(score);+ expect(r.success).toBe(false);+ expect(JSON.stringify(r.error.issues)).toContain('too many notes');+ });+it('rejects duplicate channel ids', () => {const score = validScore();score.channels.push({ id: 'pulse1', wave: 'square' });