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 2): StrictMode-safe mounted guard, own-key order lookup, stale-pin/target/OGG cleanup
[._.]/ Adam Eivy54e3b203b506
diff --git a/client/src/components/music/ChiptunePanel.jsx b/client/src/components/music/ChiptunePanel.jsxindex f8632363c3..bd59fea7a5 100644--- a/client/src/components/music/ChiptunePanel.jsx+++ b/client/src/components/music/ChiptunePanel.jsx@@ -15,6 +15,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';import { Loader2, Wand2, Play, Square, Disc3, Gamepad2 } from 'lucide-react';import toast from '../ui/Toast';import useProviderModels from '../../hooks/useProviderModels';+import useMounted from '../../hooks/useMounted';import ProviderModelSelector from '../ProviderModelSelector';import { buildChiptuneSchedule, createChiptunePlayer } from '../../lib/chiptunePlayback.js';import {@@ -43,8 +44,10 @@ export default function ChiptunePanel({ track, onTrackUpdate, remix }) {// 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; }, []);+ // StrictMode-safe (re-armed on remount) — a plain `useRef(true)` + cleanup+ // would stay false after StrictMode's dev double-mount and wedge every+ // post-await state update.+ const mountedRef = useMounted();const {providers, selectedProviderId, selectedModel, availableModels,@@ -93,13 +96,19 @@ export default function ChiptunePanel({ track, onTrackUpdate, remix }) {}).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).+ // Apply the saved provider pin once providers are loaded. A stale saved+ // provider id degrades to the hook's own default selection; a stale saved+ // MODEL (removed/renamed since it was pinned) is skipped too — the select+ // doesn't render unmatched values, so applying it would silently send a+ // model the provider no longer has while displaying a different one.useEffect(() => {if (!savedPin || providersLoading || !providers.length) return;- if (providers.some((p) => p.id === savedPin.providerId)) {+ const provider = providers.find((p) => p.id === savedPin.providerId);+ if (provider) {setSelectedProviderId(savedPin.providerId);- if (savedPin.model) setSelectedModel(savedPin.model);+ const models = (provider.models?.length ? provider.models : [provider.defaultModel])+ .map((m) => (typeof m === 'string' ? m : m?.id)).filter(Boolean);+ if (savedPin.model && models.includes(savedPin.model)) setSelectedModel(savedPin.model);}setSavedPin(null); // apply once}, [savedPin, providersLoading, providers, setSelectedProviderId, setSelectedModel]);@@ -174,8 +183,14 @@ export default function ChiptunePanel({ track, onTrackUpdate, remix }) {const list = await getApps({ silent: true }).catch(() => []);if (!mountedRef.current) return;// Publishable targets are managed apps with a repo on disk — PortOS- // itself is excluded (its repo is not a game asset destination).- setApps((Array.isArray(list) ? list : []).filter((a) => a.repoPath && a.id !== 'portos-default' && !a.archived));+ // itself is excluded (its repo is not a game asset destination); the+ // server enforces the same policy.+ const publishable = (Array.isArray(list) ? list : []).filter((a) => a.repoPath && a.id !== 'portos-default' && !a.archived);+ setApps(publishable);+ // A remembered target that is no longer publishable (deleted/archived/+ // repo-less) would leave the select showing nothing while Publish sends+ // the stale id — clear it so the user picks a live target.+ setPublishAppId((id) => (id && !publishable.some((a) => a.id === id) ? '' : id));}setPublishOpen((o) => !o);};diff --git a/server/lib/chiptuneScore.js b/server/lib/chiptuneScore.jsindex 337c28a430..f622843d0b 100644--- a/server/lib/chiptuneScore.js+++ b/server/lib/chiptuneScore.js@@ -114,7 +114,10 @@ export const chiptuneScoreSchema = z.object({}}for (const name of score.order) {- if (!score.patterns[name]) {+ // Object.hasOwn, not truthiness: an order entry like "toString" or+ // "constructor" resolves through the prototype chain to a function+ // (truthy), then every downstream `.bars` read is undefined → NaN math.+ if (!Object.hasOwn(score.patterns, name)) {ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['order'], message: `order references unknown pattern "${name}"` });return;}diff --git a/server/lib/chiptuneScore.test.js b/server/lib/chiptuneScore.test.jsindex abc118cbe7..8ac2ea0f65 100644--- a/server/lib/chiptuneScore.test.js+++ b/server/lib/chiptuneScore.test.js@@ -41,6 +41,14 @@ describe('chiptuneScoreSchema', () => {expect(chiptuneScoreSchema.safeParse(score).success).toBe(false);});+ it('rejects prototype-chain order entries that are not own pattern keys', () => {+ for (const name of ['toString', 'constructor']) {+ const score = validScore();+ score.order = [name];+ expect(chiptuneScoreSchema.safeParse(score).success).toBe(false);+ }+ });+it('rejects notes on an undeclared channel', () => {const score = validScore();score.patterns.A.notes.pulse2 = [{ step: 0, pitch: 'G4', len: 2 }];diff --git a/server/services/chiptune.js b/server/services/chiptune.jsindex c21fd0472a..19bda60e2d 100644--- a/server/services/chiptune.js+++ b/server/services/chiptune.js@@ -121,13 +121,20 @@ export async function generateChiptuneScore({ trackId, prompt, providerId, model// or `<basename>.wav` when ffmpeg isn't installed. Returns the filename used.async function renderScoreToFile(score, dir, basename) {const wavPath = join(dir, `${basename}.wav`);+ const oggPath = join(dir, `${basename}.ogg`);await atomicWrite(wavPath, renderScoreToWav(score)); // ensureDir + temp-renameconst bin = await findFfmpeg();- if (!bin) return `${basename}.wav`;- const oggPath = join(dir, `${basename}.ogg`);+ if (!bin) {+ // WAV fallback: drop any stale <slug>.ogg from an earlier ffmpeg-equipped+ // publish, or a game still referencing it would play the old composition+ // while the score JSON says otherwise.+ await unlink(oggPath).catch(() => {});+ return `${basename}.wav`;+ }const result = await runFfmpegProcess({ bin, args: ['-y', '-i', wavPath, '-c:a', 'libvorbis', '-q:a', '5', oggPath] });if (!result.ok) {console.error(`❌ Chiptune OGG encode failed (keeping WAV): ${result.reason}`);+ await unlink(oggPath).catch(() => {}); // stale or partial encode outputreturn `${basename}.wav`;}await unlink(wavPath).catch(() => {});