Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(realtime): speaking past a pause no longer submits half the order

rubenluetke10-beep87dd046978c9
diff --git a/docs/BUGS.md b/docs/BUGS.md
index ea250780fb..cf7e191cad 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -9475,3 +9475,87 @@ reader is: a dropped HTTP client has lost the answer, while a person who hangs
up has withdrawn the request. The same cancellation means different things to
different callers, so survival has to be the CALLER's declaration, never the
work's default.
+
+## BUG-137: a spoken order is cut off after a few sentences — the guard that protects it reports its own ceiling as the user falling silent (HIGH, FIXED 2026-08-13)
+
+**Symptoms (maintainer report).** In realtime mode you cannot finish a long
+prompt. After roughly three or four sentences the turn submits by itself and
+the rest of the sentence is gone. Reported for the agentic-IDE case in
+particular — the truncated fragment is what gets typed into a coding pane and
+submitted with Enter, so a quarter-order becomes a real briefing.
+
+**Evidence.** `data/flight_recorder/<date>.jsonl` + `data/jarvis_desktop.log`,
+session `373af352`, 2026-08-13 16:46/16:47. Both turns were terminal-prompt
+orders; the recorded `user_text` of the second ends mid-phrase ("…and you know
+when you do a customer ID with a"). The log tells the whole story:
+
+```
+16:46:22.919 turn-state: LISTENING -> PROCESSING ← provider closed the input turn
+16:46:23.189 holding the dispatch — the microphone still carries the user's voice
+16:46:26.939 user stopped speaking after a 4.00s hold ← the CEILING, not the user
+...
+16:47:19.668 holding the dispatch — the microphone still carries the user's voice
+16:47:25.527 provider committed a boundary while the user is still audibly speaking
+```
+
+`4.00s` is `_USER_SPEAKING_DISPATCH_CAP_S` to the centisecond. At 16:47:25 —
+six seconds after the cut — the session's own microphone probe still said the
+user was talking.
+
+**Root.** Two layers, and the second one hid the first.
+
+1. **The provider was never asked to be patient.** `RealtimeSessionConfig`
+ carried exactly one turn-detection knob, `silence_duration_ms`, pinned to
+ `None` by the 2026-07-21 directive (a fixed window taxed every short
+ utterance and read as "done speaking but still listening" — that directive
+ was right). So `gemini_live.py` omitted `realtime_input_config` entirely
+ and inherited Gemini's native end-of-speech detection, which treats an
+ ordinary mid-sentence pause as end-of-turn. The knob that actually fits the
+ problem — `end_of_speech_sensitivity`, present in the installed SDK, and
+ unlike a silence window free for short utterances — appeared in **zero**
+ files in the repository.
+
+2. **The compensating guard was a fixed budget.** `_await_stable_input_boundary`
+ correctly detects that the microphone still carries the user's voice after a
+ premature commit (BUG-131's fix), but measured its authority as
+ `started + 4.0s` from the provider's commit. That is a budget for how long
+ the user may keep talking. Speak past it and the tail is dropped, the
+ truncated text is dispatched, and the pane is briefed with it.
+
+**Why it survived a day of live calls.** The release log line read
+`user stopped speaking after a 4.00s hold`. A timeout reported as an
+observation. Every truncation looked, in the log, like the guard working.
+
+**Fix.** Both layers, because either alone leaves the failure reachable:
+
+- `end_of_speech_sensitivity` added to `RealtimeSessionConfig` (default
+ `"low"`), wired in `gemini_live.py` behind an SDK capability probe (AP-21 —
+ an SDK without the enum opens on the provider default and says so in the
+ log) and in `openai_realtime.py` as semantic-VAD `eagerness`. Plain
+ `server_vad` has no equivalent and honestly keeps its default rather than
+ faking patience with a fixed window. `silence_duration_ms` stays unset: the
+ 2026-07-21 directive is untouched.
+- The microphone hold became a ROLLING window
+ (`_MIC_HOLD_STALE_TRANSCRIPT_S`, re-armed by every growth of the input
+ transcript) with an absolute backstop (`_MIC_HOLD_ABSOLUTE_CAP_S`). The
+ ceiling still bounds the only failure it was ever for — a floor stuck open
+ on room noise or a hot mic — because noise produces voiced frames but no
+ WORDS. A talking user keeps the floor indefinitely; a stuck floor releases
+ within one window. The provider-silence cap no longer fires while the
+ microphone is actively holding.
+- The release log line now distinguishes "the user stopped" from "the floor
+ stayed loud without producing a word".
+
+**Class.** A bounded guard whose bound is expressed in the units of the thing
+it is protecting. The ceiling on "how long may the microphone override the
+provider" was written as a duration of USER SPEECH, when the failure it exists
+for is a microphone that produces sound without content. Bound the failure
+mode, not the legitimate behaviour — and never let a guard log its own timeout
+in the vocabulary of a measurement.
+
+**Tests.** `tests/unit/realtime/test_utterance_continuation.py`
+(`test_a_long_order_survives_past_the_hold_ceiling` — verified to FAIL against
+the fixed-budget form, losing the final fragment exactly as the live call did;
+`test_a_loud_but_wordless_floor_still_releases_the_order` for the bounded
+half) and `tests/unit/realtime/test_gemini_live.py` (default sensitivity, the
+opt-out, and the old-SDK degradation).
diff --git a/jarvis/plugins/realtime/gemini_live.py b/jarvis/plugins/realtime/gemini_live.py
index bf685a70bb..7b16fadd72 100644
--- a/jarvis/plugins/realtime/gemini_live.py
+++ b/jarvis/plugins/realtime/gemini_live.py
@@ -57,6 +57,45 @@ def _compression_kwargs(types: Any) -> dict[str, Any]:
}
+_END_SENSITIVITY_MEMBERS = {
+ "low": "END_SENSITIVITY_LOW",
+ "high": "END_SENSITIVITY_HIGH",
+}
+
+
+def _end_of_speech_sensitivity(types: Any, preference: str | None) -> Any | None:
+ """Resolve the requested end-of-speech patience, or None on an old SDK.
+
+ Probed by SDK capability, never a version pin (AP-21): an SDK without the
+ enum — or without the field on AutomaticActivityDetection — opens a
+ session on the provider default instead of failing to open at all. The
+ degradation is loud, because silently inheriting Gemini's eager default is
+ exactly the bug this setting exists to fix.
+ """
+ wanted = str(preference or "").strip().lower()
+ if not wanted:
+ return None
+ member = _END_SENSITIVITY_MEMBERS.get(wanted)
+ if member is None:
+ log.warning(
+ "gemini-live: unknown end-of-speech sensitivity %r; using the default",
+ preference,
+ )
+ return None
+ enum_cls = getattr(types, "EndSensitivity", None)
+ detection_cls = getattr(types, "AutomaticActivityDetection", None)
+ fields = getattr(detection_cls, "model_fields", None) or {}
+ resolved = getattr(enum_cls, member, None) if enum_cls is not None else None
+ if resolved is None or "end_of_speech_sensitivity" not in fields:
+ log.warning(
+ "gemini-live: installed google-genai SDK cannot set the "
+ "end-of-speech sensitivity; Gemini's own eager turn detection may "
+ "close a turn on a mid-sentence pause"
+ )
+ return None
+ return resolved
+
+
def _usage_from_metadata(md: Any) -> dict[str, int] | None:
"""Token counts of one generation as a flat dict, or None when empty.
@@ -578,10 +617,25 @@ class GeminiLiveProvider:
voice_name=voice
)
)
- # An unset window (None/0) omits realtime_input_config entirely so
- # Gemini's native automatic activity detection decides the turn end;
- # only an explicit override forces a fixed silence window.
+ # An unset window (None/0) sends no silence_duration_ms at all, so
+ # Gemini keeps deciding turn ends on its own timing; only an explicit
+ # override forces a fixed window (the 2026-07-21 directive).
silence_ms = getattr(cfg, "silence_duration_ms", None)
+ # End-of-speech SENSITIVITY is a different knob and the one that
+ # matters here: Gemini's native default reads an ordinary mid-sentence
+ # pause as the end of the turn. Live 2026-08-13 16:46/16:47 — one
+ # spoken brief for a coding pane was committed twice while the
+ # microphone still carried the user's voice, and the pane was handed a
+ # quarter of the sentence. LOW reads a pause as a pause and costs a
+ # finished short utterance nothing.
+ aad_kwargs: dict[str, Any] = {}
+ if silence_ms:
+ aad_kwargs["silence_duration_ms"] = int(silence_ms)
+ sensitivity = _end_of_speech_sensitivity(
+ types, getattr(cfg, "end_of_speech_sensitivity", None)
+ )
+ if sensitivity is not None:
+ aad_kwargs["end_of_speech_sensitivity"] = sensitivity
# Gemini 3.1 rejects client_content (1007, the whole connection dies)
# unless the setup declares it as initial history — so the declaration
# and the seed travel together, and neither happens without the other
@@ -608,11 +662,11 @@ class GeminiLiveProvider:
"realtime_input_config": types.RealtimeInputConfig(
automatic_activity_detection=types.AutomaticActivityDetection(
disabled=False,
- silence_duration_ms=int(silence_ms),
+ **aad_kwargs,
)
)
}
- if silence_ms
+ if aad_kwargs
else {}
),
**(
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index da086280ae..c0681e8152 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -266,6 +266,15 @@ def _session_payload(
silence_ms = getattr(cfg, "silence_duration_ms", None)
if turn_detection == "server_vad" and silence_ms:
turn_detection_config["silence_duration_ms"] = int(silence_ms)
+ # OpenAI's name for end-of-speech sensitivity is semantic-VAD "eagerness":
+ # low = let the user take their time before the turn is called over. Plain
+ # server_vad has no equivalent knob at all, so a session configured for it
+ # honestly keeps the provider default rather than faking patience with a
+ # fixed silence window (which would tax every short utterance — the very
+ # trade the 2026-07-21 directive rejected).
+ sensitivity = str(getattr(cfg, "end_of_speech_sensitivity", "") or "").lower()
+ if turn_detection == "semantic_vad" and sensitivity in {"low", "high"}:
+ turn_detection_config["eagerness"] = sensitivity
payload: dict[str, Any] = {
"type": "realtime",
diff --git a/jarvis/realtime/protocol.py b/jarvis/realtime/protocol.py
index 6d9bc914c5..87320ca013 100644
--- a/jarvis/realtime/protocol.py
+++ b/jarvis/realtime/protocol.py
@@ -102,6 +102,19 @@ class RealtimeSessionConfig:
# listening" (maintainer directive 2026-07-21). An explicit int still
# overrides the provider default for callers that need a fixed window.
silence_duration_ms: int | None = None
+ # How eagerly the provider's native VAD may declare the user finished.
+ # "low" = read a pause as a pause; "high" = the provider's own eager
+ # default; None = send nothing and inherit whatever the provider ships.
+ #
+ # This is deliberately NOT ``silence_duration_ms``. A fixed silence window
+ # taxes EVERY utterance with the same wait, which is why the 2026-07-21
+ # directive removed it — that directive stands. End-of-speech sensitivity
+ # changes only how a PAUSE is interpreted, so a finished short sentence
+ # still commits immediately while a hesitation inside a long order no
+ # longer ends the turn (live 2026-08-13 16:46/16:47: a spoken brief for a
+ # coding pane was closed twice mid-sentence and delivered truncated).
+ # Providers without the concept ignore it.
+ end_of_speech_sensitivity: str | None = "low"
tools: tuple[dict[str, Any], ...] = ()
# Bounded transcript of the call so far, oldest first, as
# ``{"role": "user" | "assistant", "text": ...}`` mappings. A fresh
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index 2564a14b0a..b4500471e3 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -248,10 +248,31 @@ _USER_VOICE_PEAK = 800
# Long enough to bridge the hesitations inside one sentence, short enough
# that a genuinely finished utterance dispatches without a perceptible wait.
_USER_SPEAKING_HOLD_S = 0.7
-# Ceiling on how long the microphone may hold back a delegated dispatch. A
-# stuck-open floor (a noisy room, a hot mic) must cost a bounded delay, never
-# a turn that is never executed at all.
-_USER_SPEAKING_DISPATCH_CAP_S = 4.0
+# Ceiling on how long the microphone may hold back a delegated dispatch.
+#
+# This is NOT a budget for how long the user is allowed to talk. A flat 4.0 s
+# ceiling measured from the provider's premature commit was exactly that, and
+# it cut a 40 s spoken order at 4 s (live 2026-08-13 16:46:26.939 — the log
+# line "user stopped speaking after a 4.00s hold" was the CEILING expiring,
+# not the user; at 16:47:25.527, six seconds after the same cut, the session
+# still logged "the user is still audibly speaking"). The truncated fragment
+# was then pressed into a coding pane with Enter.
+#
+# The ceiling exists for ONE failure: a floor stuck open on room noise or a
+# hot mic, which must cost a bounded delay rather than an order that never
+# runs. Noise produces voiced frames but no WORDS — so the window re-arms on
+# every growth of the input transcript and expires only on a microphone that
+# is loud yet wordless. A user who keeps talking keeps the floor; a stuck
+# floor still releases within this window.
+#
+# Comfortably clear of one provider transcription lag (Gemini's input
+# transcription ran ~2.6 s behind its own commit in the 2026-08-13 forensics)
+# plus a long thinking pause inside a sentence.
+_MIC_HOLD_STALE_TRANSCRIPT_S = 8.0
+# Absolute backstop for a pathological floor that somehow keeps producing
+# transcript growth. Long enough for any single spoken order, bounded so the
+# wait always terminates.
+_MIC_HOLD_ABSOLUTE_CAP_S = 45.0
# After the microphone finally goes quiet, the provider's transcript for the
# LAST words is still in flight — Gemini's input transcription ran ~2.6 s
# behind its own commit in the 2026-08-13 forensics. A dispatch that fires
@@ -2426,6 +2447,19 @@ class RealtimeVoiceSession:
if provider_config is not None
else ""
)
+ # The active mode may ask for its own voice — a friend should not sound
+ # like a butler. Unlike the classic pipeline, which picks a voice per
+ # utterance, a realtime provider pins the voice when the session opens:
+ # switching modes mid-call therefore changes the voice on the NEXT call,
+ # not this sentence. Documented rather than worked around, because
+ # tearing down a live conversation to change its timbre would cost the
+ # user their turn.
+ try:
+ from jarvis.brain.modes import active_voice
+
+ voice = active_voice() or voice
+ except Exception as exc: # noqa: BLE001 - a voice preference never costs a session
+ log.debug("Mode voice not applied to the realtime session: %s", exc)
return model, voice
@staticmethod
@@ -8143,9 +8177,12 @@ class RealtimeVoiceSession:
started = time.monotonic()
deadline = started + stability_s * _DELEGATE_INPUT_BOUNDARY_MAX_ROUNDS
# The microphone outranks every provider boundary while it still
- # carries the user's voice — but only for a bounded stretch, so a
- # noisy room delays an order instead of swallowing it.
- mic_deadline = started + _USER_SPEAKING_DISPATCH_CAP_S
+ # carries the user's voice. Its authority is bounded by a ROLLING
+ # window that every new word re-arms, never by a fixed budget from the
+ # provider's commit: the budget shape is what truncated a long order
+ # at its own ceiling (_MIC_HOLD_STALE_TRANSCRIPT_S).
+ mic_deadline = started + _MIC_HOLD_STALE_TRANSCRIPT_S
+ hard_deadline = started + _MIC_HOLD_ABSOLUTE_CAP_S
stable_since = started
settle_deadline = 0.0
last_transcript = self._last_user_text
@@ -8164,7 +8201,14 @@ class RealtimeVoiceSession:
except TimeoutError:
pass
now = time.monotonic()
- if self._user_is_speaking() and now < mic_deadline:
+ transcript_grew = self._last_user_text != last_transcript
+ if transcript_grew:
+ last_transcript = self._last_user_text
+ # Words are the one thing a stuck floor cannot produce, so a
+ # growing transcript renews the microphone's authority over
+ # the provider's boundary for another full window.
+ mic_deadline = now + _MIC_HOLD_STALE_TRANSCRIPT_S
+ if self._user_is_speaking() and now < mic_deadline and now < hard_deadline:
# Whatever the provider committed, the user is mid-sentence.
# Re-arm the stability window: the words already accepted are
# a fragment, and the later finals still to arrive grow
@@ -8179,20 +8223,32 @@ class RealtimeVoiceSession:
self.session_id,
)
stable_since = now
- last_transcript = self._last_user_text
else:
if mic_holding:
mic_holding = False
settle_deadline = now + _UTTERANCE_TAIL_SETTLE_S
- log.info(
- "realtime[%s] deterministic delegate: user stopped "
- "speaking after a %.2fs hold; settling for the tail "
- "transcript",
- self.session_id,
- now - started,
- )
- if self._last_user_text != last_transcript:
- last_transcript = self._last_user_text
+ if self._user_is_speaking():
+ # Still loud, but no new words for a full window: this
+ # is a stuck floor, not a talking user. Reporting it as
+ # "the user stopped" is what hid the truncation for a
+ # whole day of live calls.
+ log.info(
+ "realtime[%s] deterministic delegate: the "
+ "microphone stayed loud for %.1fs without a single "
+ "new word; treating the floor as stuck and "
+ "settling for the tail transcript",
+ self.session_id,
+ _MIC_HOLD_STALE_TRANSCRIPT_S,
+ )
+ else:
+ log.info(
+ "realtime[%s] deterministic delegate: user stopped "
+ "speaking after a %.2fs hold; settling for the tail "
+ "transcript",
+ self.session_id,
+ now - started,
+ )
+ if transcript_grew:
stable_since = now
elif (
turn_state.input_final and not mic_held_ever
@@ -8220,7 +8276,11 @@ class RealtimeVoiceSession:
len(str(self._last_user_text or "").split()),
)
return
- if now >= deadline:
+ if now >= deadline and not mic_holding:
+ # The provider-silence cap answers "the provider said nothing".
+ # It must never fire while the MICROPHONE is actively holding
+ # the floor — that is the case this function exists for, and
+ # letting it through here re-truncated a long order at 9 s.
log.warning(
"realtime[%s] deterministic delegate: input transcript "
"kept growing through the %.0fs wait cap; dispatching "
@@ -8229,6 +8289,16 @@ class RealtimeVoiceSession:
stability_s * _DELEGATE_INPUT_BOUNDARY_MAX_ROUNDS,
)
return
+ if now >= hard_deadline:
+ log.warning(
+ "realtime[%s] deterministic delegate: the microphone held "
+ "the floor for the full %.0fs ceiling; dispatching the %d "
+ "words the utterance has",
+ self.session_id,
+ _MIC_HOLD_ABSOLUTE_CAP_S,
+ len(str(self._last_user_text or "").split()),
+ )
+ return
async def _speak_public_fact_ack(
self,
diff --git a/tests/unit/realtime/test_gemini_live.py b/tests/unit/realtime/test_gemini_live.py
index 67e4dc56da..4a631b7a9f 100644
--- a/tests/unit/realtime/test_gemini_live.py
+++ b/tests/unit/realtime/test_gemini_live.py
@@ -330,17 +330,60 @@ async def test_every_selectable_model_uses_live_audio_and_transcriptions(
@pytest.mark.asyncio
-async def test_default_config_keeps_native_activity_detection(
+async def test_default_config_asks_gemini_to_sit_through_a_pause(
monkeypatch: pytest.MonkeyPatch,
) -> None:
+ """A default session is patient about pauses without a forced window.
+
+ Live 2026-08-13 16:46/16:47: Gemini's own default read a mid-sentence
+ pause as end-of-turn and a coding pane was briefed with a quarter of the
+ sentence. LOW fixes that; silence_duration_ms must STAY unset, because a
+ fixed window taxes every short utterance (directive 2026-07-21).
+ """
+ from google.genai import types
+
+ holder = _patch_genai_client(monkeypatch)
+ provider = GeminiLiveProvider(api_key="test-key")
+
+ session = await provider.open_session(RealtimeSessionConfig(voice="Puck"))
+ _selected, config = holder["client"].aio.live.connect_calls[0]
+ detection = config.realtime_input_config.automatic_activity_detection
+ assert detection.end_of_speech_sensitivity == types.EndSensitivity.END_SENSITIVITY_LOW
+ assert detection.silence_duration_ms is None
+ assert detection.disabled is False
+ await session.close()
+
+
+async def test_sensitivity_can_be_waived_back_to_the_provider_default(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ holder = _patch_genai_client(monkeypatch)
+ provider = GeminiLiveProvider(api_key="test-key")
+
+ session = await provider.open_session(
+ RealtimeSessionConfig(voice="Puck", end_of_speech_sensitivity=None)
+ )
+ _selected, config = holder["client"].aio.live.connect_calls[0]
+ assert config.realtime_input_config is None
+ await session.close()
+
+
+async def test_an_sdk_without_the_enum_still_opens_a_session(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """AP-21: a capability gap degrades the session, never blocks it."""
+ from google.genai import types
+
holder = _patch_genai_client(monkeypatch)
+ monkeypatch.delattr(types, "EndSensitivity", raising=False)
provider = GeminiLiveProvider(api_key="test-key")
session = await provider.open_session(RealtimeSessionConfig(voice="Puck"))
_selected, config = holder["client"].aio.live.connect_calls[0]
- # No forced silence window: Gemini's native automatic activity detection
- # decides the turn end (the Settings "Thinking pause" is pipeline-only).
assert config.realtime_input_config is None
+ assert config.speech_config is not None
await session.close()
diff --git a/tests/unit/realtime/test_utterance_continuation.py b/tests/unit/realtime/test_utterance_continuation.py
index ee4eab50de..5bb290c0a3 100644
--- a/tests/unit/realtime/test_utterance_continuation.py
+++ b/tests/unit/realtime/test_utterance_continuation.py
@@ -160,7 +160,8 @@ def _build_session(
def _fast_windows(monkeypatch: pytest.MonkeyPatch) -> None:
"""Scale the real-time windows down so the test stays sub-second."""
monkeypatch.setattr(session_module, "_USER_SPEAKING_HOLD_S", 0.12)
- monkeypatch.setattr(session_module, "_USER_SPEAKING_DISPATCH_CAP_S", 3.0)
+ monkeypatch.setattr(session_module, "_MIC_HOLD_STALE_TRANSCRIPT_S", 0.6)
+ monkeypatch.setattr(session_module, "_MIC_HOLD_ABSOLUTE_CAP_S", 10.0)
monkeypatch.setattr(session_module, "_UTTERANCE_TAIL_SETTLE_S", 0.4)
monkeypatch.setattr(session_module, "_DELEGATE_INPUT_BOUNDARY_WAIT_S", 0.2)
monkeypatch.setattr(session_module, "_DELEGATE_INPUT_BOUNDARY_POLL_S", 0.02)
@@ -247,3 +248,125 @@ async def test_mid_sentence_commit_keeps_one_turn_and_one_executor(
assert len(brain.calls) == 1, f"one order, one executor: {brain.calls}"
assert _FRAGMENT_ONE in brain.calls[0]
assert _FRAGMENT_TWO in brain.calls[0]
+
+
+_LONG_ORDER = (
+ "Can you please prompt terminal five",
+ "to do a deep dive into the spawning",
+ "it should work with every IDE we connected",
+ "and tell me what you find",
+ "before the end of the day",
+)
+
+
+class _LongOrderWire(_ChoppedUtteranceWire):
+ """Commits after the opening clause, then transcribes the rest slowly."""
+
+ session_id = "long-order-wire"
+
+ def __init__(self, *, gap_s: float) -> None:
+ super().__init__()
+ self._gap_s = gap_s
+ self.all_sent = asyncio.Event()
+
+ async def receive(self):
+ for index, fragment in enumerate(_LONG_ORDER):
+ yield RealtimeEvent(
+ type="input_transcript",
+ text=fragment,
+ is_final=True,
+ item_id=f"long-{index}",
+ )
+ if index == 0:
+ self.first_final.set()
+ await asyncio.sleep(self._gap_s)
+ self.all_sent.set()
+ await self.closed.wait()
+
+
+class _LongOrderProvider(_ChoppedUtteranceProvider):
+ name = "long-order"
+
+ def __init__(self, *, gap_s: float) -> None:
+ self.session = _LongOrderWire(gap_s=gap_s)
+
+
+async def test_a_long_order_survives_past_the_hold_ceiling(
+ _fast_windows: None,
+) -> None:
+ """The 2026-08-13 16:46:26.939 truncation: the CEILING expired, not the user.
+
+ A fixed budget measured from the provider's commit cut a long spoken order
+ at its own ceiling and briefed a coding pane with the opening clause. Here
+ the user talks for twice a full window after the commit; every new word
+ must renew the microphone's authority so the whole order survives.
+ """
+ provider = _LongOrderProvider(gap_s=0.25)
+ brain = _OrderBrain()
+ session = _build_session(provider, brain, session_id="long-order")
+
+ stop_speaking = asyncio.Event()
+
+ async def _hold_the_floor() -> None:
+ while not stop_speaking.is_set():
+ await session.handle_audio_frame(_voiced_frame())
+ await asyncio.sleep(0.02)
+
+ await session.handle_control({"type": "audio_start", "sample_rate": 16_000})
+ floor = asyncio.create_task(_hold_the_floor())
+ try:
+ await asyncio.wait_for(provider.session.first_final.wait(), timeout=1.0)
+ # Well past the point a fixed budget would have given up at.
+ await asyncio.sleep(session_module._MIC_HOLD_STALE_TRANSCRIPT_S * 2)
+ assert brain.calls == [], "dispatched while the user was still talking"
+
+ await asyncio.wait_for(provider.session.all_sent.wait(), timeout=5.0)
+ stop_speaking.set()
+ await floor
+ await asyncio.wait_for(brain.called.wait(), timeout=5.0)
+ finally:
+ stop_speaking.set()
+ if not floor.done():
+ floor.cancel()
+ await session.end(reason="test")
+
+ assert len(brain.calls) == 1, f"one order, one executor: {brain.calls}"
+ for fragment in _LONG_ORDER:
+ assert fragment in brain.calls[0], f"lost {fragment!r}: {brain.calls[0]!r}"
+
+
+async def test_a_loud_but_wordless_floor_still_releases_the_order(
+ _fast_windows: None,
+) -> None:
+ """The bounded half: a hot mic may DELAY an order, never swallow it.
+
+ Room noise keeps the voice floor above the threshold forever but produces
+ no words, so the rolling window must expire and the turn must still run.
+ """
+ provider = _ChoppedUtteranceProvider()
+ brain = _OrderBrain()
+ session = _build_session(provider, brain, session_id="stuck-floor")
+
+ stop = asyncio.Event()
+
+ async def _hot_mic() -> None:
+ while not stop.is_set():
+ await session.handle_audio_frame(_voiced_frame())
+ await asyncio.sleep(0.02)
+
+ await session.handle_control({"type": "audio_start", "sample_rate": 16_000})
+ mic = asyncio.create_task(_hot_mic())
+ try:
+ await asyncio.wait_for(provider.session.first_final.wait(), timeout=1.0)
+ # The tail is never released and the floor never goes quiet.
+ await asyncio.wait_for(brain.called.wait(), timeout=5.0)
+ finally:
+ stop.set()
+ if not mic.done():
+ mic.cancel()
+ await session.end(reason="test")
+
+ assert brain.calls, "a stuck floor swallowed the order entirely"
+ assert _FRAGMENT_ONE in brain.calls[0]