Repository navigation
fix(voice): Workspace read-aloud scrubs staged credential values before TTS, and the parity guard pins both remaining speech sinks (#4359) - #4361
Conversation
…ynthesis (#4228) send_message removes every staged credential value (the ent#279 runtime_secret_scrub seam) from a body before it is delivered. Neither voice send did: send_voice_reply (in-session) and send_proactive_voice (the addressed path) handed the agent's raw text to text-to-speech, so a value an agent had fetched could be sent to the TTS provider, spoken to the recipient, and hosted as a WhatsApp voice.ogg. The addressed path also wrote the first 100 characters of the raw text into the append-only audit log as message_preview, on every outcome past the gate: delivery, not_authorized, rate_limited, recipient_not_linked and suppressed. Both functions now scrub at the top, in the same shape send_message uses, so everything downstream reads the scrubbed text: the audit preview, the text_too_long cap (and the length its guidance quotes), and synthesis on every channel. The cap therefore judges what synthesis receives: the 14-char marker can make a text longer or shorter, and judging the raw text would let a note that grew past the cap through to tts_service's own cost cap, which refuses it before any provider call and surfaces it as synthesis_failed. A store outage fails open, as it does for send_message. The ent#279 parity guard now pins both voice sends as direct sinks. The tests use a value no credential pattern matches, so only the staged-value store can catch it.
…re TTS, and the parity guard pins both remaining speech sinks (#4359) synthesize_portal_tts handed the text the Workspace client sent straight to tts_service.synthesize_mp3. The reply was scrubbed when it was saved, but a value staged after that save (or text that never went through a scrubbed save) reached the third-party TTS provider as given. It now removes staged values first, the same way send_message and the voice sends do: fail-open on a store outage, and the shared cost cap inside synthesize_mp3 judges the scrubbed text. The parity guard's _REQUIRED_SCRUBBERS now lists synthesize_portal_tts and direct_voice_service._speak_sentence, so deleting either scrub turns CI red. Its comments no longer carry a count that goes stale with each new sink. Docs: the runtime-secret-scrub flow lists every speech sink, and the seam's "behaviour-neutral for OSS" docstring is corrected — OSS code stages values too. Closes #4359
…d value with edge whitespace still matches (#4359) The Workspace secret field stages a value as typed, edge whitespace included. synthesize_portal_tts stripped the request text first, which broke the exact match when the value sat at the text's edge and sent it raw to the provider. Scrub now runs on the text as sent; the strip and empty check follow. Docs: the sessions bullet moves back above the speech-sink heading, and the flow names services/gemini_voice.py tool results as an uncovered residual instead of implying the speech-sink list is complete.
| ): "Workspace read-aloud text -> TTS provider (#4359)", | ||
| ( | ||
| "services/direct_voice_service.py", | ||
| "_speak_sentence", |
There was a problem hiding this comment.
Direct-voice sink scrubs text that speakable() has already rewritten, so exact-match scrub can miss. _speak_sentence gets its input from sentences(item.text), and sentences() runs speakable() first. _MARKS removes __, ** and ~~ anywhere in a line, and _INLINE_CODE / _URL also change the text. So a staged value such as ab__cd1234efgh turns into abcd1234efgh before scrub_text sees it. The changed value then fails to match, goes to the streaming TTS provider, and goes back to the browser in the spoken frame. A second gap: each item.text is one stream delta, so a value split across two SSE entries never matches in full. This entry pins the function as covered, and the doc says it is, but the guard only checks that a scrub call exists, not what text it runs on. Scrub the raw reply (or the raw delta stream accumulated per turn) before speakable()/sentences().
There was a problem hiding this comment.
Fixed in e0de9e3. speak_execution now scrubs each stream text block and the persisted reply before sentences() / speakable() run. _speak_sentence keeps its scrub as the floor for every line, including the fixed lines and ask lines, and speak_execution is now pinned in _REQUIRED_SCRUBBERS too. New tests drive DirectBridge.speak_execution with plum__orchid__velvet4359. Restoring the old sentences(item.text) turns test_a_streamed_value_that_speakable_would_rewrite_is_never_spoken red.
On a value split across two entries: normalize_stream_entry yields whole content blocks (the text block of a Claude Code assistant message, or a Codex item.completed message), not token deltas. A value spans two items only if the agent itself splits it across two text blocks, so I left that part as is.
| result the caller reports so the agent replies with text).""" | ||
| # ent#279 / #4228: scrub staged credential values at the TOP, like | ||
| # send_message — before the cost cap judges the text and before synthesis. | ||
| _staged = get_staged_values() |
There was a problem hiding this comment.
The listener hears the redaction placeholder read out loud. scrub_text puts in ***REDACTED***, a marker meant for stored text. On a speech sink, ElevenLabs reads it aloud ("asterisk asterisk asterisk redacted", or similar). It can also make the text longer: an 8-char value becomes 14 chars, and each of the 3 renditions matches separately. A note that fits before the scrub can then fail _too_long, and the guidance tells the agent "this text is {len(text)}", a length it never wrote. Use a speech-specific replacement (e.g. "a redacted value"), or leave the value out of the cap count.
There was a problem hiding this comment.
Fixed in d374dea (the voice sends and synthesize_mp3) and e0de9e3 (read-aloud and the direct call). The seam now has SPOKEN_PLACEHOLDER ("redacted"), and scrub_text / scrub_staged take a marker. Every speech sink speaks it. The addressed note's audit preview keeps ***REDACTED***. The placeholder is 8 characters, the staging floor, so a scrub can never make spoken text longer. The cap now judges the text as the agent wrote it, and the guidance quotes that length.
|
|
||
| _staged = get_staged_values() | ||
| if _staged and text: | ||
| text = scrub_text(_staged, text) |
There was a problem hiding this comment.
Client-supplied text plus a global scrub store gives a membership oracle. In this route the client chooses text, and the staged set is global across all agents and owners. A Workspace user can POST a candidate string (for example an old leaked key) and tell whether it is currently staged anywhere on the instance. The answer shows in the audio, and often without listening: when a 14-char placeholder pushes the text over TTS_MAX_CHARS, the status flips between 200 and 422. Low severity, since it confirms a guess rather than revealing a secret, but it is new to this route. One option is to limit the scrub to values staged for this agent, or to a list of replies saved for the session.
There was a problem hiding this comment.
Partly fixed in e0de9e3. The status no longer changes. The cap judges the text as sent, before the scrub, so an over-cap text gets a 422 whether or not the guess is staged (test_the_status_does_not_depend_on_what_is_staged).
The audio still says "redacted" for a staged guess, and I left that for two reasons. First, the same client can already learn it from a voice call: persist_voice_turn scrubs its spoken turns against the same store when it saves them to the thread. Second, the store is global on purpose. It has no per-agent or per-session index, and the seam treats scrubbing a value wherever it appears as always correct, including text relayed between agents. Scoping it would weaken that for every sink. The flow doc now records this as a residual (bd0f0f2).
| # store down get_staged_values() returns [] and the text is spoken as given. | ||
| from services.runtime_secret_scrub import get_staged_values, scrub_text | ||
|
|
||
| _staged = get_staged_values() |
There was a problem hiding this comment.
Duplicated seam boilerplate; the and text guard is redundant. scrub_text already passes falsy text through and returns early on empty values, so if _staged and text: repeats both checks. The same 3-line _staged = get_staged_values(); if _staged: text = scrub_text(_staged, text) block now appears in send_message, both voice sends and here, while direct_voice_service / client_portal/voice.py use the one-line scrub_text(get_staged_values(), x). Add a scrub_staged(text) helper to runtime_secret_scrub and call it in all of them. The parity guard could then match one name.
| - `voice_reply_service.send_voice_reply` (in-session voice note) and | ||
| `send_proactive_voice` (addressed voice note — also before its audit | ||
| `message_preview`) — #4228. | ||
| - `direct_voice_service._speak_sentence` — each sentence of a direct voice call, |
There was a problem hiding this comment.
Altitude: every speech sink is wired by hand, and #4362 is the gap that leaves. Each TTS caller scrubs itself (four sites, plus a residual in gemini_voice). All but Gemini Live go through tts_service.synthesize_mp3 / synthesize_voice_note or a provider's synthesize_stream. Scrubbing there would close the class for future callers too, and would no longer depend on remembering to add each one to _REQUIRED_SCRUBBERS. The callers would keep only the extra scrub needed before audit message_preview and the cap check.
There was a problem hiding this comment.
Fixed in d374dea. tts_service.synthesize_mp3 scrubs before its cap and the request, so it and synthesize_voice_note cover any caller, and it is pinned in _REQUIRED_SCRUBBERS. Callers still scrub first where they also show or store the text (the audit preview, the cap guidance, the spoken frame). I did not wrap the streaming providers' synthesize_stream: its only caller is _speak_sentence, which has to scrub anyway for the spoken frame. Gemini Live stays with #4362.
| # send_message — before the cost cap judges the text and before synthesis. | ||
| _staged = get_staged_values() | ||
| if _staged: | ||
| text = scrub_text(_staged, text) |
There was a problem hiding this comment.
The staged-value read runs before the cheap refusals, on the event loop. get_staged_values() makes a synchronous Redis HGETALL plus one decrypt per staged member. It now runs at the top of both functions, before the unsupported_channel / no_destination checks and before _gate's tts_unavailable / voice_disabled / channel_disabled refusals, which don't need the text. It also blocks the loop inside an async def. Move the scrub to after the channel and destination checks, right before _gate (the cap still sees scrubbed text), or wrap it in asyncio.to_thread. The same applies at L279 and in synthesize_portal_tts, which scrubs before the tts_service.is_available() check.
There was a problem hiding this comment.
Fixed. Both voice sends (d374dea) and read-aloud (e0de9e3) now read the store only after their channel, destination and gate refusals. The tests count Redis reads on each refusal and assert zero. I did not move the read to asyncio.to_thread. Every other scrub sink (send_message, the execution appliers, chat persistence) reads the store on the loop, and this path now reads it only on a call that is about to synthesize. If the read cost matters, the fix belongs in get_staged_values, for every caller.
…b at synthesis (#4228) Review follow-up on the voice-note scrub. - runtime_secret_scrub gains SPOKEN_PLACEHOLDER ("redacted") for text that is read aloud, a marker argument on scrub_text, and scrub_staged(text) for a sink that scrubs one text. The placeholder is no longer than the staging floor, so a scrub never lengthens spoken text. - Both voice sends scrub after the channel, destination and gate refusals, so a refused call never reads the store, and the cap judges the text as the agent wrote it. Its answer and the length it quotes no longer depend on what is staged, which closes a probe of the shared store through that length. The addressed path's audit preview keeps the stored marker. - tts_service.synthesize_mp3 scrubs too, so any caller (and synthesize_voice_note) is covered; it is pinned in the parity guard, which now also counts scrub_staged as a scrub call. - send_message uses scrub_staged; behaviour unchanged.
…to AndriiPasternak31/issue-4359 # Conflicts: # tests/unit/test_ent279_scrub_parity.py
…ud judges the cap as sent (#4359) Review follow-up. - DirectBridge.speak_execution scrubs each stream text block and the persisted reply before sentences() runs speakable(), which drops `__`, `**` and `~~` anywhere, so a value holding one no longer slips past an exact-match scrub on the rewritten text. A stored marker already in the saved reply is said as the spoken placeholder. _speak_sentence keeps its scrub as the floor for every line. speak_execution is pinned in the parity guard. - synthesize_portal_tts runs its refusals before it reads the store, judges the cost cap on the text as the client sent it (the spoken placeholder never lengthens text), and speaks the spoken placeholder. The status a client gets no longer depends on what is staged.
…p as written, and scrub at synthesis (#4359)
… the scrub flow (#4228) The ent#279 flow did not list the two voice sends or synthesize_mp3 as scrub sinks, nor the marker parameter, scrub_staged or the spoken placeholder this PR adds. It now does, with the rule that a cap judges text as written, the positive pins in the parity guard, the reformatted-value residual and the new test file.
…to AndriiPasternak31/issue-4359 # Conflicts: # docs/memory/feature-flows/runtime-secret-scrub.md
… is scrubbed (#4359) "Spoken text is scrubbed of staged secrets" no longer described the order that matters: the stream blocks and the saved reply are scrubbed before speakable() rewrites them, and what is spoken says "redacted". Links the scrub flow's speech-sink section and names the test file.
|
The red regression diff on the previous head (6aa923f) was |
What was wrong
client_portal/service.py::synthesize_portal_ttspassed the text the client sends straight totts_service.synthesize_mp3. The reply was scrubbed when it was saved, but a credential value staged after that save, or text that never went through a scrubbed save, reached the third-party provider as given.direct_voice_service._speak_sentencescrubs before streaming TTS, but_REQUIRED_SCRUBBERSin the parity guard didn't list it, so deleting that scrub turned nothing red. It also scrubbed each sentence afterspeakable()had rewritten it.speakable()drops**,__and~~anywhere, so a value holding one no longer matched and was spoken.What changed
synthesize_portal_ttsremoves staged values before synthesis, after its refusals (empty text, voice unavailable, no voice), so a refused request never reads the store.redacted(from fix(voice): scrub staged credential values from a voice note before synthesis (#4228) #4356), not***REDACTED***, which would be read out as punctuation.DirectBridge.speak_executionscrubs each stream text block and the persisted reply beforesentences()runsspeakable()._speak_sentencekeeps its scrub as the floor for every line, including the fixed lines and ask lines.tests/unit/test_ent279_scrub_parity.py:_REQUIRED_SCRUBBERSnow listssynthesize_portal_tts,_speak_sentenceandspeak_execution. Its comments no longer carry a sink count that goes stale with every addition.runtime-secret-scrub.mdlists every speech sink and explains the placeholder and the cap rule.services/gemini_voice.pytool results (agent text sent to Gemini Live on the non-Workspace voice paths) as an uncovered residual, tracked in fix(voice): Gemini Live voice tool results go to the speech provider without the credential scrub #4362. That one predates this PR and is outside fix(voice): Workspace read-aloud sends unscrubbed text to TTS, and the direct-call scrub is not pinned by the parity guard #4359.services/credential_sink.py).workspace-direct-voice.mdsays where the spoken reply is scrubbed (beforespeakable()) and what is said in its place.Evidence
New
tests/unit/test_4359_portal_tts_scrub.py, 14 tests:synthesize_portal_ttsand the realsynthesize_mp3, so the cost cap is the real one, against the real scrub module over fakeredis, with Redis reads counted. Assertions read the JSON body the provider's HTTP client was sent.DirectBridge.speak_executionandrun_speaker, with the realspeakable()/sentences(), and read what the speech provider and thespokenframes received.redacted__→ never spoken, raw or rewrittenredactedMutation (each restored afterwards):
sentences(item.text), the old shape)__streamed-value testBefore the review round, deleting the scrub in
synthesize_portal_ttsturned 5 tests red and deleting the one in_speak_sentenceturned the guard red, naming it. The guard now also pinsspeak_execution. It requires a scrub call in each pinned function, whichspeak_executionhas twice: removing one leaves the guard green, and the behaviour tests above go red.Validation:
test_3232;:6390and is unrelated to this change.run:block passes locally.tests/lint_sys_modules.pyreports no new violations.Unverified: no call to the real ElevenLabs API, no read-aloud in a live Workspace and no live direct call. The providers are faked one layer below
synthesize_mp3andsynthesize_stream.Closes #4359
Journey Impact: none: a fix inside the Workspace read-aloud request, the direct-call speaker and a test guard; no journey's promise changes. Read-aloud and direct calls still speak the reply, only a staged credential value in it is no longer sent to the TTS provider