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): preserve subscription voice engine

rubenluetke10-beep22da1038c966
diff --git a/jarvis/core/config.py b/jarvis/core/config.py
index 701d266665..cbccf42b51 100644
--- a/jarvis/core/config.py
+++ b/jarvis/core/config.py
@@ -2468,8 +2468,8 @@ class VoiceConfig(BaseModel):
# normal brain. ``codex-subscription-voice`` keeps the proven local
# microphone/STT/TTS/playback pipeline and replaces only conversational
# text generation with the stable Codex App Server subscription transport.
- # The legacy realtime provider id is migrated at read time by
- # ``jarvis.voice.subscription_profile``.
+ # This must be selected explicitly: choosing the similarly named Realtime
+ # provider never implies this classic-pipeline profile.
profile: str = ""
# Realtime tool exposure. "delegate" (default) gives the live model one
# compact jarvis_action function and hands action turns to the key-aware
@@ -3947,6 +3947,29 @@ def _migrate_worker_env_vars() -> None:
#: process. The on-disk marker is the durable guard; this only keeps a hot
#: ``load_config`` loop from re-reading the file for a migration that is done.
_DICTATION_HOTKEY_HEALED: set[Path] = set()
+_LEGACY_CODEX_REALTIME_HEALED: set[Path] = set()
+
+
+def _heal_legacy_codex_realtime_once(path: Path) -> None:
+ """Retire the Pipeline profile accidentally persisted by old Realtime UI."""
+ if path in _LEGACY_CODEX_REALTIME_HEALED:
+ return
+ _LEGACY_CODEX_REALTIME_HEALED.add(path)
+ try:
+ from jarvis.core.config_writer import migrate_legacy_codex_realtime_selection
+
+ migrated = migrate_legacy_codex_realtime_selection(path=path)
+ except Exception: # noqa: BLE001 - a boot migration must not block startup
+ logging.getLogger(__name__).warning(
+ "Could not repair the legacy Codex Realtime voice selection.",
+ exc_info=True,
+ )
+ return
+ if migrated:
+ logging.getLogger(__name__).warning(
+ "Repaired legacy Codex Realtime configuration: removed the "
+ "Pipeline-only voice profile and restored Realtime mode."
+ )
def _heal_dictation_hotkeys_once(path: Path) -> None:
@@ -3984,6 +4007,10 @@ def load_config(
"""
if config_file is None:
config_file = resolve_config_path()
+ # An earlier Codex-subscription implementation silently rewrote the
+ # Realtime selection as a Pipeline profile. Heal the exact persisted
+ # triple before the first parse so the UI and runtime see one state.
+ _heal_legacy_codex_realtime_once(config_file)
# One-time dictation-shortcut backfill BEFORE the file is read, so the
# very first boot after the update already sees the healed values
# (BUG-010 config drift; see config_writer for why a marker and not an
diff --git a/jarvis/core/config_writer.py b/jarvis/core/config_writer.py
index bcd6601e75..9d71d3f679 100644
--- a/jarvis/core/config_writer.py
+++ b/jarvis/core/config_writer.py
@@ -1248,6 +1248,107 @@ def set_voice_profile(
)
+def set_realtime_voice_selection(
+ provider: str,
+ *,
+ profile: str,
+ mode: str,
+ path: Path = DEFAULT_CONFIG_FILE,
+) -> None:
+ """Persist one Realtime provider and its compatible voice state atomically.
+
+ This is the migration-safe writer for a Realtime provider switch that also
+ has to retire a classic voice profile. Keeping all three values in one TOML
+ replacement prevents a crash or write failure from leaving the selected
+ provider paired with a stale Pipeline-only profile.
+ """
+ path = _ensure_writable_config_path(path)
+ normalized_provider = str(provider or "").strip()
+ normalized_profile = str(profile or "").strip()
+ normalized_mode = str(mode or "").strip().lower()
+ if not normalized_provider:
+ raise ValueError("A Realtime provider id is required.")
+ if normalized_mode not in {"pipeline", "realtime"}:
+ raise ValueError("Voice mode must be 'pipeline' or 'realtime'.")
+
+ with _WRITE_LOCK:
+ raw = path.read_text(encoding="utf-8")
+ had_bom = raw.startswith(_BOM)
+ if had_bom:
+ raw = raw[len(_BOM) :]
+ doc: TOMLDocument = tomlkit.parse(raw)
+
+ brain = doc.get("brain")
+ if brain is None:
+ brain = tomlkit.table()
+ doc["brain"] = brain
+ realtime = brain.get("realtime")
+ if realtime is None:
+ realtime = tomlkit.table()
+ brain["realtime"] = realtime
+ realtime["provider"] = normalized_provider
+
+ voice = doc.get("voice")
+ if voice is None:
+ voice = tomlkit.table()
+ doc["voice"] = voice
+ voice["profile"] = normalized_profile
+ voice["mode"] = normalized_mode
+
+ out = tomlkit.dumps(doc)
+ if had_bom:
+ out = _BOM + out
+ _atomic_write(path, out)
+
+
+def migrate_legacy_codex_realtime_selection(
+ *, path: Path = DEFAULT_CONFIG_FILE
+) -> bool:
+ """Repair the exact Realtime-to-Pipeline state written by the old switch.
+
+ Older builds represented the Codex Realtime card as the classic
+ ``codex-subscription-voice`` profile and persisted Pipeline mode. The card
+ then appeared active while the Realtime mode control refused to switch,
+ leaving no in-app recovery path. Only that exact three-key legacy state is
+ changed; explicit Pipeline configurations using any other provider remain
+ untouched.
+ """
+ if path == DEFAULT_CONFIG_FILE:
+ from jarvis.core.config import resolve_config_path
+
+ path = resolve_config_path()
+ if not path.exists():
+ return False
+
+ with _WRITE_LOCK:
+ raw = path.read_text(encoding="utf-8")
+ had_bom = raw.startswith(_BOM)
+ if had_bom:
+ raw = raw[len(_BOM) :]
+ doc: TOMLDocument = tomlkit.parse(raw)
+ brain = doc.get("brain")
+ realtime = brain.get("realtime") if brain is not None else None
+ voice = doc.get("voice")
+ if (
+ realtime is None
+ or voice is None
+ or str(realtime.get("provider") or "").strip()
+ != "codex-subscription-realtime"
+ or str(voice.get("profile") or "").strip()
+ != "codex-subscription-voice"
+ or str(voice.get("mode") or "").strip().lower() != "pipeline"
+ ):
+ return False
+
+ voice["profile"] = ""
+ voice["mode"] = "realtime"
+ out = tomlkit.dumps(doc)
+ if had_bom:
+ out = _BOM + out
+ _atomic_write(path, out)
+ return True
+
+
def set_realtime_provider(provider: str, *, path: Path = DEFAULT_CONFIG_FILE) -> None:
"""Persist the active realtime-voice provider to ``[brain.realtime] provider``.
diff --git a/jarvis/ui/web/provider_routes.py b/jarvis/ui/web/provider_routes.py
index 9997abf1da..1d8d5d837e 100644
--- a/jarvis/ui/web/provider_routes.py
+++ b/jarvis/ui/web/provider_routes.py
@@ -731,13 +731,6 @@ def _active_realtime(request: Request) -> str | None:
"""
try:
cfg = _resolve_cfg(request)
- from jarvis.voice.subscription_profile import ( # noqa: PLC0415
- LEGACY_CODEX_REALTIME_PROVIDER,
- subscription_voice_selected,
- )
-
- if cfg is not None and subscription_voice_selected(cfg):
- return LEGACY_CODEX_REALTIME_PROVIDER
realtime_cfg = getattr(getattr(cfg, "brain", None), "realtime", None)
provider = (getattr(realtime_cfg, "provider", None) or "").strip()
if provider:
@@ -3353,21 +3346,6 @@ async def get_realtime_options(provider_id: str, request: Request) -> RealtimeOp
dicts directly rather than going through ``catalog_spec``.
"""
_require_realtime_provider(provider_id)
- if provider_id == "codex-subscription-realtime":
- # The visible id is a compatibility alias. This profile no longer uses
- # ChatGPT-Live's server-selected model or voices: Codex streams text and
- # the configured Jarvis TTS owns synthesis. Keep the existing generic
- # control honest without coupling this backend fix to a frontend build.
- return RealtimeOptionsResponse(
- provider=provider_id,
- models=[RealtimeOptionInfo(id="auto", label="Codex App Server (subscription text)")],
- voices=[
- RealtimeOptionInfo(id="configured-tts", label="Configured Jarvis voice output")
- ],
- current_model="auto",
- current_voice="configured-tts",
- preview_available=True,
- )
from jarvis.brain.model_catalog import REALTIME_MODELS, REALTIME_VOICES
cfg = _resolve_cfg(request)
@@ -3617,54 +3595,39 @@ async def _openai_realtime_voice_sample(
async def _codex_subscription_voice_sample(
api_key: str, *, model: str, voice: str, text: str, language: str
) -> tuple[bytes, int]:
- """Exercise the stable subscription-text -> configured-TTS voice path."""
- del api_key, model, voice
- from jarvis.core.protocols import BrainMessage, BrainRequest # noqa: PLC0415
- from jarvis.plugins.brain.codex import CodexBrain # noqa: PLC0415
- from jarvis.plugins.tts import build_tts_from_config # noqa: PLC0415
- from jarvis.voice.subscription_profile import ( # noqa: PLC0415
- subscription_language_directive,
+ """Sample the subscription voice through its ChatGPT-Live transport."""
+ del api_key, model
+ from jarvis.plugins.realtime.codex_subscription import ( # noqa: PLC0415
+ CodexSubscriptionRealtimeProvider,
)
+ from jarvis.realtime.protocol import RealtimeSessionConfig # noqa: PLC0415
- brain = CodexBrain(prefer_subscription=True)
- request = BrainRequest(
- messages=(
- BrainMessage(
- "user",
- f"Reply with one short, natural spoken sentence matching this message: {text}",
- ),
- ),
- system=subscription_language_directive(language),
- stream=True,
+ provider = CodexSubscriptionRealtimeProvider(
+ binary_path=_codex_binary_path(),
+ # A preview sends no microphone audio and needs no input recognizer.
+ input_transcriber_factory=lambda: None,
+ )
+ session = await provider.open_session(
+ RealtimeSessionConfig(
+ instructions="Speak only the trusted sample text supplied by the client.",
+ language=language,
+ voice=voice,
+ )
)
- answer_parts: list[str] = []
- async for delta in brain.complete(request):
- if delta.content:
- answer_parts.append(delta.content)
- answer = "".join(answer_parts).strip()
- if not answer:
- raise RuntimeError("The subscription text transport returned no sample.")
-
- active_config = cfg_mod.load_config()
- tts = build_tts_from_config(active_config.tts)
pcm = bytearray()
- sample_rate = 0
- language_code = {"de": "de-DE", "en": "en-US", "es": "es-ES"}.get(language, language)
+ sample_rate = int(getattr(provider, "output_sample_rate", 24_000) or 24_000)
try:
- async for chunk in tts.synthesize(answer, language_code=language_code):
- rate = int(chunk.sample_rate or 0)
- if sample_rate and rate != sample_rate:
- raise RuntimeError("The configured voice changed sample rate mid-sample.")
- sample_rate = rate
- pcm += bytes(chunk.pcm)
+ await session.send_speech(text)
+ async for event in session.receive():
+ if event.type == "audio_delta" and event.audio is not None:
+ pcm += bytes(event.audio.pcm)
+ sample_rate = int(event.audio.sample_rate or sample_rate)
+ elif event.type == "error":
+ raise RuntimeError(str(event.error or "subscription preview failed"))
+ elif event.type == "turn_complete":
+ break
finally:
- close = getattr(tts, "aclose", None)
- if callable(close):
- closed = close()
- if inspect.isawaitable(closed):
- await closed
- if not pcm or sample_rate <= 0:
- raise RuntimeError("The configured voice produced no audible sample.")
+ await session.close()
return bytes(pcm), sample_rate
@@ -3710,14 +3673,11 @@ async def realtime_voice_preview(provider_id: str, body: RealtimeVoicePreviewBod
voice = body.voice.strip()
if not voice:
raise HTTPException(status_code=400, detail="A voice id is required.")
- allowed_voices = {option.id for option in REALTIME_VOICES.get(provider_id, ())}
- if provider_id == "codex-subscription-realtime":
- allowed_voices.add("configured-tts")
_validate_realtime_option(
provider_id=provider_id,
field="voice",
value=voice,
- allowed=allowed_voices,
+ allowed={option.id for option in REALTIME_VOICES.get(provider_id, ())},
)
model = body.model.strip()
_validate_realtime_option(
@@ -4692,79 +4652,13 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
"Connect or configure this provider first."
),
)
- if spec.id == "codex-subscription-realtime":
- from jarvis.codex_app_server import (
- get_shared_codex_app_server,
- set_codex_subscription_activation_block,
- )
- from jarvis.voice.subscription_profile import (
- CODEX_SUBSCRIPTION_VOICE_PROFILE,
- )
-
- # A previous stable-text session or the retired duplex adapter may be
- # warm on another event loop. Provider selection is an explicit
- # handoff: release that old owner before the activation probe acquires
- # the single subscription-profile lease.
- if not codex_transport_released:
- await _release_codex_transports_for_voice_switch()
- client = None
- try:
- client = get_shared_codex_app_server(_codex_binary_path(request), purpose="text")
- await asyncio.wait_for(client.require_chatgpt_login(), timeout=45.0)
- except TimeoutError as exc:
- raise HTTPException(
- status_code=409,
- detail="The ChatGPT subscription text check timed out. Try again.",
- ) from exc
- except Exception as exc: # noqa: BLE001 - safe activation refusal
- raise HTTPException(status_code=409, detail=str(exc)) from exc
- finally:
- close = getattr(client, "close", None)
- if callable(close):
- try:
- await asyncio.shield(close())
- except Exception as cleanup_exc: # noqa: BLE001
- log.warning(
- "Codex subscription activation transport cleanup failed",
- exc_info=True,
- )
- raise HTTPException(
- status_code=409,
- detail=(
- "The ChatGPT subscription check could not release its "
- "voice transport. Try activation again."
- ),
- ) from cleanup_exc
- await asyncio.to_thread(set_codex_subscription_activation_block, None)
-
- if body.persist:
- try:
- from jarvis.core.config_writer import set_voice_profile
-
- set_voice_profile(CODEX_SUBSCRIPTION_VOICE_PROFILE, mode="pipeline")
- except Exception as exc: # noqa: BLE001
- raise HTTPException(status_code=500, detail=f"TOML write failed: {exc}") from exc
-
- cfg = _resolve_cfg(request)
- voice_cfg = getattr(cfg, "voice", None) if cfg is not None else None
- if voice_cfg is not None:
- voice_cfg.profile = CODEX_SUBSCRIPTION_VOICE_PROFILE
- voice_cfg.mode = "pipeline"
- await _emit(request, SecretConfigured(key="voice.profile", action="set"))
-
- from jarvis.ui.web.voice_runtime import apply_voice_profile
-
- session_restarted = apply_voice_profile(request, CODEX_SUBSCRIPTION_VOICE_PROFILE)
- _invalidate_section_health_state(request)
- return {
- "ok": True,
- "active": body.provider,
- "profile": CODEX_SUBSCRIPTION_VOICE_PROFILE,
- "mode": "pipeline",
- "persisted": body.persist,
- "restart_required": False,
- "session_restarted": session_restarted,
- }
+ if spec.id == "codex-subscription-realtime" and not codex_transport_released:
+ # The realtime activation probe needs the same single-profile App Server
+ # lease as a warm classic subscription session. Release the old owner
+ # first, then let the actual realtime provider verify and keep its own
+ # transport warm.
+ await _release_codex_transports_for_voice_switch()
+ codex_transport_released = True
try:
from jarvis.core.registry import load
from jarvis.realtime.protocol import RealtimeProvider
@@ -4791,10 +4685,12 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
# A refused plan already recorded its sticky diagnosis where it was
# discovered (require_chatgpt_login) — the live call path shares it.
raise HTTPException(status_code=409, detail=str(exc)) from exc
- # The replacement provider is viable. Release any stable or legacy Codex
- # voice client before persisting/reopening the new session so switching
- # away and back never leaves an invisible subscription-profile owner.
- await _release_codex_transports_for_voice_switch()
+ # The replacement provider is viable. A non-Codex replacement must release
+ # any warm subscription transport before the active call is reopened. The
+ # Codex branch already released the previous owner before its live probe;
+ # closing again here would throw away the newly verified warm transport.
+ if spec.id != "codex-subscription-realtime":
+ await _release_codex_transports_for_voice_switch()
if spec.id == "codex-subscription-realtime":
from jarvis.codex_app_server import set_codex_subscription_activation_block
@@ -4803,33 +4699,48 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
# across filesystem work.
await asyncio.to_thread(set_codex_subscription_activation_block, None)
+ cfg = _resolve_cfg(request)
+ from jarvis.voice.subscription_profile import subscription_voice_selected
+
+ stale_subscription_profile = bool(
+ spec.id == "codex-subscription-realtime"
+ and cfg is not None
+ and subscription_voice_selected(cfg)
+ )
+ configured_mode = str(
+ getattr(getattr(cfg, "voice", None), "mode", "pipeline") or "pipeline"
+ ).strip().lower()
+ # Releases that routed this Realtime card through the classic composition
+ # persisted both the profile and Pipeline mode. That pair is repairable
+ # migration damage, not a user choice: selecting the same Realtime provider
+ # once restores Realtime. Ordinary provider switches preserve the mode.
+ effective_mode = "realtime" if stale_subscription_profile else configured_mode
+
if body.persist:
try:
from jarvis.core.config_writer import (
set_realtime_provider,
- set_voice_profile,
+ set_realtime_voice_selection,
)
- set_realtime_provider(body.provider)
- cfg_now = _resolve_cfg(request)
- from jarvis.voice.subscription_profile import (
- subscription_voice_selected,
- )
-
- if cfg_now is not None and subscription_voice_selected(cfg_now):
- current_mode = str(
- getattr(getattr(cfg_now, "voice", None), "mode", "pipeline") or "pipeline"
+ if cfg is not None and subscription_voice_selected(cfg):
+ set_realtime_voice_selection(
+ body.provider,
+ profile="",
+ mode=effective_mode,
)
- set_voice_profile("", mode=current_mode)
+ else:
+ set_realtime_provider(body.provider)
except FileNotFoundError as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc
except Exception as exc: # noqa: BLE001
raise HTTPException(status_code=500, detail=f"TOML write failed: {exc}") from exc
- cfg = _resolve_cfg(request)
if cfg is not None and getattr(cfg, "voice", None) is not None:
try:
cfg.voice.profile = ""
+ if stale_subscription_profile:
+ cfg.voice.mode = "realtime"
except Exception as exc: # noqa: BLE001 - detached config is harmless
log.debug("In-memory voice.profile update skipped: %s", exc)
if cfg is not None and getattr(cfg, "brain", None) is not None:
@@ -4877,6 +4788,8 @@ async def realtime_switch(body: SwitchBody, request: Request) -> dict[str, Any]:
return {
"ok": True,
"active": body.provider,
+ "profile": "",
+ "mode": effective_mode,
"persisted": body.persist,
"restart_required": False,
"session_restarted": session_restarted,
diff --git a/jarvis/ui/web/provider_spec.py b/jarvis/ui/web/provider_spec.py
index f8a1e75e02..ea0956d421 100644
--- a/jarvis/ui/web/provider_spec.py
+++ b/jarvis/ui/web/provider_spec.py
@@ -755,15 +755,16 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
install_hint="npm i -g @openai/[email protected]",
signup_url="https://chatgpt.com",
credential_help=(
- "Uses the ChatGPT plan signed in through Codex for stable streamed "
- "text generation. Jarvis keeps ownership of microphone capture, "
- "speech recognition, sentence synthesis, playback, follow-ups, and "
- "interruption, so the same voice pipeline works on Windows, macOS, "
- "and Linux. No OpenAI API key is used. Cloud STT or TTS providers "
- "may still bill their own configured keys; choose on-device speech "
- "providers for a fully non-metered audio path."
- ),
- experimental=False,
+ "Beta — subscription voice through Codex is not finished yet and "
+ "can break without notice. Uses the ChatGPT plan signed in through "
+ "Codex. The voice itself needs no API key, and the app never switches "
+ "it silently to metered API voice: if it cannot start, the call stops. "
+ "Select an API Realtime provider if you want usage billing. Jarvis "
+ "transcribes your side of the call with the provider selected in "
+ "Speech-to-Text, so a cloud recognizer can still bill its configured "
+ "key; choose an on-device one to keep input transcription local."
+ ),
+ experimental=True,
),
ProviderSpec(
id="openai-realtime",
diff --git a/jarvis/voice/subscription_profile.py b/jarvis/voice/subscription_profile.py
index 46225eaf6d..ceae859929 100644
--- a/jarvis/voice/subscription_profile.py
+++ b/jarvis/voice/subscription_profile.py
@@ -98,16 +98,16 @@ def subscription_voice_capability(
def configured_voice_profile(config: object) -> str:
- """Return the canonical profile, including the legacy selection alias."""
+ """Return only an explicitly selected classic-pipeline voice profile.
+
+ A realtime provider pin is not a profile alias. Treating the Codex
+ subscription provider as one silently changed ``voice.mode`` to pipeline
+ after a user selected it in the Realtime section.
+ """
voice = getattr(config, "voice", None)
profile = str(getattr(voice, "profile", "") or "").strip().lower()
if profile == CODEX_SUBSCRIPTION_VOICE_PROFILE:
return CODEX_SUBSCRIPTION_VOICE_PROFILE
- brain = getattr(config, "brain", None)
- realtime = getattr(brain, "realtime", None)
- provider = str(getattr(realtime, "provider", "") or "").strip().lower()
- if provider == LEGACY_CODEX_REALTIME_PROVIDER:
- return CODEX_SUBSCRIPTION_VOICE_PROFILE
return ""
diff --git a/tests/unit/core/test_voice_mode_config.py b/tests/unit/core/test_voice_mode_config.py
index 621bde06e8..8a1a9983fe 100644
--- a/tests/unit/core/test_voice_mode_config.py
+++ b/tests/unit/core/test_voice_mode_config.py
@@ -52,6 +52,63 @@ def test_set_subscription_voice_profile_persists_compatible_mode_atomically(
assert 'profile = "codex-subscription-voice"' in content
+def test_realtime_voice_selection_persists_all_three_values_once(
+ tmp_path: Path,
+ monkeypatch,
+):
+ toml = tmp_path / "jarvis.toml"
+ toml.write_text(
+ '[brain.realtime]\nprovider = "codex-subscription-realtime"\n\n'
+ '[voice]\nmode = "pipeline"\nprofile = "codex-subscription-voice"\n',
+ encoding="utf-8",
+ )
+ writes: list[str] = []
+ original_atomic_write = config_writer._atomic_write
+
+ def counted_write(path: Path, content: str) -> None:
+ writes.append(content)
+ original_atomic_write(path, content)
+
+ monkeypatch.setattr(config_writer, "_atomic_write", counted_write)
+
+ config_writer.set_realtime_voice_selection(
+ "codex-subscription-realtime",
+ profile="",
+ mode="realtime",
+ path=toml,
+ )
+
+ content = toml.read_text(encoding="utf-8")
+ assert len(writes) == 1
+ assert 'provider = "codex-subscription-realtime"' in content
+ assert 'profile = ""' in content
+ assert 'mode = "realtime"' in content
+
+
+def test_load_config_repairs_already_active_legacy_codex_realtime_state(
+ tmp_path: Path,
+ monkeypatch,
+):
+ toml = tmp_path / "jarvis.toml"
+ toml.write_text(
+ '[brain.realtime]\nprovider = "codex-subscription-realtime"\n\n'
+ '[voice]\nmode = "pipeline"\nprofile = "codex-subscription-voice"\n',
+ encoding="utf-8",
+ )
+ monkeypatch.setattr(cfg_mod, "resolve_config_path", lambda: toml)
+ cfg_mod._LEGACY_CODEX_REALTIME_HEALED.discard(toml)
+
+ loaded = cfg_mod.load_config()
+
+ assert loaded.brain.realtime is not None
+ assert loaded.brain.realtime.provider == "codex-subscription-realtime"
+ assert loaded.voice.mode == "realtime"
+ assert loaded.voice.profile == ""
+ content = toml.read_text(encoding="utf-8")
+ assert 'mode = "realtime"' in content
+ assert 'profile = ""' in content
+
+
def test_realtime_tier_field_accepts_brain_tier_config():
cfg = cfg_mod.JarvisConfig.model_validate(
{"brain": {"realtime": {"provider": "openai"}}}
diff --git a/tests/unit/realtime/test_factory.py b/tests/unit/realtime/test_factory.py
index 4704997dc3..513e5bb5b0 100644
--- a/tests/unit/realtime/test_factory.py
+++ b/tests/unit/realtime/test_factory.py
@@ -457,20 +457,11 @@ async def test_warm_selected_transports_still_warms_the_realtime_install(
assert warm.calls == 1
- ("profile", "provider"),
- [
- ("codex-subscription-voice", "openai-realtime"),
- ("", "codex-subscription-realtime"),
- ],
-)
@pytest.mark.asyncio
async def test_warm_selected_transports_skips_the_subscription_pipeline_profile(
monkeypatch,
- profile: str,
- provider: str,
) -> None:
- """Neither the canonical profile nor its legacy pin may warm duplex Codex."""
+ """An explicit classic profile must not warm an unused duplex transport."""
warm = _WarmProbe()
monkeypatch.setattr(
factory,
@@ -484,12 +475,39 @@ async def test_warm_selected_transports_skips_the_subscription_pipeline_profile(
)
await factory.realtime_warm_selected_transports(
- _cfg(mode="realtime", provider=provider, profile=profile)
+ _cfg(
+ mode="realtime",
+ provider="openai-realtime",
+ profile="codex-subscription-voice",
+ )
)
assert warm.calls == 0
+async def test_warm_selected_transports_keeps_codex_realtime_provider_realtime(
+ monkeypatch,
+) -> None:
+ warm = _WarmProbe()
+ monkeypatch.setattr(
+ factory,
+ "_explicit_provider_ids",
+ lambda _cfg: ["codex-subscription-realtime"],
+ )
+ monkeypatch.setattr(
+ factory,
+ "load",
+ lambda _group, _pid, protocol=None: warm,
+ )
+
+ await factory.realtime_warm_selected_transports(
+ _cfg(mode="realtime", provider="codex-subscription-realtime")
+ )
+
+ assert warm.calls == 1
+
+
def test_declared_handshake_budget_reaches_the_surface(monkeypatch) -> None:
"""A surface must not call a start attempt dead inside a declared budget.
diff --git a/tests/unit/ui/test_provider_spec_codex_subscription_realtime.py b/tests/unit/ui/test_provider_spec_codex_subscription_realtime.py
index 8fdaca3789..7ee98aa639 100644
--- a/tests/unit/ui/test_provider_spec_codex_subscription_realtime.py
+++ b/tests/unit/ui/test_provider_spec_codex_subscription_realtime.py
@@ -32,7 +32,7 @@ def test_codex_subscription_realtime_spec_has_no_api_key_path() -> None:
assert spec.auth_mode == "codex"
assert spec.secret_keys == ()
assert provider_billing(spec) == "subscription"
- assert spec.experimental is False
+ assert spec.experimental is True
@pytest.mark.parametrize(
@@ -260,7 +260,7 @@ async def test_plan_unsupported_activation_retries_the_live_gate(
request,
)
- assert gate_calls, "the stable text gate must re-judge a plan-blocked account"
+ assert gate_calls, "the realtime provider gate must re-judge a plan-blocked account"
assert close_calls == gate_calls
assert caught.value.status_code == 409
detail = str(caught.value.detail)
@@ -377,11 +377,13 @@ async def test_realtime_activation_reclaims_a_warm_transport_before_retry(
routes.SwitchBody(
provider="codex-subscription-realtime",
persist=False,
+ accept_experimental=True,
),
SimpleNamespace(app=SimpleNamespace(state=SimpleNamespace(config=config))),
)
- assert response["profile"] == "codex-subscription-voice"
+ assert response["profile"] == ""
+ assert response["mode"] == "realtime"
assert release_calls == ["released"]
assert snapshots == []
@@ -883,10 +885,11 @@ def test_reason_code_vocabulary_is_pinned() -> None:
@pytest.mark.asyncio
-async def test_subscription_profile_no_longer_requires_experimental_acknowledgement(
+async def test_subscription_realtime_activation_preserves_realtime_mode(
monkeypatch: pytest.MonkeyPatch,
) -> None:
from jarvis import codex_app_server
+ from jarvis.core import config_writer
monkeypatch.setattr(
routes,
@@ -928,6 +931,12 @@ async def test_subscription_profile_no_longer_requires_experimental_acknowledgem
"_release_codex_transports_for_voice_switch",
release_previous_transport,
)
+ persisted: list[tuple[str, str]] = []
+ monkeypatch.setattr(
+ config_writer,
+ "set_realtime_provider",
+ lambda provider: persisted.append(("provider", provider)),
+ )
config = SimpleNamespace(
codex=SimpleNamespace(binary_path="codex"),
voice=SimpleNamespace(profile="", mode="realtime"),
@@ -936,15 +945,93 @@ async def test_subscription_profile_no_longer_requires_experimental_acknowledgem
response = await routes.realtime_switch(
routes.SwitchBody(
provider="codex-subscription-realtime",
- persist=False,
+ persist=True,
+ accept_experimental=True,
),
SimpleNamespace(app=SimpleNamespace(state=SimpleNamespace(config=config))),
)
- assert response["profile"] == "codex-subscription-voice"
- assert response["mode"] == "pipeline"
- assert len(close_calls) == 1
+ assert response["profile"] == ""
+ assert response["mode"] == "realtime"
+ assert config.voice.mode == "realtime"
+ assert config.brain.realtime.provider == "codex-subscription-realtime"
+ assert close_calls == []
assert release_calls == ["released"]
+ assert persisted == [("provider", "codex-subscription-realtime")]
+
+
+async def test_subscription_realtime_activation_repairs_the_old_pipeline_profile(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ from jarvis import codex_app_server
+ from jarvis.core import config_writer
+
+ monkeypatch.setattr(
+ routes,
+ "_codex_subscription_status_payload",
+ lambda _binary_path: {
+ "installed": True,
+ "connected": True,
+ "mode": "chatgpt",
+ "message": "ready",
+ "reason_code": "ready",
+ },
+ )
+
+ class _Client:
+ async def require_chatgpt_login(self) -> None:
+ return None
+
+ monkeypatch.setattr(
+ codex_app_server,
+ "get_shared_codex_app_server",
+ lambda *_args, **_kwargs: _Client(),
+ )
+ monkeypatch.setattr(
+ codex_app_server,
+ "set_codex_subscription_activation_block",
+ lambda _value: None,
+ )
+
+ async def release_previous_transport() -> None:
+ return None
+
+ monkeypatch.setattr(
+ routes,
+ "_release_codex_transports_for_voice_switch",
+ release_previous_transport,
+ )
+
+ writes: list[tuple[str, str, str]] = []
+ monkeypatch.setattr(
+ config_writer,
+ "set_realtime_voice_selection",
+ lambda provider, *, profile, mode: writes.append(
+ (provider, profile, mode)
+ ),
+ )
+ config = SimpleNamespace(
+ codex=SimpleNamespace(binary_path="codex"),
+ voice=SimpleNamespace(profile="codex-subscription-voice", mode="pipeline"),
+ brain=SimpleNamespace(realtime=SimpleNamespace(provider="openai-realtime")),
+ )
+
+ response = await routes.realtime_switch(
+ routes.SwitchBody(
+ provider="codex-subscription-realtime",
+ persist=True,
+ accept_experimental=True,
+ ),
+ SimpleNamespace(app=SimpleNamespace(state=SimpleNamespace(config=config))),
+ )
+
+ assert response["mode"] == "realtime"
+ assert response["profile"] == ""
+ assert config.voice.mode == "realtime"
+ assert config.voice.profile == ""
+ assert config.brain.realtime.provider == "codex-subscription-realtime"
+ assert writes == [("codex-subscription-realtime", "", "realtime")]
@pytest.mark.asyncio
diff --git a/tests/unit/voice/test_subscription_profile.py b/tests/unit/voice/test_subscription_profile.py
index 48544c1821..e8d83fa066 100644
--- a/tests/unit/voice/test_subscription_profile.py
+++ b/tests/unit/voice/test_subscription_profile.py
@@ -22,24 +22,23 @@ def _config(*, profile: str = "", realtime_provider: str = "") -> SimpleNamespac
)
-def test_canonical_and_legacy_selections_resolve_to_stable_profile() -> None:
+def test_only_explicit_profile_selects_the_classic_subscription_composition() -> None:
assert (
configured_voice_profile(profile := _config(profile=CODEX_SUBSCRIPTION_VOICE_PROFILE))
== CODEX_SUBSCRIPTION_VOICE_PROFILE
)
assert profile.voice.mode == "realtime"
- assert (
- configured_voice_profile(_config(realtime_provider="codex-subscription-realtime"))
- == CODEX_SUBSCRIPTION_VOICE_PROFILE
- )
+ assert configured_voice_profile(
+ _config(realtime_provider="codex-subscription-realtime")
+ ) == ""
assert configured_voice_profile(_config()) == ""
-def test_legacy_selection_forces_classic_pipeline_engine() -> None:
+def test_realtime_provider_pin_does_not_change_the_selected_engine() -> None:
pipeline = SpeechPipeline.__new__(SpeechPipeline)
pipeline._config = _config(realtime_provider="codex-subscription-realtime")
- assert pipeline._configured_voice_mode() == "pipeline"
+ assert pipeline._configured_voice_mode() == "realtime"
def test_profile_can_be_applied_and_removed_without_process_restart() -> None:
diff --git a/tests/unit/web/test_realtime_option_validation.py b/tests/unit/web/test_realtime_option_validation.py
index 5612628472..662b6eacee 100644
--- a/tests/unit/web/test_realtime_option_validation.py
+++ b/tests/unit/web/test_realtime_option_validation.py
@@ -120,10 +120,9 @@ def test_get_realtime_options_reports_preview_capability(
body = subscription_response.json()
assert body["preview_available"] is True
assert body["models"] == [
- {"id": "auto", "label": "Codex App Server (subscription text)"}
+ {"id": "auto", "label": "ChatGPT-Live (model chosen by OpenAI)"}
]
- assert body["voices"] == [
- {"id": "configured-tts", "label": "Configured Jarvis voice output"}
- ]
- assert body["current_model"] == "auto"
- assert body["current_voice"] == "configured-tts"
+ assert body["voices"][0] == {"id": "cove", "label": "cove"}
+ assert "configured-tts" not in {voice["id"] for voice in body["voices"]}
+ assert body["current_model"] == ""
+ assert body["current_voice"] == ""
diff --git a/tests/unit/web/test_realtime_voice_preview.py b/tests/unit/web/test_realtime_voice_preview.py
index 00fb98cae5..ccbe2a7110 100644
--- a/tests/unit/web/test_realtime_voice_preview.py
+++ b/tests/unit/web/test_realtime_voice_preview.py
@@ -10,7 +10,6 @@ from __future__ import annotations
import io
import wave
-from types import SimpleNamespace
import pytest
from fastapi import FastAPI
@@ -18,7 +17,6 @@ from fastapi.testclient import TestClient
from jarvis.core import config as cfg_mod
from jarvis.core.config import JarvisConfig
-from jarvis.core.protocols import AudioChunk, BrainDelta
from jarvis.ui.web import provider_routes
from jarvis.ui.web.provider_routes import router
@@ -113,42 +111,6 @@ def test_subscription_preview_does_not_require_an_api_key(
assert response.status_code == 200
-async def test_subscription_sampler_uses_text_brain_and_configured_tts(
- monkeypatch: pytest.MonkeyPatch,
-) -> None:
- from jarvis.plugins import tts as tts_module
- from jarvis.plugins.brain import codex
-
- requests = []
-
- async def complete(_self, request):
- requests.append(request)
- yield BrainDelta(content="Ready.")
- yield BrainDelta(finish_reason="stop")
-
- class TTS:
- async def synthesize(self, text, *, language_code=None):
- assert text == "Ready."
- assert language_code == "de-DE"
- yield AudioChunk(b"\x01\x02" * 10, 22_050, 0, 1)
-
- async def aclose(self) -> None:
- return None
-
- monkeypatch.setattr(codex.CodexBrain, "complete", complete)
- monkeypatch.setattr(cfg_mod, "load_config", lambda: SimpleNamespace(tts=object()))
- monkeypatch.setattr(tts_module, "build_tts_from_config", lambda _cfg: TTS())
-
- pcm, rate = await provider_routes._codex_subscription_voice_sample(
- "", model="", voice="cove", text="Ready.", language="de"
- )
-
- assert pcm == b"\x01\x02" * 10
- assert rate == 22_050
- assert requests and requests[0].tools == ()
-
-
def test_happy_path_returns_playable_wav(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(cfg_mod, "get_provider_secret", lambda _pid: "sk-test")
calls: list[dict[str, str]] = []