Skip to content

fix(live): one mic pipeline, one conversation per device, close idle sessions - #34

Merged
Alorse merged 4 commits into
mainfrom
fix/single-mic-pipeline
Sep 29, 2026
Merged

Alorse merged 4 commits into
mainfrom
fix/single-mic-pipeline

Conversation

@Alorse

@Alorse Alorse commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Stacked on #33 (fix/honest-not-understood).

What changes for the learner

  • One microphone, and "off" means off (Only one microphone at a time, and off really means off #18). Before, a quick double tap opened two microphones, and turning the mic "off" left one of them recording. Now a tap while the mic is still starting is ignored. A second start joins the one already opening. If the conversation ends while the mic is still opening, the mic is released as soon as it arrives.
  • One conversation per device (Only one conversation at a time across tabs and the installed app #19). Before, if Parley was open in two tabs, or in a tab and the installed app, both could talk at once. Now, starting a conversation in one window ends it in the other, and the older window says "Parley is open in another window, so this conversation was closed here." This works in two ways:
    • In the browser: a BroadcastChannel tells the older window right away.
    • On the server: each device has a random id stored in localStorage and sent with start, and the server allows one conversation per id. This also covers a tab the phone has frozen, which cannot receive browser messages. An older conversation that is still connecting is ended too.
  • Closing conversations nobody is in (Close tutor sessions nobody is listening to #20). A /live connection with no sign of the learner (speech, typed text or taps) for PARLEY_IDLE_TIMEOUT_MS is closed, and the app says why (code: "idle"). The default is 5 minutes, and 0 turns it off. Mic frames alone don't count, because an open mic also streams silence. A socket that never starts is closed the same way. Two cases from the issue were already fixed in fix(live): resume after upstream drops, never freeze, log session lifecycle #32, and their harness tests keep passing: a learner who leaves during setup, and a second start on the same socket.

Public files changed, so the cache version is bumped to 10 (?v=10 in index.html, CACHE_NAME parley-v10, and sw.js?v=10).

Closes #18
Closes #19
Closes #20

Test evidence

node scripts/repro-browser.mjs (headless Chrome, fake mic, real server, fake Gemini):

scenario before after
double-tap 2 live mic tracks, 2 getUserMedia calls; 1 track still live after "Microphone off" 1 track, 1 call, 30.5–32 frames/s; 0 tracks and 0 frames/s after "off"
server-restart, then tap again 1 track, 29 frames/s (already fixed in #32) 1 track, 31.5 frames/s
upstream-drop-twice — resumed, 31 frames/s, 1 socket (one pipeline, not the 63/s in the issue)
upstream-lost socket closed, mic off, slot freed unchanged
two-tabs both tabs "Parley is speaking", 1 socket each tab 1: 0 sockets, 0 mic tracks, "Parley is open in another window…"; tab 2: speaking

Test suites. Both runs pass with 0 failures. The 2 remaining todo tests are outside this PR's scope: the thinking-state timer and ACCESS_TOKENS.

run before after
GOOGLE_API_KEY=ci-placeholder-key npm test (node 26) 143 tests, 141 pass 154 tests, 152 pass
/usr/bin/node --import tsx --test test/*.test.js (node 20) 143 tests, 141 pass 154 tests, 152 pass

npm run typecheck is clean.

New tests. I checked that each new test fails without its fix:

  • test/audio-capture.test.js: a start while opening joins it; a stop while opening releases the late mic; a start after a cancelled one opens exactly one mic; a failed open releases what it acquired.
  • Harness: Only one conversation at a time across tabs and the installed app #19 a newer start from the same device takes over, and the older one gets replaced and its upstream is closed. This also works while the older one is still being set up. Different devices don't affect each other.
  • Harness: Close tutor sessions nobody is listening to #20 a silent open mic and a socket that never starts are both closed with idle, the upstream is closed and the slot is freed, while transcribed speech and typed text keep the conversation open.
  • Config: the PARLEY_IDLE_TIMEOUT_MS default, 0 to disable, and invalid values. data.js: the device id is created once and shared.

No real-API run: these changes are about the connection lifecycle and never touch the Gemini setup or prompts.

🤖 Generated with Claude Code

Alorse and others added 4 commits September 29, 2026 08:54
A second tap while the mic was still connecting or opening started a
second capture next to the first, and turning the mic "off" then stopped
only one of them: the button said off while a track kept recording.

AudioCapture now joins a start that is already open or opening instead
of opening another mic, and a stop that lands mid-open releases whatever
that open acquires. The mic button ignores taps while it is busy, and a
session that ended while the mic was opening leaves it off.

Browser repro (double-tap): 2 live mic tracks and 1 still live after
"off" before; 1 track at 32 frames/s and none after "off" now.

Bumps the cache version to 10.

Refs #18

Co-authored-by: Claude Code <noreply@anthropic.com>
…lled app

With Parley open in two windows, both could hold a conversation at once:
two tutors talking over each other, each hearing the other through the
mic.

The app now keeps a random device id in localStorage and sends it with
start. The server keeps one conversation per id: a newer start ends the
older connection (even one still being set up) with code "replaced" and
a plain message. In the browser, a BroadcastChannel claim makes the older
window release its mic and socket at once and say why; a claim that
arrives while it is still connecting cancels quietly.

Browser repro (two-tabs): both tabs speaking before; now only the newer
tab holds a conversation and the older one shows "Parley is open in
another window".

Refs #19

Co-authored-by: Claude Code <noreply@anthropic.com>
A tab left open, or a phone put down with the mic on, kept its tutor
session running (and spending quota) until the upstream gave out.

Each /live connection now closes after PARLEY_IDLE_TIMEOUT_MS (5 min by
default, 0 disables it) without learner activity: transcribed speech,
typed text or taps. Mic frames alone don't count, since an open mic
streams silence too, and a socket that never starts is covered as well.
The client is told why (code "idle") and its upstream and slot are freed.

Leaving during setup and a second start on one socket were already
closed by earlier fixes; their harness tests keep passing.

Refs #20

Co-authored-by: Claude Code <noreply@anthropic.com>
…rror wording

The takeover, idle and start-failure paths each sent an error and then
closed the connection; they now share one helper, and the start failure
carries a code too. The idle default sits with the other live timing
defaults. The client keeps the wording for server error codes it owns
(busy, replaced) in one table, and showError ignores an empty message,
so the start-error wrapper goes.

Co-authored-by: Claude Code <noreply@anthropic.com>
@Alorse
Alorse changed the base branch from fix/honest-not-understood to main September 29, 2026 14:21
@Alorse
Alorse merged commit f2a71e1 into main Sep 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant