Repository navigation
fix(workspace): the mic renders on speech-to-text capability, not key presence (#2695) - #2699
Conversation
… presence (#2695) `stt_available` was `bool(tts_service.is_available())` — a non-empty check on the ElevenLabs key. ElevenLabs permissions are per endpoint, so a key granted Text-to-Speech but not Speech-to-Text rendered a fully working-looking mic that failed on every press with `401 missing_permissions`, while spoken replies played normally on the same instance. Nothing in the UI or the admin panel could say so: `key_configured` was honestly true. New `services/stt_capability_service.py`: one provider probe per key — a one-byte non-audio POST to `/v1/speech-to-text`, which authorises before it validates, so 401/403 is `refused` (with the provider's status word), any other definitive status is `capable`, and a transport error / 5xx is `unknown`. The verdict is cached in Redis under a digest of the key (6h decided / 2min unknown, per-process fallback when Redis is down), so a key change is a miss by construction and the key resolver stays uncached across workers. Reads are bounded (`WAIT_BUDGET_SECONDS`: a slow provider answers `unknown` now and the probe fills the cache in the background) and fail soft: only a definitive refusal hides the mic. `client_portal.service._stt_ready` is now THE gate — the roster card, the agent page and `transcribe_portal_audio` all resolve it, so the control a client sees and the endpoint it calls still cannot disagree (#2212's rule). A real `/stt` 401 stores `refused`, so the reported symptom heals the cache even if the probe never ran. `GET`/`PUT /api/settings/elevenlabs` carry `stt_capability`, `stt_detail` and `stt_checked_at` beside `key_configured`; re-saving a key invalidates its row. Settings → Voice renders "can transcribe" / "cannot transcribe — <reason>" / "transcription not verified" next to the presence badge, via the pure `utils/sttCapability.js` rule. Tests execute every consumer of the verdict (classifier partition, cache keying, bounded wait, roster threading, endpoint refusal, live-refusal feedback, settings state) — none read source text. Fixes #2695 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht
Resolve docs/memory/learnings.md: append-only log, both sides kept (dev's 2026-09-10 entries first, this branch's 2026-09-11 entry after). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht
…ace-model-choice) The spec's own docstring says every box is taken from ONE render, but the icon-button loop re-measured each button after `picker`/`send` were captured, and skipped Send by coordinate (`box.x >= send.x`). The picker is a native <select> sized by its widest option label, which re-measures ~150 ms after paint when the web font lands (211 -> 199 px at 768 on a cold profile); a Send read after that sits left of the earlier `send.x`, is mistaken for an icon button, and fails 'an icon button sits right of the picker'. The race is on dev too — instrumented: dev's picker drifts identically — this branch just loses it more often (its unmocked requests shift the timing). Wait for `document.fonts.ready` and for the picker to hold its box across two consecutive reads before measuring anything, and skip Send by element identity. 3/3 green locally at 375/768/1280 on this branch (was 2 of 5 failing every run). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht
|
merge-train 2026-09-11: not on this train — not a defect in the PR, a sibling collision.
Also flagging ahead of time: Merge |
|
Resolve by running |
|
Resolve by merging |
|
merge-train 2026-09-12: not on this train —
|
|
merge-train 2026-09-13: not on this train. The previous ejection (see the merge-train comment above) has no push after it — the branch head is unchanged — so the same finding stands. Rides the next train once addressed. |
|
merge-train: ejected this run — rides the next train once rebased. The branch conflicts with |
Three conflicts, resolved on their merits rather than by side: * `docs/memory/learnings.md` — both sides appended a new entry at the top of a ledger. Kept BOTH; this is an append-only file and picking a side would delete someone's lesson. * `client_portal/service.py` — `_row_to_card` gained `stt_ready` here and `can_manage_canvases` on dev, in the same signature and the same roster call. Kept both parameters and both kwargs; dev's `may_manage_canvases` comment is carried verbatim. Both call sites (the roster and the #2160 single-agent lookup) now pass both. * `workspace-model-choice.spec.js` — took dev's version WHOLESALE, which makes this branch's `06b86be9` a no-op. Both commits fix the same flake: this branch waited for `document.fonts.ready` and the picker's width to settle, then skipped Send by element identity; dev's #2705 instead takes every box in ONE `page.evaluate` and emulates reduced motion. Dev's is strictly stronger — when all boxes come from one frame, a font re-measure cannot invalidate a relative assertion, so the coordinate Send-skip it keeps is sound again and no wait is needed at all. Two fixes for one race is worse than either; this one loses. The two `--check` whitespace warnings (`hardeningGuide.js`, `test_voice_auth.py`) are pre-existing on origin/dev and arrive with the merge — verified byte-for-byte against `origin/dev` — so they are deliberately left alone rather than swept into an unrelated branch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q19uRCksdn4DiRAJ55rfpZ
|
Rebased onto Three conflicts, each decided on its merits rather than by picking a side:
Dev's is strictly stronger: when all boxes come from one frame, a font re-measure cannot invalidate a relative assertion, so the coordinate Send-skip it keeps is sound again and no wait is needed at all. Two fixes for one race is worse than either, so mine loses. The spec file no longer appears in this PR's diff. Not swept in: Verified after the merge: |
|
merge-train 2026-09-14: not on this train — one finding on the AC the issue underlined, needs a test the suite lacks. Lane B: Cross-worker staleness is still reachable — Fix: make Riders for the same push:
The rest traces end to end and is executed: |
|
merge-train: not on today's train — rides the next one once this is answered. The cross-worker staleness finding from the 2026-09-14 review is unchanged on the branch, and it is the acceptance criterion #2695 states in its own words ("must not reintroduce cross-worker staleness").
The shape of the fix is small — consult Everything else checks out and is worth saying so it does not get re-litigated: the probe is not per-card, it single-flights in-process with a 4s budget, it fails open on transport errors so the mic survives an ElevenLabs outage, presence stays fail-closed, the portal reads the capability off the roster payload rather than the Three riders for the same push: the #2702 is stacked on this branch and is otherwise ready, so it lands right behind you. |
…en it cannot be asked (#2695) Review finding on the AC the issue underlines ("must not reintroduce cross-worker staleness"): `read_cached` fell through to the per-process `_local` on a Redis MISS, not only on a Redis error, while `store` wrote `_local` unconditionally and `invalidate` popped it in the calling worker only. Sequence: admin re-saves the key on worker A → A pops its local, deletes the Redis row, re-probes; if that probe lands `unknown` (2-minute row) or times out, the row expires and worker B serves its stale `refused` from `_local` for the rest of the 6 h — mic withheld on B, offered on A, for the same customer. `read_cached` now treats Redis as authoritative whenever it ANSWERS: a hit is returned, a miss returns None AND evicts this worker's local copy (a corrupt row is a miss too, never a fall-through); `_local` is read only when there is no client or the read raised. `store` still writes both, so the outage fallback stays warm. Tests: the Redis-present branch had zero executing coverage (the autouse fixture stubs `_redis` to None). A dict-backed `_FakeRedis` shared by two module instances (= two uvicorn workers, each with its own `_local`) now pins: TTLs reach the wire and rows decode; an invalidate on A is honoured by B and B's local copy is evicted; the review's 6 h sequence (unknown row expires) is a miss; the local copy is used only while the read raises; a corrupt row is a miss. 4 of the 5 are red against the pre-fix service. Riders from the same review: - `PROBE_TIMEOUT_SECONDS` comment said it sits BELOW `WAIT_BUDGET`; it is 8.0 vs 4.0 and deliberately above — the reader stops at 4 s, the probe runs on to fill the cache. Comment now says why. - "the Workspace mic is hidden" (service log, docstring, Settings hint, backend.md) is browser-dependent: `resolveMicMode` falls back to Web Speech when `serverStt` is false, so a refused key disables server-side dictation and hides the mic only where the browser has no engine. - `stt_capability_service.py` gets its own catalog entry in backend.md instead of riding the `tts_service.py` line. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Addressed in Cross-worker staleness — fixed as proposed. The Redis-present branch now executes. A dict-backed
Mutation-checked: 4 of the 5 are red against the pre-fix service (the TTL/decode one is pure branch coverage and passes on both). 33/33 in Riders, same push:
#2702 is stacked on this branch — it will need a rebase onto the new head. |
…ot a bare sys.modules write (#2695) Both red checks on this PR were the same two lines. `_load_worker` builds a second instance of the module to stand in for a second uvicorn worker. The synthetic name has to be in `sys.modules` while `exec_module` runs — `@dataclass` resolves the class's module BY NAME during the module body — and that was done with a bare assignment plus a `finally` pop: sys.modules[name] = mod try: spec.loader.exec_module(mod) finally: sys.modules.pop(name, None) `tests/lint_sys_modules.py` exists to stop exactly that, because one leaked entry is a module every later test in the session imports instead of the real one. It failed twice over: the `lint (sys.modules pollution check)` job directly, and `regression diff`, whose sole new failure was the pytest mirror of the same rule (`test_lint_sys_modules::test_committed_baseline_matches_current_repo_state`). `monkeypatch.setitem(sys.modules, name, mod)` is the fix the lint names, and it is available here because the only caller is a fixture. It is also stronger than the hand-rolled pair: pytest removes the entry at teardown even if `exec_module` raises before the `finally` is reached. The entry now lives until teardown instead of being popped immediately. Harmless and deliberate — the name is unique per fixture instance and nothing after `exec_module` resolves it. Not a baseline regeneration: the violations are gone, so the committed baseline (0 for this file) is satisfied as written. Verified: `python tests/lint_sys_modules.py` → "no new violations"; the two affected test files pass under all three CI seeds (12345 / 67890 / 99999), 58 tests each. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf
`_row_to_card`'s new `stt_ready` parameter carried `= None`, and an omitted value resolves to the PRE-FIX presence behaviour (`stt_ready if stt_ready is not None else True`). The guard that exists to forbid exactly that — `test_row_to_cards_capability_arguments_have_no_defaults`, whose own docstring says "a default would let a call site keep compiling while silently serving the wrong card" — pinned only `is_platform`, `runtime` and `model_context`, so the fourth capability argument slipped past it. Not a live bug: both production call sites (`get_agent_card`, `get_roster`) pass it explicitly. But a third call site added later would silently un-fix #2695 with the whole suite green, which is the regression the guard was written to make impossible. Drops the default, adds `stt_ready` to the guard's tuple, and passes the neutral `True` at the four older call sites that relied on it — `True` reproduces exactly what the bit meant before the capability probe existed, so no assertion changes meaning. Also corrects the field docstring in `client_portal/models.py`, which still defined `stt_available` as "an ElevenLabs key resolves" — the pre-#2695 gate this PR replaced. Verified: reintroducing the default fails the guard; reverting the card gate to presence-only fails 2 tests in the PR's own suite; 2081 related unit tests pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
merge-train: a commit was pushed to this branch ( Validation result firstREADY — and unusually well covered. Eight backend mutations plus one frontend one, every single hop goes red when reverted:
The CRITICAL that ejected this from the 2026-09-14 train is genuinely closed — restoring the old Redis-miss fall-through turns 4 tests red, proven with a dict-backed fake shared across two module instances. And the mic gate correctly runs through the portal roster payload rather than What was pushed, and why
Not a live bug: both production call sites pass it explicitly. But a third call site added later would silently un-fix #2695 with the suite green — the exact regression the guard was written to make impossible. This was the one finding across the whole batch that could quietly revert its own issue. The commit drops the default, adds Verified: reintroducing the default fails the guard; reverting the card gate to presence-only fails 2 tests in your own suite; 2081 related unit tests pass. Two follow-ups for you (neither blocks the merge)
Minor, not pushed: |
|
vybe
left a comment
There was a problem hiding this comment.
merge-train: validated on #2820 (batch of 6, full suite green). Lane B — /validate-pr + /review; coverage mutation-proven at all 8 backend hops plus the frontend helper. The 2026-09-14 train's CRITICAL is confirmed closed (restoring the Redis-miss fall-through turns 4 tests red). Mic gate correctly runs through the portal roster payload, not the get_current_user-gated feature-flags endpoint, so it avoids the #2128 class. One mechanical commit pushed to this branch (2b966b4) — the no-defaults guard now covers stt_ready; details in the comment above.
… provider-error branch Re-applied after rebasing onto dev: #2699 squash-merged with its own final wording of this bullet, so the branch's copy of the paragraph conflicted and dev's was taken; this is #2696's one addition to it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf
…ue 422 (#2696) (#2702) * fix(workspace): the /stt provider error says why, instead of one opaque 422 (#2696) `transcribe_portal_audio` mapped every non-200 from ElevenLabs onto `422 "Could not transcribe the audio"`. A missing endpoint permission, a rejected key, exhausted credits, a provider rate limit and a rejected audio container all read identically, while the actionable status word sat in a backend WARNING one line above — a live instance cost an operator with container access a full round-trip to answer a question the system already knew. `stt_capability_service.classify_stt_failure()` (pure) maps a provider answer onto a named category with its own client status and sentence: permission / auth / quota 401·402·403 by status word → 503, operator-actionable rate_limit 429 → 429, the existing retry wording audio 400·413·415·422 → 422, "the recording could not be read" provider 5xx → 502, the existing transport wording unknown anything else → 502, still says who failed No arm returns the old string; a test sweeps every status 300-599 to pin that, so an unrecognised provider answer cannot regress to it. The client sentence never carries the provider body. `record_live_failure` keeps the status word + category for THIS key (`stt:last_failure:<digest>`, 24h; per-process fallback) and still feeds #2695's capability cache on a 401/403, so the mic hides on the next load. `GET /api/settings/elevenlabs` (admin-only) carries it as `stt_last_failure`, and Settings -> Voice renders "Last voice-input failure: <why> (HTTP <status> <word>) — <time>" under the capability badge. Fail-soft is unchanged: every branch raises ClientPortalError, never a 500, and the client can always type instead. Fixes #2696 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht * fix(stt): a quota word in the provider's prose is not a quota verdict (#2696) Review finding, reproduced by driving the classifier: a 401 whose body carries no status token was classified `quota` whenever its SENTENCE happened to contain one of `_QUOTA_WORDS`. 401 {"detail":"Invalid API key for your plan"} -> quota 401 {"detail":{"message":"…not valid for this subscription"}} -> quota Both are ordinary auth failures. The client was told "the account is out of credits or not on a plan that allows it" and the admin panel said the same, so an operator whose key simply needed replacing was sent to a billing page. That is worse than the opaque 422 this issue replaces — it is confidently wrong in a direction someone acts on. The cause is that `provider_status_word` collapsed two different things: `det["status"]`/`det["code"]`, which are machine tokens the provider documents, and `det["message"]`/a bare string detail, which is prose written for a human. The comment above `_QUOTA_WORDS` already claimed matching happened on "the status token"; the code matched whatever came back. `provider_status_parts(body) -> (token, prose)` keeps them apart, and `classify_stt_failure` matches ONLY the token. A 401/403 carrying prose alone is now `auth` — the honest reading of "the key was rejected and the provider did not say why". `provider_status_word` stays as the operator-facing display value (token else prose), so nothing is lost from the panel: the prose still shows, it just no longer votes. Verified in the backend image: 38 passing in this suite (5 new table rows + 3 new tests), 66 with #2695's alongside it, and the portal/settings sweep has the identical non-passing set on this branch and on its base — no new failures. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Q19uRCksdn4DiRAJ55rfpZ * docs(architecture): the stt_capability_service bullet carries the #2696 provider-error branch Re-applied after rebasing onto dev: #2699 squash-merged with its own final wording of this bullet, so the branch's copy of the paragraph conflicted and dev's was taken; this is #2696's one addition to it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf * fix(stt): the last-failure row obeys the verdict's cross-worker rule, and invalidate forgets it (#2696) The /review on #2702 (I1): `read_last_failure` fell through to this worker's local copy on a Redis MISS — the pre-#2695-fix shape of `read_cached`, which that PR was held for. After the rebase the two readers in one module disagreed about what a miss means; now they share the rule (Redis answers ⇒ authoritative, miss evicts the local copy; local only when Redis cannot be asked). `invalidate` also drops the key's last-failure row, so re-saving a fixed key does not show the operator the pre-fix failure for 24h beside a fresh `capable` verdict. Mutation: restoring the fallthrough turns the new two-worker test red. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf * merge-train: the operator-facing stt detail is scrubbed of the key (#2702) — mechanical, per the merge-train note on the PR `record_live_failure` stores the provider's status word / prose as the operator `detail` for 24h and the Settings panel renders it. The client half is a constant, so this row is the only place a provider body reaches any surface; the panel promises the key is never echoed, so enforce it here with `scrub_secret` instead of assuming it of the provider. One test drives a body carrying the key and asserts neither the returned failure nor the stored row contains it (mutation: scrub removed → red). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Summary
stt_availableon the Workspace card wasbool(tts_service.is_available())— key presence. ElevenLabs permissions are per endpoint, so a key with Text-to-Speech but no Speech-to-Text rendered a mic that failed on every press with401 missing_permissions, while voice replies played normally.GET /api/settings/elevenlabsreportedkey_configured: true, so the condition was only visible in the container log.What changes
services/stt_capability_service.py(new) — one provider probe per key: a one-byte non-audio POST to/v1/speech-to-text. The provider authorises before it validates, so401/403→refused(with the provider's status word), any other definitive status →capable, transport error / 5xx →unknown. Costs no transcription minutes.stt:capability:<sha256[:16]>; 6h decided / 2min unknown; per-process fallback when Redis is down). A key change is a cache miss by construction — nothing to remember to invalidate, andget_elevenlabs_api_key()stays uncached (the--workers 2rule)._localis read only when Redis cannot be asked (no client / read raised); a Redis MISS returnsNoneand evicts the local copy. Consulting it on a miss let worker B serve arefusedthat worker A'sinvalidatehad deleted, for the rest of the 6h. Proven with a dict-backed fake Redis shared by two module instances (test_invalidate_on_one_worker_is_honoured_by_the_other+ 4 siblings; 4 of 5 red against the pre-fix service).WAIT_BUDGET_SECONDS(4s); past it they getunknownand the probe fills the cache in the background. Only a definitive refusal withholds server-side dictation —resolveMicModethen falls back to the browser's own Web Speech engine where one exists, so the mic is hidden only where there is neither. One awaited O(1) read on the roster, not a fan-out (perf(workspace): the roster's latency floor is its slowest agent — defer briefing hydration off the critical path #2163 guard still green).client_portal.service._stt_readyis read by the roster card, the agent page andtranscribe_portal_audio, so the control a client sees and the endpoint it calls cannot disagree (bug: Workspace voice mode starts the mic and stops instantly, with every failure silent #2212's rule, kept). A real/stt401 storesrefused, so the reported symptom self-heals the cache even if the probe never ran.GET/PUT /api/settings/elevenlabscarrystt_capability/stt_detail/stt_checked_atbesidekey_configured; re-saving a key invalidates its row. Settings → Voice shows can transcribe / cannot transcribe — missing_permissions / transcription not verified next to the presence badge (utils/sttCapability.js, pure + tested).Acceptance criteria
_row_to_card(... stt_ready=False)→stt_available=False;test_card_hides_the_mic_when_the_key_cannot_transcribe,test_roster_threads_the_capability_into_every_cardprobe()/classify_response();test_provider_answers_partition_into_verdictstest_verdict_is_cached_so_the_roster_does_not_probe_per_requesttest_cache_is_keyed_on_the_key_so_a_changed_key_is_a_misstest_probe_that_cannot_complete_is_unknown_never_refused,test_a_slow_probe_answers_unknown_now_and_fills_the_cache_later,test_stt_ready_is_the_capability_verdict_and_fails_softsttCapability.spec.jsGET /api/settings/elevenlabsreflects it —test_settings_state_distinguishes_configured_from_can_transcribeCoverage
Every test executes the changed path (the classifier, the cache,
ensure_capability's bounded wait,get_roster,transcribe_portal_audio, the settings state builder) with the provider stubbed athttpx.AsyncClient. None reads source text.Verification
Docs:
docs/memory/architecture/backend.md(the #2212 sentence now states the capability gate),docs/memory/learnings.mdentry.Fixes #2695
🤖 Generated with Claude Code
https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht