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): close training mic when a non-loop run ends naturally
Adam Eivy6a094f97ee00
diff --git a/client/src/components/songs/SongTraining.jsx b/client/src/components/songs/SongTraining.jsxindex d571fc2a1f..bb6c8a2192 100644--- a/client/src/components/songs/SongTraining.jsx+++ b/client/src/components/songs/SongTraining.jsx@@ -120,6 +120,21 @@ export default function SongTraining({// eslint-disable-next-line react-hooks/exhaustive-deps}, [stream]);+ // When a run finishes NATURALLY and we're not looping, close the mic and drop+ // out of the Stop state — otherwise the mic stays open (and the UI stuck on+ // Stop) until the user clicks Stop by hand. Looping keeps the mic open across+ // the relaunch gap; an armed-but-not-yet-started run (stream just landed,+ // `start()` pending) is gated by `armedRef` so this can't close the mic before+ // the first run even begins.+ const armedRef = useRef(false);+ useEffect(() => { if (running) armedRef.current = true; }, [running]);+ useEffect(() => {+ if (armedRef.current && !running && !loop) {+ armedRef.current = false;+ closeMic();+ }+ }, [running, loop, closeMic]);+// Tear the mic down on unmount.useEffect(() => () => {if (streamRef.current) streamRef.current.getTracks().forEach((t) => t.stop());diff --git a/client/src/components/songs/SongTraining.test.jsx b/client/src/components/songs/SongTraining.test.jsxindex 492298f305..2f1e475dde 100644--- a/client/src/components/songs/SongTraining.test.jsx+++ b/client/src/components/songs/SongTraining.test.jsx@@ -71,4 +71,29 @@ describe('SongTraining', () => {expect(screen.getByText(/last take/i)).toBeTruthy();expect(screen.getByText(/75%/)).toBeTruthy();});++ it('closes the mic when a non-loop run finishes naturally', async () => {+ // Track stop() on the mic's track so we can assert teardown without a real+ // AudioContext. The hook is mocked, so we drive `running` true→false by hand+ // and re-render — that edge is the natural-completion signal.+ const trackStop = vi.fn();+ const getUserMedia = vi.fn().mockResolvedValue({ getTracks: () => [{ stop: trackStop }] });+ Object.defineProperty(global.navigator, 'mediaDevices', {+ value: { getUserMedia }, configurable: true,+ });++ const { rerender } = render(<SongTraining score={SCORE} />);+ fireEvent.click(screen.getByRole('button', { name: /start/i }));+ await screen.findByRole('button', { name: /stop/i }); // mic landed → armed run++ // Hook reports the run started, then finished (running flips true → false).+ hookState = { ...hookState, running: true };+ rerender(<SongTraining score={SCORE} />);+ hookState = { ...hookState, running: false };+ rerender(<SongTraining score={SCORE} />);++ // Natural completion (loop off) must stop the mic track and drop back to Start.+ expect(trackStop).toHaveBeenCalled();+ expect(screen.getByRole('button', { name: /start/i })).toBeTruthy();+ });});