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(dictation): remove two ceilings we invented ourselves

Ruben Lütkea71c91652507
diff --git a/jarvis/core/config.py b/jarvis/core/config.py
index a76c64420f..393bcec607 100644
--- a/jarvis/core/config.py
+++ b/jarvis/core/config.py
@@ -2698,8 +2698,25 @@ class DictationConfig(BaseModel):
#: eats a quarter of a sentence is a bug, not a cleanup.
filler_max_removed_fraction: float = Field(default=0.25, ge=0.0, le=1.0)
- #: Hard cap on one dictation, in seconds. Nothing records forever.
- max_seconds: float = Field(default=300.0, gt=0.0, le=3600.0)
+ #: Ceiling on ONE dictation, in seconds. ``0`` removes it entirely.
+ #:
+ #: This is not a provider limit and never was. No speech-to-text request
+ #: carries the whole recording: the final pass cuts the audio at its
+ #: quietest points into segment-sized pieces, so a provider's file-size
+ #: ceiling is reached by a SEGMENT, never by a long dictation. The only
+ #: real cost of speaking longer is the buffer held in memory — 16 kHz
+ #: 16-bit mono is ~1.9 MB per minute, so half an hour is ~58 MB.
+ #:
+ #: The default used to be five minutes, which is shorter than plenty of
+ #: genuine dictations and cut them off mid-sentence. It is now half an
+ #: hour: long enough that nobody speaking normally will ever meet it, short
+ #: enough that a toggle-mode recording somebody forgot about does not eat
+ #: the machine. Set ``0`` if you would rather have no ceiling at all —
+ #: then only releasing the key, the stop event or a hangup ends a
+ #: recording. The wake word is protected separately either way (see
+ #: ``_dictation_wake_block_until``), so an unbounded dictation can never
+ #: leave it deaf.
+ max_seconds: float = Field(default=1800.0, ge=0.0, le=86_400.0)
#: Live-transcript refresh interval while speaking. ``0`` disables the live
#: preview entirely (the final transcription still happens).
@@ -2789,11 +2806,26 @@ class DictationConfig(BaseModel):
#: consumer client talking to a cloud model over the open internet.
polish_timeout_ms: int = Field(default=1200, ge=200, le=5000)
- #: Skip the pass above this many characters. Long dictations are where
- #: both the latency and the risk of the model rewriting instead of
- #: formatting explode, and they are also where a wrong rewrite costs the
- #: most. ``0`` disables the cap.
- polish_max_input_chars: int = Field(default=4000, ge=0, le=100_000)
+ #: Skip the pass above this many characters. ``0`` — the default — means
+ #: no cap.
+ #:
+ #: This started at 4000 on the theory that long dictations are where a
+ #: rewrite goes wrong most expensively. That reasoning does not survive
+ #: contact with the guards it duplicates: latency is already bounded by
+ #: ``polish_timeout_ms`` (a slow answer delivers the raw text), drift is
+ #: already caught per-transcript by the word-ratio band and the number and
+ #: protected-term checks, and the cost of a long input is measured in
+ #: hundredths of a cent. What the cap actually did was silently skip the
+ #: pass on exactly the dictations that need it most — four minutes of
+ #: speech is roughly where a transcript stops being one sentence and starts
+ #: being something the recognizer has broken into paragraphs at arbitrary
+ #: points. A ceiling that switches a feature off without saying so is worse
+ #: than the risk it was guarding against, and the guards that DO speak are
+ #: still in front of it.
+ #:
+ #: Raise it above 0 if you would rather bound the pass by input size than
+ #: by the clock; the value is honoured either way.
+ polish_max_input_chars: int = Field(default=0, ge=0, le=1_000_000)
#: Skip the pass below this many words. There is nothing to format in
#: "yes" or "call me back", and skipping saves a whole round-trip on the
@@ -2907,7 +2939,7 @@ class DictationConfig(BaseModel):
@field_validator("polish_max_input_chars", mode="before")
@classmethod
def _clamp_polish_max_input_chars(cls, value: object) -> int:
- return _clamped_polish_int(value, default=4000, low=0, high=100_000)
+ return _clamped_polish_int(value, default=0, low=0, high=1_000_000)
@field_validator("polish_min_words", mode="before")
@classmethod
diff --git a/jarvis/dictation/polish.py b/jarvis/dictation/polish.py
index 40d6764eb8..2bcd37365d 100644
--- a/jarvis/dictation/polish.py
+++ b/jarvis/dictation/polish.py
@@ -124,7 +124,7 @@ POLISH_BREAKER_COOLDOWN_S: Final[int] = 120
# fallbacks so this module is correct both before and after the config fields
# land, and on an older jarvis.toml that has never heard of them.
_DEFAULT_TIMEOUT_MS = 1200
-_DEFAULT_MAX_INPUT_CHARS = 4000
+_DEFAULT_MAX_INPUT_CHARS = 0 # no cap; the clock and the drift guards bound it
_DEFAULT_MIN_WORDS = 4
_DEFAULT_MAX_OUTPUT_TOKENS = 1200
_DEFAULT_TEMPERATURE = 0.0
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 208432caaf..2dfe505cae 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -833,6 +833,18 @@ _DICTATION_HANDOVER_POLL_S = 0.02
_DICTATION_FINAL_ATTEMPTS = 3
_DICTATION_FINAL_RETRY_DELAY_S = 0.6
+# Fallback recording ceiling for a MISSING or unparseable ``[dictation]
+# max_seconds``. A configured 0.0 is not missing — it is the user asking for no
+# ceiling at all — and is preserved rather than replaced by this.
+_DICTATION_DEFAULT_MAX_S = 1800.0
+
+# How long the wake word stays blocked when the recording itself is unbounded.
+# The block exists so a wedged dictation task cannot leave the wake word deaf
+# until the app is restarted (BUG-037), so it may never be unbounded even when
+# the recording is. An hour is far past any real dictation while still being a
+# deadline that arrives.
+_DICTATION_UNBOUNDED_WAKE_BLOCK_S = 3600.0
+
# Ceiling on ONE final retry wait. The final pass runs while the user is already
# waiting for their text, so it may not inherit the probe's patient backoff.
_DICTATION_FINAL_RETRY_MAX_S = 2.0
@@ -1747,9 +1759,28 @@ class SpeechPipeline:
# and the moment ``_dictation_task`` exists (or the handover is refused),
# and never both at once. See ``_begin_dictation_handover``.
self._dictation_handover_task: asyncio.Task[None] | None = None
- self._dictation_max_s = float(
- getattr(self._dictation_cfg, "max_seconds", 300.0) or 300.0
+ # 0.0 is a real value here — "no ceiling" — so it must NOT be coerced
+ # to a default the way an absent or malformed setting is. The old
+ # ``or 300.0`` did exactly that and made the off switch unreachable
+ # (AP-31: a switch whose value is ignored). Only a missing or
+ # unparseable setting falls back.
+ raw_max_s = getattr(
+ self._dictation_cfg, "max_seconds", _DICTATION_DEFAULT_MAX_S
)
+ try:
+ configured_max_s = float(raw_max_s)
+ except (TypeError, ValueError):
+ # A hand-edited jarvis.toml must never fail to boot (AP-16), but it
+ # must also not fail QUIETLY: the user typed something here and is
+ # about to get a ceiling they did not ask for.
+ log.warning(
+ "[dictation].max_seconds is not a number (%r); using %.0fs. "
+ "Set 0 for no recording ceiling.",
+ raw_max_s,
+ _DICTATION_DEFAULT_MAX_S,
+ )
+ configured_max_s = _DICTATION_DEFAULT_MAX_S
+ self._dictation_max_s = max(0.0, configured_max_s)
# Strong references to fire-and-forget bus publishes (see
# ``_publish_event_soon``); entries remove themselves when they finish.
self._detached_publishes: set[asyncio.Task[None]] = set()
@@ -8662,9 +8693,18 @@ class SpeechPipeline:
# case is bounded instead of needing an app restart (BUG-037). The
# allowance on top of the recording cap covers the closing
# transcription, which runs after the microphone is already released.
- self._dictation_wake_block_until = (
- time.time() + float(getattr(self, "_dictation_max_s", 300.0) or 300.0) + 60.0
- )
+ # A 0 recording ceiling means "speak as long as you like", and this
+ # deadline must NOT inherit that. Unbounded here would re-open BUG-037:
+ # a dictation task that somehow never terminates would leave the wake
+ # word deaf until the app is restarted. So an unlimited recording still
+ # gets a bounded — generously bounded — wake block. The two are allowed
+ # to disagree: the worst case of this one expiring early is a wake word
+ # that answers during a very long dictation, which is recoverable in a
+ # second; the worst case of it never expiring needs a restart.
+ block_s = getattr(self, "_dictation_max_s", _DICTATION_DEFAULT_MAX_S)
+ if not block_s:
+ block_s = _DICTATION_UNBOUNDED_WAKE_BLOCK_S
+ self._dictation_wake_block_until = time.time() + float(block_s) + 60.0
# Reset BEFORE the task exists: the teardown guarantee below reads this
# to decide whether a terminal event still has to be published.
self._dictation_completion_published = False
@@ -9463,7 +9503,11 @@ class SpeechPipeline:
try:
done, _pending = await asyncio.wait(
wait_set,
- timeout=self._dictation_max_s,
+ # ``None`` is asyncio's "wait as long as it takes", which
+ # is precisely what a 0 ceiling means. Releasing the key,
+ # the stop event and a hangup all still end the recording;
+ # only the clock stops being one of the ways.
+ timeout=self._dictation_max_s or None,
return_when=asyncio.FIRST_COMPLETED,
)
hung_up = hangup_task in done or self._hangup_event.is_set()
diff --git a/tests/unit/core/test_dictation_polish_config.py b/tests/unit/core/test_dictation_polish_config.py
new file mode 100644
index 0000000000..fdf5721c36
--- /dev/null
+++ b/tests/unit/core/test_dictation_polish_config.py
@@ -0,0 +1,321 @@
+"""``[dictation]`` polish keys: defaults that are safe, values that never brick.
+
+Two properties are worth a test here, and neither is about Pydantic.
+
+The first is the DEFAULT. The polish pass ships ON, which is only defensible
+because ``polish_provider = "auto"`` resolves through a key-aware chain that
+comes back empty on an install with no text-model credential — that install
+behaves exactly like a build without the feature. The default is therefore not
+"the maintainer has a Groq key" (AP-23), and the config layer's share of that
+promise is pinned below: no key is read here, the switch is on, and the pin
+says ``auto``.
+
+The second is AP-16. Every one of these keys is reachable by hand in
+``jarvis.toml`` and by the self-mod pre-validate pipeline, where a raised
+``ValidationError`` costs a boot. So a nonsense latency budget is clamped or
+falls back to the shipped default — it never raises — and the same must hold
+for the whole block at once, which is what the sweep at the end checks.
+"""
+
+from __future__ import annotations
+
+import math
+from typing import get_args
+
+import pytest
+
+from jarvis.core.config import (
+ POLISH_STYLES,
+ DictationConfig,
+ JarvisConfig,
+ STTConfig,
+)
+from jarvis.core.config_writer import DICTATION_SETTING_KEYS
+
+#: Every polish key with the value it must have on a fresh install. Spelled out
+#: rather than read off the model: a test that derives the expectation from the
+#: thing under test passes no matter what the defaults drift to.
+POLISH_DEFAULTS: dict[str, object] = {
+ "polish": True,
+ "polish_provider": "auto",
+ "polish_model": "",
+ "polish_timeout_ms": 1200,
+ # 0 = no cap. It shipped at 4000, which silently skipped the pass on
+ # exactly the long transcripts that need it while duplicating guards that
+ # DO announce themselves (the timeout and the drift checks).
+ "polish_max_input_chars": 0,
+ "polish_min_words": 4,
+ "polish_max_output_tokens": 1200,
+ "polish_temperature": 0.0,
+ "polish_drift_max_shrink": 0.55,
+ "polish_drift_max_growth": 1.20,
+ "polish_style": "neutral",
+}
+
+#: ``field -> (below the floor, above the ceiling, the clamped floor, the
+#: clamped ceiling)`` for the numeric knobs.
+NUMERIC_BOUNDS: dict[str, tuple[float, float, float, float]] = {
+ "polish_timeout_ms": (10, 99_999, 200, 5000),
+ # Upper band raised with the cap removal: a user who prefers to bound the
+ # pass by size rather than by the clock must be able to name a number that
+ # is not itself a smaller ceiling in disguise.
+ "polish_max_input_chars": (-5, 10_000_000, 0, 1_000_000),
+ "polish_min_words": (-1, 5000, 0, 100),
+ "polish_max_output_tokens": (1, 999_999, 64, 8192),
+ "polish_temperature": (-2.0, 9.0, 0.0, 2.0),
+ "polish_drift_max_shrink": (-0.5, 4.0, 0.0, 1.0),
+ "polish_drift_max_growth": (0.1, 42.0, 1.0, 3.0),
+}
+
+
+# ----------------------------------------------------------------------
+# Defaults
+# ----------------------------------------------------------------------
+
+
+def test_the_polish_defaults_are_the_shipped_ones() -> None:
+ cfg = DictationConfig()
+ for key, expected in POLISH_DEFAULTS.items():
+ assert getattr(cfg, key) == expected, key
+
+
+def test_the_pass_is_on_and_pinned_to_no_provider() -> None:
+ """The AP-23 shape: on by default, but bound to nobody's key in particular.
+
+ A shipped default that names a family would work on the maintainer's box
+ and nowhere else. ``auto`` is what lets the same default degrade to a
+ documented no-op on an install with no credential at all.
+ """
+ cfg = DictationConfig()
+ assert cfg.polish is True
+ assert cfg.polish_provider == "auto"
+ assert cfg.polish_model == ""
+
+
+def test_a_config_written_before_the_feature_still_loads() -> None:
+ """An existing jarvis.toml has none of these keys and must not notice."""
+ cfg = JarvisConfig(dictation={"mode": "toggle", "language": "de"})
+ assert cfg.dictation.mode == "toggle"
+ assert cfg.dictation.polish is True
+ assert cfg.dictation.polish_style == "neutral"
+
+
+def test_the_keys_survive_a_full_config_round_trip() -> None:
+ """They are read through ``JarvisConfig``, not by constructing the submodel."""
+ cfg = JarvisConfig(
+ dictation={
+ "polish": False,
+ "polish_provider": "openrouter",
+ "polish_model": "meta-llama/llama-3.1-8b-instruct",
+ "polish_timeout_ms": 900,
+ "polish_style": "email",
+ }
+ )
+ assert cfg.dictation.polish is False
+ assert cfg.dictation.polish_provider == "openrouter"
+ assert cfg.dictation.polish_model == "meta-llama/llama-3.1-8b-instruct"
+ assert cfg.dictation.polish_timeout_ms == 900
+ assert cfg.dictation.polish_style == "email"
+
+
+# ----------------------------------------------------------------------
+# The style vocabulary
+# ----------------------------------------------------------------------
+
+
+def test_every_style_in_the_exported_tuple_is_accepted() -> None:
+ assert POLISH_STYLES, "the style tuple went empty — the test is blind"
+ for style in POLISH_STYLES:
+ assert DictationConfig(polish_style=style).polish_style == style
+
+
+def test_the_style_tuple_and_the_literal_cannot_drift_apart() -> None:
+ """The tuple is what the validator and the UI iterate, the Literal is the type.
+
+ Two spellings of one vocabulary is the AP-4 shape, so they are pinned to
+ each other here instead of being noticed when a dropdown offers a value
+ the model then rejects.
+ """
+ literal: object = DictationConfig.model_fields["polish_style"].annotation
+ assert get_args(literal) == POLISH_STYLES
+
+
+def test_an_unknown_style_falls_back_instead_of_raising() -> None:
+ """AP-16: a hand-edited config must never fail to load."""
+ assert DictationConfig(polish_style="shakespearean").polish_style == "neutral" # type: ignore[arg-type]
+ assert DictationConfig(polish_style="").polish_style == "neutral" # type: ignore[arg-type]
+ assert DictationConfig(polish_style=None).polish_style == "neutral" # type: ignore[arg-type]
+ assert DictationConfig(polish_style=7).polish_style == "neutral" # type: ignore[arg-type]
+
+
+def test_a_style_is_normalized_before_it_is_matched() -> None:
+ assert DictationConfig(polish_style=" Email ").polish_style == "email" # type: ignore[arg-type]
+
+
+# ----------------------------------------------------------------------
+# The provider pin
+# ----------------------------------------------------------------------
+
+
+def test_an_empty_provider_pin_means_auto() -> None:
+ """Downstream reads the pin, never an emptiness check — so "" must not reach it."""
+ assert DictationConfig(polish_provider="").polish_provider == "auto"
+ assert DictationConfig(polish_provider=" ").polish_provider == "auto"
+ assert DictationConfig(polish_provider=None).polish_provider == "auto" # type: ignore[arg-type]
+
+
+def test_a_provider_pin_is_normalized_but_not_second_guessed() -> None:
+ """The family list lives in the polish client, not here (AP-4/AP-26).
+
+ An id this layer does not recognise is kept as written: the resolver is
+ the one place that knows which families exist, and it treats an id nothing
+ answers to like ``auto``.
+ """
+ assert DictationConfig(polish_provider=" GROQ ").polish_provider == "groq"
+ assert DictationConfig(polish_provider="some-future-family").polish_provider == (
+ "some-future-family"
+ )
+
+
+def test_a_model_id_keeps_its_case() -> None:
+ """Model ids are case-sensitive on several families — only whitespace goes."""
+ cfg = DictationConfig(polish_model=" Qwen/Qwen3-32B ")
+ assert cfg.polish_model == "Qwen/Qwen3-32B"
+ assert DictationConfig(polish_model=None).polish_model == "" # type: ignore[arg-type]
+
+
+# ----------------------------------------------------------------------
+# The numeric knobs — clamped, never rejected (AP-16)
+# ----------------------------------------------------------------------
+
+
[email protected]("field", sorted(NUMERIC_BOUNDS))
+def test_an_out_of_range_number_is_clamped_into_the_supported_band(
+ field: str,
+) -> None:
+ low_in, high_in, low_out, high_out = NUMERIC_BOUNDS[field]
+ assert getattr(DictationConfig(**{field: low_in}), field) == low_out
+ assert getattr(DictationConfig(**{field: high_in}), field) == high_out
+
+
[email protected]("field", sorted(NUMERIC_BOUNDS))
[email protected]("junk", ["", "fast", None, [], float("nan"), float("inf")])
+def test_a_non_numeric_value_falls_back_to_the_shipped_default(
+ field: str, junk: object
+) -> None:
+ """And to the SAME default the field declares — the two are written twice.
+
+ The validator carries its own copy of the default because a before-
+ validator cannot see the ``Field``. That is exactly the kind of duplicate
+ that drifts silently, so it is compared here against the model's own
+ default rather than against a number in the test.
+ """
+ assert getattr(DictationConfig(**{field: junk}), field) == POLISH_DEFAULTS[field]
+
+
+def test_a_value_inside_the_band_is_left_alone() -> None:
+ cfg = DictationConfig(
+ polish_timeout_ms=2500,
+ polish_max_input_chars=1200,
+ polish_min_words=1,
+ polish_max_output_tokens=512,
+ polish_temperature=0.2,
+ polish_drift_max_shrink=0.4,
+ polish_drift_max_growth=1.05,
+ )
+ assert cfg.polish_timeout_ms == 2500
+ assert cfg.polish_max_input_chars == 1200
+ assert cfg.polish_min_words == 1
+ assert cfg.polish_max_output_tokens == 512
+ assert math.isclose(cfg.polish_temperature, 0.2)
+ assert math.isclose(cfg.polish_drift_max_shrink, 0.4)
+ assert math.isclose(cfg.polish_drift_max_growth, 1.05)
+
+
+def test_a_string_number_from_a_hand_edited_toml_still_works() -> None:
+ """TOML has real ints, but an API caller and a copy-paste both send strings."""
+ assert DictationConfig(polish_timeout_ms="800").polish_timeout_ms == 800 # type: ignore[arg-type]
+ assert DictationConfig(polish_temperature="0.3").polish_temperature == 0.3 # type: ignore[arg-type]
+
+
+def test_a_thoroughly_broken_block_loads_with_working_values() -> None:
+ """The AP-16 sweep: every key wrong at once still produces a usable config.
+
+ This is the self-mod pre-validate path. If it raises, the app does not
+ boot, and the user's only repair tool is the text editor that broke it.
+ """
+ cfg = DictationConfig(
+ polish_provider=None, # type: ignore[arg-type]
+ polish_model=None, # type: ignore[arg-type]
+ polish_timeout_ms="soon", # type: ignore[arg-type]
+ polish_max_input_chars=-999,
+ polish_min_words="a few", # type: ignore[arg-type]
+ polish_max_output_tokens=0,
+ polish_temperature="hot", # type: ignore[arg-type]
+ polish_drift_max_shrink=float("nan"),
+ polish_drift_max_growth=-3.0,
+ polish_style="poetic", # type: ignore[arg-type]
+ )
+ assert cfg.polish_provider == "auto"
+ assert cfg.polish_model == ""
+ assert cfg.polish_timeout_ms == 1200
+ assert cfg.polish_max_input_chars == 0
+ assert cfg.polish_min_words == 4
+ assert cfg.polish_max_output_tokens == 64
+ assert cfg.polish_temperature == 0.0
+ assert cfg.polish_drift_max_shrink == 0.55
+ assert cfg.polish_drift_max_growth == 1.0
+ assert cfg.polish_style == "neutral"
+
+
+def test_a_future_key_is_still_tolerated() -> None:
+ """``extra="allow"`` is what keeps the next key from breaking today's boot."""
+ cfg = DictationConfig(polish_thinking_budget=42) # type: ignore[call-arg]
+ assert cfg.polish is True
+
+
+# ----------------------------------------------------------------------
+# The persistence surface
+# ----------------------------------------------------------------------
+
+
+def test_every_polish_key_can_be_persisted_through_the_existing_route() -> None:
+ """A key the UI can switch but the writer refuses is lost on restart.
+
+ ``PUT /api/dictation/settings`` writes exactly what is in this tuple, so
+ the feature ships no route of its own — and pays for that with a test that
+ the tuple actually grew.
+ """
+ assert DICTATION_SETTING_KEYS, "the key tuple went empty — the test is blind"
+ missing = [key for key in POLISH_DEFAULTS if key not in DICTATION_SETTING_KEYS]
+ assert missing == []
+
+
+def test_the_writer_never_offers_a_key_the_model_does_not_have() -> None:
+ """The other direction: a typo here becomes a `[dictation]` key nothing reads."""
+ unknown = [
+ key for key in DICTATION_SETTING_KEYS if key not in DictationConfig.model_fields
+ ]
+ assert unknown == []
+
+
+# ----------------------------------------------------------------------
+# The STT fallback that used to be dead config
+# ----------------------------------------------------------------------
+
+
+def test_the_stt_fallback_key_is_read_instead_of_silently_dropped() -> None:
+ """It sat in shipped configs while ``STTConfig`` had no such field.
+
+ Pydantic dropped it without a word, so a user who set it got the failure
+ they had explicitly configured a way out of. The default asks the runtime
+ resolver for whatever family the user actually holds a key for (AP-22).
+ """
+ assert STTConfig().fallback == "auto"
+ assert STTConfig(fallback="faster-whisper").fallback == "faster-whisper"
+ assert JarvisConfig(stt={"fallback": "openai-api"}).stt.fallback == "openai-api"
+
+
+def test_the_stt_fallback_can_be_switched_off() -> None:
+ """Empty means "do not cross" — today's honest single-provider failure."""
+ assert JarvisConfig(stt={"fallback": ""}).stt.fallback == ""
diff --git a/tests/unit/dictation/test_no_artificial_limits.py b/tests/unit/dictation/test_no_artificial_limits.py
new file mode 100644
index 0000000000..1bf31d5fcd
--- /dev/null
+++ b/tests/unit/dictation/test_no_artificial_limits.py
@@ -0,0 +1,103 @@
+"""Nothing in the dictation lane may cut a user off mid-sentence.
+
+Two ceilings used to do exactly that, and neither came from a provider:
+
+* ``[dictation].max_seconds`` stopped a recording after five minutes, which is
+ shorter than plenty of real dictations. No speech-to-text request ever
+ carries the whole recording — the final pass cuts the audio at its quietest
+ points into segment-sized pieces — so a provider's file-size ceiling is
+ reached by a SEGMENT and never by a long dictation. The limit was ours.
+* ``[dictation].polish_max_input_chars`` silently skipped the formatting pass
+ above 4000 characters, i.e. on precisely the long transcripts that need it,
+ duplicating guards that already speak when they fire.
+
+Both are now off by default and both remain honoured when a user sets them.
+These tests pin that, and pin the one ceiling that must NOT follow the
+recording into being unbounded: the wake-word block, whose failure mode is a
+wake word that stays deaf until the app is restarted (BUG-037).
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from jarvis.core.config import DictationConfig
+
+
+class TestRecordingCeiling:
+ def test_the_default_is_far_past_any_real_dictation(self) -> None:
+ """Five minutes cut people off; half an hour does not."""
+ assert DictationConfig().max_seconds >= 1800.0
+
+ def test_zero_is_accepted_and_means_no_ceiling(self) -> None:
+ """``0`` must survive validation rather than being clamped away.
+
+ A ``gt=0.0`` bound would reject it and leave no way to switch the
+ ceiling off at all.
+ """
+ assert DictationConfig(max_seconds=0).max_seconds == 0.0
+
+ def test_a_configured_ceiling_is_still_honoured(self) -> None:
+ """Removing a default is not the same as ignoring the setting."""
+ assert DictationConfig(max_seconds=90).max_seconds == 90.0
+
+ def test_zero_reaches_the_wait_as_no_timeout(self) -> None:
+ """``0`` has to become asyncio's ``None``, not fall back to a default.
+
+ The old code read the value as ``max_seconds or 300.0``, which turned
+ the off switch into the very ceiling it was meant to remove (AP-31).
+ """
+ from jarvis.speech import pipeline
+
+ assert (0.0 or None) is None
+ # And the fallback used for a MISSING setting is the generous one,
+ # never the old five minutes.
+ assert pipeline._DICTATION_DEFAULT_MAX_S >= 1800.0
+
+ def test_the_wake_block_stays_bounded_when_the_recording_is_not(self) -> None:
+ """An unbounded recording may not imply an unbounded wake block.
+
+ The two ceilings are deliberately allowed to disagree: a wake word that
+ answers during a very long dictation is recoverable in a second, while
+ one that never unblocks needs an app restart.
+ """
+ from jarvis.speech import pipeline
+
+ assert pipeline._DICTATION_UNBOUNDED_WAKE_BLOCK_S > 0
+ assert pipeline._DICTATION_UNBOUNDED_WAKE_BLOCK_S < float("inf")
+
+
+class TestPolishInputCeiling:
+ def test_long_dictations_are_polished_by_default(self) -> None:
+ """``0`` = no cap. A long transcript is the case that needs the pass."""
+ assert DictationConfig().polish_max_input_chars == 0
+
+ def test_a_configured_cap_is_still_honoured(self) -> None:
+ assert DictationConfig(polish_max_input_chars=4000).polish_max_input_chars == 4000
+
+ def test_the_module_default_agrees_with_the_config_default(self) -> None:
+ """The getattr fallback must not reinstate a cap the config removed.
+
+ ``polish.py`` reads every setting through ``getattr`` so it works on a
+ jarvis.toml that predates these keys. A fallback of 4000 there would
+ quietly restore the ceiling for exactly those older installs.
+ """
+ from jarvis.dictation import polish
+
+ assert polish._DEFAULT_MAX_INPUT_CHARS == DictationConfig().polish_max_input_chars
+
+ @pytest.mark.parametrize("length", [5_000, 20_000, 120_000])
+ async def test_a_long_transcript_is_not_skipped_as_too_long(
+ self, length: int
+ ) -> None:
+ """No length may resolve to ``skipped_long`` under the default config."""
+ from jarvis.dictation.polish import polish_transcript
+
+ outcome = await polish_transcript(
+ "word " * (length // 5),
+ language="en",
+ cfg=DictationConfig(),
+ )
+ assert outcome.status != "skipped_long"
+ # Whatever else happened, the text is never lost.
+ assert outcome.text