Repository navigation
fix(live): resume after upstream drops, never freeze, log session lifecycle - #32
Merged
Merged
Conversation
Every /live connection now writes one-line 'live-session {json}' records to
the journal with a short session id: open, busy, start, upstream-ready,
upstream-error, upstream-close (code, reason, uptime), reconnecting,
going-away, gave-up, start-failed and end (duration, learner turns,
reconnects, client close code). Metadata only: no speech, audio, API key or
resumption handle.
Refs #21
Co-authored-by: Claude Code <noreply@anthropic.com>
Every Live setup now asks for session resumption and the server keeps the latest sessionResumptionUpdate handle. When the upstream closes mid conversation, the server holds the mic gate, tells the client 'reconnecting' then 'interrupted' (so the lost turn's queued audio is flushed), and reconnects with the handle: the same conversation carries on with no persona resend and no second greeting. Nothing is sent upstream until the new setup completes. Drops are retried with exponential backoff (3 attempts per drop, PARLEY_MAX_RECONNECTS total, default 8). goAway no longer warns the learner when the close can be resumed. The client shows a 'Reconnecting…' state. Refs #16 Co-authored-by: Claude Code <noreply@anthropic.com>
Every wait now has a limit. An upstream setup that does not complete within PARLEY_SETUP_TIMEOUT_MS (default 15 s) fails that attempt. A reply whose turnComplete never arrives is completed by the server PARLEY_TURN_WATCHDOG_MS (default 10 s) after its audio would have finished playing, so the mic reopens without cutting a burst-sent reply short. When the tutor can't be reached any more (reconnects exhausted, or no live model completes setup) the server sends an error, frees the MAX_SESSIONS slot at once and closes the socket. A client that leaves mid-setup no longer leaves the pending upstream running. In the browser, a remotely ended conversation now stops the microphone, flushes playback, returns to idle and says it ended; a stale socket's late close no longer ends a newer session. Adds an 'upstream-lost' browser repro scenario and a rejectConnections option to the fake upstream. Refs #17 Co-authored-by: Claude Code <noreply@anthropic.com>
A repeated start used to open a second upstream session and interleave two
voices into one client. It is now refused with {code:'already-started'} and
logged as start-rejected.
Co-authored-by: Claude Code <noreply@anthropic.com>
- public/app.js: one teardownSession() for the End button and remote
closes; endSession() uses setUiState('idle').
- server/live.ts: a settle() helper for the four setup outcomes; sendAudio
relies on _sendUpstream's readiness check.
- server/config.ts: live tuning defaults come from live.ts, defined once.
- server/index.ts: drop the ambiguous 'started' field from the end record.
Co-authored-by: Claude Code <noreply@anthropic.com>
This was referenced Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Conversations survive a dropped line (#16). Gemini Live sometimes closes the connection mid-conversation (we've seen close 1011 after about 8 minutes). Before, Parley opened a brand-new session, greeted the learner again and had forgotten everything. It could also only do this once. Now every session asks Gemini for resumption handles, and after a drop the server reconnects with the latest handle, so the conversation carries on where it was. While it reconnects:
reconnectingfollowed byinterrupted, so audio still queued from the lost turn is dropped rather than played over what comes next.Each drop gets 3 attempts with exponential backoff (starting at 0.5 s, capped at 4 s). A session allows 8 reconnects in total, set by
PARLEY_MAX_RECONNECTS.Nothing waits forever any more (#17).
PARLEY_SETUP_TIMEOUT_MS), and the next live model is tried.turnCompletenever arrives: the server completes the turn itself 10 s after the reply's audio would have finished playing (PARLEY_TURN_WATCHDOG_MS), so the mic reopens. The watchdog allows for the playback time, so it doesn't cut short gemini-3.8-live's burst-sent replies.MAX_SESSIONSslot straight away and closes the socket. The browser then turns the mic off, stops playback, returns to idle and says the conversation ended.Lifecycle records in the journal (#21). Each
/liveconnection writes one-linelive-session {json}records, stamped with a short session id: open, busy, start, upstream-ready, upstream-close (code, reason, uptime), reconnecting, reconnected, gave-up, setup-timeout, turn-watchdog and end (duration, learner turns, reconnects). A test checks they never contain speech, audio, the API key or the resumption handle.DEVELOPING.mdexplains how to grep them.Hardening. A second
starton the same socket is now rejected with{code:"already-started"}. Before, it opened a second upstream and two voices played into one client.Browser side. The cache version is bumped from v8 to v9. The late
closeof a stale socket no longer ends a newer session. Teardown is now shared between the End button and a close from the other side.Closes #16
Closes #17
Closes #21
Test evidence
npm run typecheckpasses.npm testand/usr/bin/node(v20.20.2)--test test/*.test.jsboth pass: 136 tests, 130 pass, 0 fail, 6 todo. Before this change it was 124 tests, 110 pass, 14 todo. Eight harnesstodotests are now regression tests, and there are new tests for the resumption setup, repeated drops, the reconnect limit and backoff, the burst-safe watchdog, config parsing and the session logger.scripts/repro-browser.mjs(headless Chrome, fake mic, fake upstream), before onmainand after on this branch:[1, 1](greeted again)[1, 0, 0]activeSessions1)activeSessions0Real API check. The resumption flow ran once against
gemini-3.8-livewith the realGeminiLiveSession: greeting, then a turn ("my favourite fruit is a pomegranate"), then a forced drop. The resumed setup was accepted in 491 ms with no second greeting. Asked afterwards, the tutor answered "Your favorite fruit is a pomegranate."Not in this PR
todos are other issues: the thinking state, Parley misunderstands the user's language and asks them to repeat phrases they never said #14 hearing/persona, and ACCESS_TOKENS. So is thedouble-tapbrowser scenario, which still gives 2 mic tracks.🤖 Generated with Claude Code