Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(speech): cap takes at 2:30 — an oversized ws frame would drop the whole bridge (final review)
enesb3abc0636a6c
diff --git a/src/renderer/components/DictationOverlay.test.ts b/src/renderer/components/DictationOverlay.test.tsnew file mode 100644index 000000000..3771bb5bc--- /dev/null+++ b/src/renderer/components/DictationOverlay.test.ts@@ -0,0 +1,20 @@+import { describe, expect, it } from 'vitest'+import { isAtRecordingCap } from './DictationOverlay'++// Base64 int16 PCM runs ~2.6 MB/min; WS_MAX_PAYLOAD (src/server/ws.ts) is 8 MiB, so an unbounded+// take would eventually blow the ws frame budget and drop the whole bridge. The 2:30 hard cap+// (MAX_RECORDING_MS) is what DictationOverlay's elapsed poller checks each tick to auto-stop+// well under that line — pin the boundary here since it isn't otherwise exercised by any test.+describe('isAtRecordingCap', () => {+ it('is false just under the 2:30 cap', () => {+ expect(isAtRecordingCap(149_999)).toBe(false)+ })++ it('is true exactly at the cap', () => {+ expect(isAtRecordingCap(150_000)).toBe(true)+ })++ it('is true past the cap', () => {+ expect(isAtRecordingCap(200_000)).toBe(true)+ })+})diff --git a/src/renderer/components/DictationOverlay.tsx b/src/renderer/components/DictationOverlay.tsxindex 45517c190..681fbef3d 100644--- a/src/renderer/components/DictationOverlay.tsx+++ b/src/renderer/components/DictationOverlay.tsx@@ -51,6 +51,17 @@ export function appendTake(existing: string, take: string): string {const LEVEL_POLL_MS = 100 // ~10Hz+// Base64-encoded int16 PCM runs ~2.6 MB/min. The ws bridge caps a single frame at+// WS_MAX_PAYLOAD (8 MiB, see src/server/ws.ts) — a take left running past ~3 minutes would+// produce a transcribe payload big enough to blow that budget, and `ws` drops the WHOLE+// connection on an oversized frame, not just the one message. Auto-stop well under that line.+const MAX_RECORDING_MS = 150_000 // 2:30++/** Whether elapsed recording time has crossed the hard cap (see MAX_RECORDING_MS above). Pure. */+export function isAtRecordingCap(elapsedMs: number): boolean {+ return elapsedMs >= MAX_RECORDING_MS+}+export function DictationOverlay({ target, onClose }: DictationOverlayProps) {const { api } = useSession()const addLocalUser = useChatSessions((s) => s.addLocalUser)@@ -64,6 +75,7 @@ export function DictationOverlay({ target, onClose }: DictationOverlayProps) {const [elapsedMs, setElapsedMs] = useState(0)const [level, setLevel] = useState(0)const [sending, setSending] = useState(false)+ const [capped, setCapped] = useState(false)const captureRef = useRef<PcmCapture | null>(null)const consentAskedRef = useRef(false)@@ -85,6 +97,7 @@ export function DictationOverlay({ target, onClose }: DictationOverlayProps) {setError(null)setElapsedMs(0)setLevel(0)+ setCapped(false)}, [target?.nodeId])// Belt-and-braces: if this component unmounts mid-recording (parent flips `open` without going@@ -97,8 +110,28 @@ export function DictationOverlay({ target, onClose }: DictationOverlayProps) {}}, [clearTimer])+ const stopRecording = useCallback(async () => {+ clearTimer()+ const capture = captureRef.current+ captureRef.current = null+ if (!capture) return+ const pcm = capture.stop()+ setPhase('transcribing')+ try {+ const { text: transcribed } = await window.nodeTerminal.speech.transcribe(pcm)+ setText((prev) => appendTake(prev, transcribed))+ setPhase('text')+ } catch (err) {+ setError(err instanceof Error ? err.message : 'Transcription failed.')+ // Fall back to the text state (editable) if a prior take already produced some, else back+ // to idle so the mic button reappears.+ setPhase(text.trim() ? 'text' : 'idle')+ }+ }, [clearTimer, text])+const startRecording = useCallback(async () => {setError(null)+ setCapped(false)if (!consentAskedRef.current) {consentAskedRef.current = truetry {@@ -127,29 +160,17 @@ export function DictationOverlay({ target, onClose }: DictationOverlayProps) {setLevel(0)setPhase('recording')timerRef.current = setInterval(() => {- setElapsedMs(Date.now() - startedAtRef.current)+ const elapsed = Date.now() - startedAtRef.current+ setElapsedMs(elapsed)setLevel(captureRef.current?.level() ?? 0)+ if (isAtRecordingCap(elapsed)) {+ // clearTimer() inside stopRecording fires synchronously before any await, so this can't+ // re-enter on the next tick.+ setCapped(true)+ void stopRecording()+ }}, LEVEL_POLL_MS)- }, [])-- const stopRecording = useCallback(async () => {- clearTimer()- const capture = captureRef.current- captureRef.current = null- if (!capture) return- const pcm = capture.stop()- setPhase('transcribing')- try {- const { text: transcribed } = await window.nodeTerminal.speech.transcribe(pcm)- setText((prev) => appendTake(prev, transcribed))- setPhase('text')- } catch (err) {- setError(err instanceof Error ? err.message : 'Transcription failed.')- // Fall back to the text state (editable) if a prior take already produced some, else back- // to idle so the mic button reappears.- setPhase(text.trim() ? 'text' : 'idle')- }- }, [clearTimer, text])+ }, [stopRecording])const handleClose = useCallback(() => {if (phase === 'recording') {@@ -278,7 +299,7 @@ export function DictationOverlay({ target, onClose }: DictationOverlayProps) {{phase === 'transcribing' && (<div className="dictation__transcribing"><span className="dictation__spinner" />- <span>Transcribing…</span>+ <span>{capped ? 'Recording capped at 2:30 — transcribing.' : 'Transcribing…'}</span></div>)}