Skip to content

test(firmware): hold a multi-turn conversation in the voice e2e - #1050

Merged
ffMathy merged 19 commits into
mainfrom
test/firmware-long-conversation-e2e
Nov 27, 2026
Merged

ffMathy merged 19 commits into
mainfrom
test/firmware-long-conversation-e2e

Conversation

@ffMathy

@ffMathy ffMathy commented Nov 24, 2026

Copy link
Copy Markdown
Owner

What changed

The acoustic end-to-end test of the Voice PE (home-assistant-voice-firmware/.scripts/wake-word-e2e.sh) asked a single question. It now holds a six-turn conversation by default, ending with a goodbye that should make the agent call end_call.

  • Each reply is recorded on its own, starting only after the user's turn has finished playing. Recording while the host plays degrades WSLg audio, which is why the old script also waited. The replies are joined with a second of silence and compared against ElevenLabs' own recording of the call.
  • A reply counts as finished when the device's speaker_is_active_ true/false log lines balance and stay balanced for REPLY_SETTLE_MS (800 ms). That keeps the next turn well inside the agent's 3 s turn timeout. A false followed by another true within one turn is counted as an underrun.
  • The serial log is checked for instability: crashes and reboots, Speaker stalled, allocation failures, the error handler and low-memory warnings. PSRAM free at the start and end of the call is reported.
  • New exit code 4 when the call ends, or a reply never finishes, before the last turn. Instability exits 2, like playback defects.
  • Audio goes to Gemini as lossless FLAC, so a minutes-long conversation stays under the 20 MB inline request limit.
  • COMMAND_TEXT still runs a single turn, and TURNS_FILE reads custom turns, one per line. Turn audio is cached under a hash of its text and voice, so editing a turn re-synthesises it.

Also

  • Adds the upload (one-shot flash) and wake-word-test Turbo targets. serve already flashes, but it then follows the logs forever and holds the serial port the e2e needs.
  • Documents the firmware targets in the firmware AGENTS.md, and why there is deliberately no firmware deploy: Release runs bunx turbo deploy workspace-wide in CI. Adds a matching pointer in .claude/rules/turbo-commands.md.
  • Documents attaching the device over USB under WSL (usbipd bind, --auto-attach) and the root-owned .esphome/build left behind by old Docker builds.
  • Replaces the stale "no automated tests exist" note.

For reviewers

  • This is a hardware-in-the-loop script, so CI does not run it. Only bash -n has been run on it so far. The first real six-turn run on the device is in progress: current firmware is being flashed first, because the firmware on the device logged nothing over USB.
  • test type, so merging this does not cut a release.

🤖 Generated with Claude Code

@ffMathy
ffMathy force-pushed the test/firmware-long-conversation-e2e branch from a891319 to a7c33b2 Compare November 24, 2026 10:51
ffMathy and others added 10 commits November 24, 2026 14:12
The acoustic e2e asked one question, which cannot show what goes wrong
only later in a call: a reply cut short on the third turn, memory that
drains per turn, or a call that drops between turns. It now holds a
six-turn conversation by default, ending with a goodbye, and records
each reply on its own before joining them for the comparison.

It also reads the serial log for crashes, speaker stalls, allocation
failures and underruns, and fails with exit 4 when the call ends or a
reply never comes before the last turn. Audio goes to Gemini as FLAC so
a minutes-long conversation stays under the inline request limit.

Also:
- Adds the upload and wake-word-test Turbo targets, so flashing once
  and running the e2e go through Turbo like everything else
- Documents the firmware targets, why there is no firmware deploy,
  and attaching the device over USB under WSL
- Replaces the stale "no automated tests" note in the firmware AGENTS.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The device rebooted in the middle of a conversation. The backtrace
ended in operator new inside decode_and_play_base64_audio, growing
reply_prebuffer_: an abort, because exceptions are disabled, with over
3 MB of PSRAM still free.

The prebuffer was a std::vector on the default allocator. ESP-IDF
serves allocations under 16 KB from internal RAM, the vector's growth
steps were that size, and internal RAM runs low once the microphone,
the TLS socket and the speaker are all busy. It now uses ESPHome's
PSRAM-first RAMAllocator and reserves its capacity once at setup, so a
reply never allocates at all. The capacity is kept between replies
instead of being shrunk and regrown each time.

Also:
- Log free and largest-block internal RAM in the periodic memory line,
  and report its trend and low point in the e2e's device health
- Stop logging the signed URL; it carries the conversation signature
- Document the two-step USB flash that works around usbipd dropping
  the chip when esptool resets it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er used

The parser compared the drop in MALLOC_CAP_8BIT, which includes PSRAM,
with the drop in PSRAM alone, so any concurrent internal allocation
tripped it. And the deltas were unsigned, so memory freed by another
task during the parse wrapped into a huge allocation. It now measures
internal RAM only and clamps both deltas at zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A synthesised "Hey Jarvis" from laptop speakers peaks at 0.67-0.81 on
the hey_jarvis model against its 0.92 cutoff, while a real voice in the
same room wakes the device. Add a start_conversation API action that
starts the stream exactly as the wake word does, and WAKE_VIA=api in the
e2e to use it, so the conversation under test does not depend on how
well the host imitates a person.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The six-turn run held up on the device: no crash, no underruns, flat
memory, and end_call hung up on the goodbye. What the comparison called
cut-off replies were the agent ending a turn at a 0.3 s comma pause. Its
reply was already playing when the turn finished, so the recorder, which
opens only after playback, missed the opening words, and the half-duplex
mic lost the rest of the sentence.

The e2e now notices a reply that starts before its turn finished playing,
tells the comparison to expect those replies to start part-way, and exits
5 when that happens, so it is never reported as a speaker defect.

Also fixes:
- agent_chat_response_part fell through to the unknown-type fallback and
  was logged in full at WARN dozens of times per reply, stalling the
  logger for 100 ms mid-playback; it is now ignored

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reply used to end when the speaker had been off for 800 ms. The agent
can pause longer than that between sentences or speak twice, and the
device can still be holding audio it has not played, so the next turn
sometimes played while Jarvis was still talking, onto a mic the device
keeps shut while its speaker plays.

A reply now ends only when the speaker is off and no audio has arrived
for REPLY_SETTLE_MS, now 2.5 s. New audio or the speaker turning back on
restarts that clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The voice e2e showed Jarvis cutting in twice over. On turnEagerness
normal, the turn model ended a turn at a 0.3 s pause, after
"Interesting." or a sentence's first clause, and answered half a
sentence. And three seconds after each reply, turnTimeout had him speak
again ("Sir, I am still here") just as the next turn began. The Voice
speaker shuts its mic while it plays, so either way sir's words were
lost whole.

turnEagerness is now patient and turnTimeout 7 s, still well inside the
30 s silenceEndCallTimeout for hanging up on a finished request. The
camera integration spec's windows grow to match, and every doc that
quoted three seconds now says seven.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The agent can split one turn into two replies, so the reply count in the
reference drifted from the turn count, and the comparison flagged the
expected cut-in after "Interesting." as a defect in a different reply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With speculative turns on, the agent still answered at the full stop in
the middle of a two-sentence request, even on patient eagerness. With
them off, the Voice e2e's six turns arrived whole but for a one-word
"Interesting.", and the speaker's playback matched the reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main replaced every AGENTS.md with scoped rules while this branch was
open, so the notes this branch had added to them move into the rules:

- home-assistant-voice-firmware-usage: the targets, why there is no
  firmware deploy, and flashing over USB under WSL
- home-assistant-voice-firmware-acoustic-e2e: the conversation test, its
  exit codes, WAKE_VIA=api, and the settle wait against turnTimeout
- elevenlabs-hanging-up-when-he-goes-quiet: turnTimeout 7, patient
  eagerness, and speculative turns off, with why
- every rule that quoted the three-second turn timeout now says seven

Also fixes:
- the firmware rule still said no automated tests exist

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ffMathy
ffMathy force-pushed the test/firmware-long-conversation-e2e branch from 2256e0f to 0c45b52 Compare November 24, 2026 13:13
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Web preview

Taken down now that this pull request is closed.

ffMathy and others added 9 commits November 27, 2026 09:09
The microphone was shut for as long as the speaker played. The agent's turn
detection starts a reply after a complete sentence ("Please introduce
yourself.", "Interesting."), even with patient eagerness, and expects the
user carrying on to interrupt it. With the mic shut the rest of the turn
never arrived: "Make it about six sentences long" reached the agent as
"make sentences longer", and the sky-blue question after "Interesting." was
lost entirely while Jarvis talked over it.

The mic now stays open; the XMOS front end cancels the speaker's echo. Two
gates had to go: speaker_is_active_, and the activation-chime check, which
also fired whenever Jarvis spoke because a resampler speaker reports its
shared i2s output's buffer as its own.

The interruption event was logged and ignored. It now stops the speaker,
which discards the abandoned reply's queued audio, and audio carrying the
interrupted event_id or an earlier one is dropped as it arrives. The fast
path reads event_id by scanning, like the payload.

Verified on hardware: six turns, all three cut-ins abandoned and answered
in full, playback faithful.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the microphone open, a reply the agent starts at a pause and abandons
as soon as the turn goes on is the intended recovery, not a failure. Exit 5
now means the reply started during the turn and no interruption followed
it. Early replies are still named for the comparison, since their openings
fall before the recording window either way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the microphone open while Jarvis speaks, his voice came back in two
ways. Averaging the XMOS front end's two channels let the tails of five of
eight replies interrupt him with nobody speaking; sending channel 0 alone,
the echo-cancelled stream voice_assistant uses for speech-to-text, stopped
every one of them.

The conversation's first line still leaked, in three runs out of three:
the greeting came back as sir's turn ("Hello, Sam. How can I help?") and
Jarvis answered himself, while no later reply did. The microphone is shut
while that opening line plays. It comes before sir has a turn, so nothing
is lost, and until now the microphone was shut for it anyway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…words

The listening marker waited for HANDLE_MIC to log
activation_speaker_running=false, but that speaker runs for the whole
conversation, so it never came. Every run sat out the 15 s timeout, longer
than the agent's 7 s turnTimeout, and Jarvis spoke into the silence before
the first turn. The marker is now the greeting finishing, which is when the
device opens its microphone.

Each turn's trailing third of a second of silence is trimmed, so a reply
that starts while a turn is playing really did start before the words
ended. One that started promptly after them was reported as talking over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rule of its own for talking over Jarvis: why the microphone stays open,
the activation-speaker check that hid a second gate, channel 0, the opening
line, and what the device does with an interruption. The e2e rule now says
what exit 5 means with the microphone open, and how the test waits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Exit 5 failed a ten-turn run whose every turn reached the agent whole: the
reply to turn 1 began as its last word played, and the host's audio path
adds an unknown delay to when the room falls quiet, so timing cannot tell
that from talking over sir. What a cut-in costs is words, so the test now
counts them in ElevenLabs' transcript (the device's log cuts long lines
short), matching each user message to its turn by time. A turn passes at
85% of its words: speech-to-text misspells one now and then, while
"Interesting." alone is 7% of its turn and the lost "make it about six"
left a story request at 77%.

Verified: ten turns, every one heard whole, PASS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ElevenLabs opens each reply with 47 ms frames sent more than 250 ms
apart. The prebuffer was armed only for a conversation's first reply
(and after an interruption), so later replies played those frames into
an empty speaker and stuttered through their first syllables.

Hold audio whenever it would start into an empty speaker, and release a
held reply from loop() once it reaches its age limit, under a lock, so a
short reply's last frame is never left waiting. The speaker callback no
longer ends a reply that is still being held.

The e2e no longer counts an interruption as an underrun.

Also fixes:
- -Wformat warnings for uint32_t arguments in elevenlabs_stream.cpp

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… task

A connection dropped mid-reply ("Connection reset by peer") rebooted the
device. The error arrives on the websocket's task, and handle_error
disconnects, destroying the client from inside the task that was still
dispatching the event; the next event-loop call asserted on freed memory
(spinlock_acquire, lock->count == 0). Defer it to the main loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ffMathy
ffMathy merged commit 4c6a333 into main Nov 27, 2026
6 checks passed
@ffMathy
ffMathy deleted the test/firmware-long-conversation-e2e branch November 27, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant