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): re-assert the one-speaker rule every turn, and tame the opening monologue

rubenluetke10-beepcb01e1e5d611
diff --git a/jarvis/core/events.py b/jarvis/core/events.py
index 25e283307f..a6da80e8be 100644
--- a/jarvis/core/events.py
+++ b/jarvis/core/events.py
@@ -1600,6 +1600,10 @@ class RealtimeSessionPostmortem(Event):
terminal_item_turns: int = 0
#: Back-to-back responses that spliced into one playback stream (<1.5 s).
response_splices: int = 0
+ #: Splices converted into clean local boundaries by the sequencing drain.
+ sequenced_boundaries: int = 0
+ #: Opening responses cut at the cap because no user question existed yet.
+ opening_responses_bounded: int = 0
#: Self-dialogue verdicts that forced a transport replacement (BUG-124).
self_dialogue_rebuilds: int = 0
#: Half-duplex mutes released by the emergency timer, not a turn boundary.
diff --git a/jarvis/plugins/realtime/codex_subscription.py b/jarvis/plugins/realtime/codex_subscription.py
index da5c3ba69e..7ac72e8959 100644
--- a/jarvis/plugins/realtime/codex_subscription.py
+++ b/jarvis/plugins/realtime/codex_subscription.py
@@ -34,6 +34,14 @@ _BROKER_OFFER_WAIT_S = 3.0
# in-reply pauses on ChatGPT-Live reach ~720 ms, so a shorter window would
# split a single answer at every breath.
_OUTPUT_QUIESCENCE_S = 1.2
+# Cap on the call's OPENING response while no user question exists yet.
+# ChatGPT-Live opens a response the moment it hears a voice - before the
+# user's first sentence is finished - and probe round 1 (2026-08-06) recorded
+# a 16 s greeting monologue riding over the user's first question. A greeting
+# that long is never a greeting. Bounded per frame (no timer task); a user
+# final arriving mid-greeting ADOPTS the response instead (see the local
+# input branch), so a genuinely fast answer is never cut.
+_OPENING_RESPONSE_MAX_S = 6.0
# How long after the last audible provider frame a further frame still counts
# as the REST of the same answer rather than a new response.
#
@@ -784,6 +792,22 @@ class _CodexSubscriptionRealtimeSession:
response_open = False
response_allowed = False
response_opened_at = 0.0
+ # Which authorization opened the current response: "" (none yet),
+ # "fresh", "greeting", "permit", "continuation" or "failopen". Feeds
+ # the opening bound below and every grant/refusal log line.
+ response_grant = ""
+ # The call's first user FINAL anchors the opening rules: a response
+ # the server opens before any final exists is a greeting, not an
+ # answer - whatever grounding it can claim (probe round 1: the
+ # opening monologue consumed the user's first utterance and the real
+ # answer was then refused as ungrounded).
+ first_user_final_seen = False
+ call_response_index = 0
+ # Once an opening response was cut at the cap, its streamed remainder
+ # must not earn a fresh greeting grant frame by frame - the utterance
+ # keeps its entitlement, but nothing speaks on it until a FINAL
+ # exists (or the user audibly starts over).
+ opening_bound_cut = False
# The grounded utterance whose answer may still be streaming, and
# whether the far end has since proven that answer ended. Together
# with the last audible frame they decide whether a frame arriving
@@ -949,6 +973,7 @@ class _CodexSubscriptionRealtimeSession:
nonlocal interrupt_grace_until, refusal_run, refusal_run_started_at
nonlocal refusal_storm_noted, self_dialogue_detected
nonlocal sequence_boundary_pending
+ nonlocal response_grant, call_response_index
if response_open:
if response_allowed or not _rejected_response_is_stale():
return response_allowed
@@ -988,20 +1013,40 @@ class _CodexSubscriptionRealtimeSession:
)
response_rejected_at = 0.0
active_response_generation = 0
+ call_response_index += 1
+ response_grant = ""
if not self._local_grounding_active():
response_allowed = True
- elif local_input_generation > consumed_input_generation:
+ response_grant = "failopen"
+ elif local_input_generation > consumed_input_generation and (
+ first_user_final_seen or not opening_bound_cut
+ ):
+ # Same consumption machinery either way; the grant label is
+ # what changes the OPENING response's treatment. The server
+ # opens a response the moment it hears a VOICE - before the
+ # user's first sentence exists (probe round 1, 2026-08-06: a
+ # 16 s greeting monologue opened 2 s into the user's question
+ # and starved the real answer). A pre-first-final response is
+ # therefore a GREETING: bounded at the media handler, adopted
+ # as the answer if the final lands while it still speaks, and
+ # its bound-cut closes WITHOUT spending - the continuation
+ # window stays open for the answer the question still earns.
active_response_generation = local_input_generation
entitled_generation = local_input_generation
entitlement_spent = False
response_allowed = True
+ response_grant = (
+ "fresh" if first_user_final_seen else "greeting"
+ )
elif _trusted_permit_available():
self._trusted_output_permits -= 1
self._diag["trusted_permit_responses"] += 1
response_allowed = True
+ response_grant = "permit"
elif _entitled_turn_continues():
active_response_generation = entitled_generation
response_allowed = True
+ response_grant = "continuation"
log.debug(
"Codex subscription realtime treats %s as the continuation "
"of the answer already grounded in utterance %d",
@@ -1465,6 +1510,7 @@ class _CodexSubscriptionRealtimeSession:
if payload.kind == _SPEECH_STARTED:
local_input_generation += 1
user_utterance_open = True
+ opening_bound_cut = False
local_transcript_failed = False
user_final_emitted = False
missing_boundary_emitted = False
@@ -1536,6 +1582,24 @@ class _CodexSubscriptionRealtimeSession:
user_utterance_open = False
local_transcript_failed = False
user_final_emitted = True
+ if not first_user_final_seen:
+ first_user_final_seen = True
+ if (
+ response_open
+ and response_allowed
+ and response_grant == "greeting"
+ ):
+ # The question landed while the opening
+ # response still speaks: adopt it as the
+ # answer and lift the greeting bound
+ # (the entitlement machinery is already
+ # armed by the grant).
+ response_grant = "fresh"
+ log.info(
+ "Codex subscription adopted the "
+ "opening response as the answer to "
+ "the user's first utterance"
+ )
yield _ProviderEvent(
type="input_transcript",
text=payload.text,
@@ -1596,6 +1660,59 @@ class _CodexSubscriptionRealtimeSession:
assistant_audio.extend(pcm[:remaining])
if audible and assistant_audio_active and not first_audible_at:
first_audible_at = asyncio.get_running_loop().time()
+ if (
+ response_allowed
+ and first_audible_at
+ and not first_user_final_seen
+ and (
+ response_grant == "greeting"
+ or (
+ response_grant == "failopen"
+ and call_response_index == 1
+ )
+ )
+ ):
+ opening_age = (
+ asyncio.get_running_loop().time() - first_audible_at
+ )
+ if opening_age > _OPENING_RESPONSE_MAX_S:
+ # No user question exists yet and the opener is
+ # still going: this is the 13.9 s / 16 s demo
+ # monologue class, cut at the cap. A greeting
+ # close keeps the user's entitlement (spent=False)
+ # so their in-flight question still earns its
+ # answer; a recognizer-less failopen host has no
+ # entitlement to keep.
+ self._diag["opening_responses_bounded"] += 1
+ opening_bound_cut = True
+ log.warning(
+ "Codex subscription bounded an opening "
+ "response at %.1fs - no user question exists "
+ "yet (grant=%s)",
+ opening_age,
+ response_grant,
+ )
+ await self._interrupt_active_codex_turn()
+ # The far end streams the remainder regardless.
+ # Deliberately NOT the output-drop barrier: its
+ # handler closes with spent=True, which would
+ # burn the continuation window the user's
+ # in-flight question needs for its real answer.
+ # The opening_bound_cut gate refuses the
+ # remainder frame by frame instead, and the
+ # grace keeps their echo captions out of the
+ # self-dialogue counters (the BUG-124 lesson).
+ interrupt_grace_until = (
+ asyncio.get_running_loop().time()
+ + _POST_INTERRUPT_GRACE_S
+ )
+ _cancel_completion()
+ completion_emitted = True
+ yield _ProviderEvent(type="turn_complete")
+ _reset_assistant_capture()
+ _close_response(spent=response_grant != "greeting")
+ response_grant = ""
+ continue
if (
audible
and assistant_audio_active
@@ -2182,6 +2299,7 @@ class _CodexSubscriptionRealtimeSession:
language: str | None = None,
tools: tuple[dict[str, Any], ...] | None = None,
turn_directive: str | None = None,
+ standing_directive: str | None = None,
) -> None:
# Tools cannot be declared here, and that is a transport fact rather
# than a policy choice: the app-server realtime RPC surface is only
@@ -2214,7 +2332,10 @@ class _CodexSubscriptionRealtimeSession:
normalized_pin = _normalized_locale(language)
pin_text = _language_pin_text(normalized_pin)
await self._deliver_context(
- instructions, turn_directive=turn_directive, language_pin=pin_text
+ instructions,
+ turn_directive=turn_directive,
+ standing_directive=standing_directive,
+ language_pin=pin_text,
)
if pin_text:
self._language = normalized_pin
@@ -2248,6 +2369,7 @@ class _CodexSubscriptionRealtimeSession:
instructions: str | None,
*,
turn_directive: str | None = None,
+ standing_directive: str | None = None,
language_pin: str = "",
) -> None:
"""Give the model Jarvis's own persona, capabilities and context.
@@ -2271,7 +2393,9 @@ class _CodexSubscriptionRealtimeSession:
"""
text = str(instructions or "").strip()
directive = str(turn_directive or "").strip()
+ standing = str(standing_directive or "").strip()
directive_lines = set(directive.splitlines()) if directive else set()
+ standing_lines = set(standing.splitlines()) if standing else set()
sections: list[str] = []
if text and text != self._delivered_context:
if not self._delivered_context:
@@ -2284,6 +2408,7 @@ class _CodexSubscriptionRealtimeSession:
if line.strip()
and line not in previous_lines
and line not in directive_lines
+ and line not in standing_lines
]
if changed:
sections.append(
@@ -2305,6 +2430,16 @@ class _CodexSubscriptionRealtimeSession:
"them silently, never acknowledge them aloud:\n"
+ directive
)
+ if standing:
+ # Re-asserted EVERY delivery, unchanged or not: three live calls
+ # in a row (2026-08-05) and probe round 1 (2026-08-06, a 16 s
+ # opening monologue over the user's first question) proved a
+ # rule stated once at open does not hold on this channel, while
+ # the per-turn language pin demonstrably does — repetition is
+ # what makes a rule real here. The constant carries BOTH halves
+ # (silence rule + its speak-request exception) so they can never
+ # ship apart again (the b181d92f regression).
+ sections.append(standing)
if language_pin:
# Reasserted every turn even when unchanged: the server can
# freeze an automatic response before the larger refresh above
diff --git a/jarvis/plugins/realtime/gemini_live.py b/jarvis/plugins/realtime/gemini_live.py
index 6f565e7d5e..71c1fd4b50 100644
--- a/jarvis/plugins/realtime/gemini_live.py
+++ b/jarvis/plugins/realtime/gemini_live.py
@@ -337,13 +337,14 @@ class _GeminiLiveSession:
language: str | None = None,
tools: tuple[dict[str, Any], ...] | None = None,
turn_directive: str | None = None,
+ standing_directive: str | None = None,
) -> None:
# Gemini fixes system instructions at connect time. The orchestrator
# reconnects on a substantive language change in a later session.
- # Accepting turn_directive keeps the per-turn update off the
- # session's TypeError-retry path; the directive is already embedded
- # in the (fixed) instructions.
- del instructions, language, tools, turn_directive
+ # Accepting the directive keywords keeps the per-turn update off the
+ # session's TypeError-retry path; both are already embedded in the
+ # (fixed) instructions.
+ del instructions, language, tools, turn_directive, standing_directive
async def request_response(self, *, required_tool: str | None = None) -> None:
# Gemini Live creates a response automatically at the VAD turn boundary.
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index 52dc275b43..1b9650d570 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -597,12 +597,14 @@ class _OpenAIRealtimeSession:
language: str | None = None,
tools: tuple[dict[str, Any], ...] | None = None,
turn_directive: str | None = None,
+ standing_directive: str | None = None,
) -> None:
del language # Input transcription stays provider-inferred and multilingual.
# This transport REPLACES its instructions wholesale, and the turn
- # directive is already embedded in them. Accepting the keyword keeps
- # the per-turn update off the session's TypeError-retry path.
- del turn_directive
+ # and standing directives are already embedded in them. Accepting the
+ # keywords keeps the per-turn update off the session's TypeError-retry
+ # path.
+ del turn_directive, standing_directive
update: dict[str, Any] = {"type": "realtime"}
if instructions is not None:
update["instructions"] = instructions
diff --git a/jarvis/realtime/protocol.py b/jarvis/realtime/protocol.py
index 5cc0b7d117..9793bd492c 100644
--- a/jarvis/realtime/protocol.py
+++ b/jarvis/realtime/protocol.py
@@ -169,6 +169,15 @@ class RealtimeSession(Protocol):
# same text is already embedded in ``instructions``. The session
# retries without it on TypeError for third-party adapters.
turn_directive: str | None = None,
+ # Session-constant discipline the adapter must RE-ASSERT on its
+ # working channel every turn (the one-speaker rule with its
+ # speak-request exception). Live finding 2026-08-05/06: a rule
+ # stated once at open does not hold on ChatGPT-Live — the language
+ # pin survives because it is repeated every turn, and this directive
+ # needs the same treatment. Wholesale-replace adapters ``del`` it
+ # (their full instructions already re-carry it); the session retries
+ # without it on TypeError for third-party adapters.
+ standing_directive: str | None = None,
) -> None: ...
async def request_response(self, *, required_tool: str | None = None) -> None: ...
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index c6fefc35a1..6e13959ddf 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -2793,6 +2793,13 @@ class RealtimeVoiceSession:
# leaving contradictory "this current turn" texts
# standing in the thread.
"turn_directive": turn_tool_directive,
+ # Re-asserted every turn on the adapter's working
+ # channel: the one-speaker rule delivered once at
+ # open demonstrably fades on ChatGPT-Live while
+ # the per-turn language pin holds — this is the
+ # exact constant (BOTH halves: silence rule and
+ # its speak-request exception, b181d92f).
+ "standing_directive": _ONE_SPEAKER_DIRECTIVE,
}
if tools_changed:
update_kwargs["tools"] = self._declared_tools()
@@ -2817,16 +2824,22 @@ class RealtimeVoiceSession:
# older update-session protocols: retire the
# NEWEST field first so an adapter that already
# understands tools keeps receiving them.
- update_kwargs.pop("turn_directive", None)
+ update_kwargs.pop("standing_directive", None)
try:
await self._session.update_session(
**update_kwargs
)
- except TypeError: # predates the tools field too
- update_kwargs.pop("tools", None)
- await self._session.update_session(
- **update_kwargs
- )
+ except TypeError:
+ update_kwargs.pop("turn_directive", None)
+ try:
+ await self._session.update_session(
+ **update_kwargs
+ )
+ except TypeError: # predates tools too
+ update_kwargs.pop("tools", None)
+ await self._session.update_session(
+ **update_kwargs
+ )
if self._tool_bridge is not None and event.is_final and transcript:
await self._tool_bridge.handle_user_transcript(
self._last_user_text
@@ -6878,6 +6891,8 @@ class RealtimeVoiceSession:
quiescence_boundary_turns=diag.get("quiescence_boundary_turns", 0),
terminal_item_turns=diag.get("terminal_item_turns", 0),
response_splices=diag.get("response_splices", 0),
+ sequenced_boundaries=diag.get("sequenced_boundaries", 0),
+ opening_responses_bounded=diag.get("opening_responses_bounded", 0),
self_dialogue_rebuilds=diag.get("self_dialogue_rebuilds", 0),
mute_emergency_releases=self._mute_emergency_releases,
sender_pacing_resyncs=diag.get("sender_pacing_resyncs", 0),
diff --git a/tests/unit/realtime/test_codex_subscription.py b/tests/unit/realtime/test_codex_subscription.py
index 0f03830329..48a4b268c7 100644
--- a/tests/unit/realtime/test_codex_subscription.py
+++ b/tests/unit/realtime/test_codex_subscription.py
@@ -3049,3 +3049,167 @@ async def test_a_barge_splice_is_sequenced_behind_a_local_boundary() -> None:
)
assert session.diagnostics().get("sequenced_boundaries", 0) == 1
await session.close()
+
+
+async def test_the_standing_directive_is_reasserted_on_every_delivery() -> None:
+ """A rule stated once at open does not hold on this channel (three live
+ calls, 2026-08-05; probe round 1, 2026-08-06), while the per-turn
+ language pin demonstrably does - repetition is what makes a rule real
+ here. The standing directive must therefore ride EVERY delivery, exactly
+ once per payload, even when nothing else changed."""
+ client = _Client()
+ session = await _provider(client).open_session(RealtimeSessionConfig())
+ baseline = len(client.text_appends)
+
+ rule = "SPEAK AS ONE VOICE ONLY."
+ await session.update_session(
+ instructions="PERSONA BLOCK", standing_directive=rule
+ )
+ await session.update_session(
+ instructions="PERSONA BLOCK", standing_directive=rule
+ )
+
+ payloads = [text for _, text, _ in client.text_appends[baseline:]]
+ assert len(payloads) == 2, "an unchanged turn still delivers the rule"
+ for payload in payloads:
+ assert payload.count(rule) == 1, payload
+ await session.close()
+
+
+async def test_a_rambling_opening_is_cut_and_the_real_answer_still_flows(
+ monkeypatch,
+) -> None:
+ """Probe round 1: a 16 s greeting monologue rode over the user's first
+ question. The opening response is now cut at the cap, its remainder is
+ refused frame by frame, and the answer the question earns still flows
+ through the continuation window afterwards."""
+ monkeypatch.setattr(codex_subscription_mod, "_OPENING_RESPONSE_MAX_S", 0.2)
+ loud = (1000).to_bytes(2, "little", signed=True) * 480
+ transcriber = _ScheduledInputTranscriber(
+ [
+ (0.02, InputTranscriptEvent(kind="speech_started")),
+ (
+ 0.55,
+ InputTranscriptEvent(
+ kind="transcript", text="What is up?", is_final=True
+ ),
+ ),
+ ]
+ )
+ endpoint = _FakeAudioEndpoint(
+ output_schedule=[
+ (0.05, loud),
+ (0.10, loud),
+ (0.10, loud),
+ (0.15, loud), # ~0.40 s in: past the 0.2 s cap -> cut here
+ (0.05, loud), # the remainder the far end streams anyway
+ (0.05, loud),
+ ]
+ )
+ client = _Client()
+ client.subscription = _ScheduledSubscription(
+ [
+ (
+ 0.8,
+ _Notification(
+ "thread/realtime/transcript/delta",
+ {
+ "threadId": "thread-1",
+ "role": "assistant",
+ "delta": "The real answer.",
+ },
+ ),
+ ),
+ ]
+ )
+ session = await _provider(
+ client,
+ endpoint=endpoint,
+ input_transcriber_factory=lambda: transcriber,
+ ).open_session(RealtimeSessionConfig())
+
+ events = []
+ async with asyncio.timeout(5.0):
+ async for event in session.receive():
+ events.append(event)
+ if event.type == "output_transcript_delta" and "real answer" in (
+ event.text or ""
+ ):
+ break
+
+ assert session.diagnostics().get("opening_responses_bounded", 0) == 1
+ boundary_positions = [
+ i for i, e in enumerate(events) if e.type == "turn_complete"
+ ]
+ assert boundary_positions, "the cut must close the opening turn"
+ answer_position = next(
+ i
+ for i, e in enumerate(events)
+ if e.type == "output_transcript_delta"
+ and "real answer" in (e.text or "")
+ )
+ assert boundary_positions[0] < answer_position
+ await session.close()
+
+
+async def test_a_final_landing_mid_opening_adopts_the_response(
+ monkeypatch,
+) -> None:
+ """A genuinely fast answer must never be cut: when the user's final lands
+ while the opening response still speaks, the response is ADOPTED as the
+ answer and the bound lifts."""
+ monkeypatch.setattr(codex_subscription_mod, "_OPENING_RESPONSE_MAX_S", 0.3)
+ loud = (1000).to_bytes(2, "little", signed=True) * 480
+ transcriber = _ScheduledInputTranscriber(
+ [
+ (0.02, InputTranscriptEvent(kind="speech_started")),
+ (
+ 0.10,
+ InputTranscriptEvent(
+ kind="transcript", text="Quick one?", is_final=True
+ ),
+ ),
+ ]
+ )
+ endpoint = _FakeAudioEndpoint(
+ output_schedule=[
+ (0.05, loud),
+ (0.15, loud),
+ (0.20, loud), # ~0.40 s in: past the cap, but adopted by then
+ (0.10, loud),
+ ]
+ )
+ client = _Client()
+ # Keep the notification stream OPEN past the collection window: an
+ # exhausted subscription ends the stream and takes the receive loop
+ # with it.
+ client.subscription = _ScheduledSubscription(
+ [
+ (
+ 5.0,
+ _Notification(
+ "thread/realtime/transcript/delta",
+ {"threadId": "thread-1", "role": "assistant", "delta": "."},
+ ),
+ ),
+ ]
+ )
+ session = await _provider(
+ client,
+ endpoint=endpoint,
+ input_transcriber_factory=lambda: transcriber,
+ ).open_session(RealtimeSessionConfig())
+
+ events = await _collect_until(
+ session, stop_after=1, kind="never", timeout_s=1.2
+ )
+
+ assert session.diagnostics().get("opening_responses_bounded", 0) == 0, (
+ "an adopted opening response is the answer and must not be cut"
+ )
+ audio_events = [e for e in events if e.type == "audio_delta"]
+ assert len(audio_events) == 4, "all audio flowed, none was refused"
+ await session.close()