Repository navigation
fix(voice): scrub staged credential values from a voice note before synthesis (#4228) - #4356
AndriiPasternak31 wants to merge 4 commits into
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.
|
Regression details (head_sha: `7b68c8af048b1e7a000d9e103a6a05f6651f51a4`)Seed Backend unit-suite regression diffPer-XML totals
❌ New failures introduced by HEAD (4)Tests failing under HEAD that did not fail under BASE in any seed:
Legend: [F] = assertion failure, [E] = collection or fixture error. Reproduce locally: |
| # 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.
Membership oracle on the global staged-value store. Because _too_long now measures the scrubbed text and quotes its length in guidance (and returns before the effect guard, audit row or rate limit on the in-session path), an agent can submit a cap-length text containing any candidate string and learn from this text is N whether it equals a value staged by any agent (the store is global). Nothing is sent and nothing is audited, so the probe is free and repeatable. Consider judging the cap on the raw text for the guidance/length while still refusing when the scrubbed text exceeds it, or reporting only the cap (not the scrubbed length).
There was a problem hiding this comment.
Fixed in d374dea. The cap judges the text as the agent wrote it and the guidance quotes that length. The scrub runs after the gate. This holds because the spoken placeholder ("redacted", 8 characters, the staging floor) never makes text longer, so a text that fits as written still fits once scrubbed. test_the_cap_answer_does_not_depend_on_what_is_staged asserts the same reason and the same guidance with and without the value staged.
| res = await send(channel, text) | ||
| assert res.reason == "text_too_long", res | ||
| assert res.max_chars == cap | ||
| assert f"this text is {cap + 6}." in res.guidance |
There was a problem hiding this comment.
This assertion pins the scrubbed length in the agent-visible guidance as a contract. From the agent's side its own text is exactly cap characters, yet it is told this text is cap+6, which is both confusing (it may retry the same text) and leaks the length delta of a staged value (see the oracle comment on the service). Suggest asserting on reason/max_chars only, or on the raw length.
There was a problem hiding this comment.
Fixed in d374dea. The test now asserts this text is {len(text)}, the raw length, and the same guidance with and without the value staged.
| 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.
get_staged_values() is synchronous (Redis HGETALL plus one AES-GCM decrypt per staged member, up to the 1000 hard cap) and runs directly on the event loop inside this async def. Every voice call pays it, and it now runs before the cheap unsupported_channel / no_destination / gate refusals. Move the scrub after the cheap structural checks (still before _gate), and/or run it via asyncio.to_thread as the router already does for another_live_destination.
There was a problem hiding this comment.
Fixed in d374dea. The scrub now runs after the channel, destination and gate refusals. test_a_structural_refusal_never_reads_the_store and test_a_gate_refusal_never_reads_the_store count the Redis reads. I did not move it to to_thread, to stay consistent with every other scrub sink, which reads on the loop. If the read cost matters, it should be fixed in get_staged_values for all of them.
| # the cost cap and synthesis — the same order send_message uses. | ||
| _staged = get_staged_values() | ||
| if _staged: | ||
| text = scrub_text(_staged, text) |
There was a problem hiding this comment.
Same blocking get_staged_values() here, ahead of the proactive_channel_unsupported / no_destination refusals that never read text. The scrub only needs to precede preview / _gate; doing it after the channel/recipient checks saves the Redis read + decrypts on refused calls.
There was a problem hiding this comment.
Fixed in d374dea. The read now comes after the proactive_channel_unsupported / no_destination checks and the gate, just before the preview is built.
| # 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() | ||
| if _staged: |
There was a problem hiding this comment.
Spoken marker. scrub_text substitutes ***REDACTED***, which is fine for text but is synthesized and read aloud to the recipient (likely as "asterisk asterisk asterisk redacted ..."). For the audio sink a speech-friendly placeholder (e.g. "[a credential, removed]") would avoid a confusing note; the audit preview can keep the shared marker.
There was a problem hiding this comment.
Fixed in d374dea. Synthesis now receives SPOKEN_PLACEHOLDER ("redacted"). The audit preview keeps ***REDACTED***.
| from services.settings_service import get_proactive_rate_limit | ||
|
|
||
| # ent#279 / #4228: scrub before anything reads the text — the audit preview, | ||
| # the cost cap and synthesis — the same order send_message uses. |
There was a problem hiding this comment.
Reuse: this is now the third verbatim copy of _staged = get_staged_values(); if _staged: text = scrub_text(_staged, text) (also proactive_message_service.send_message). A scrub_staged(text) helper in runtime_secret_scrub would keep the three sinks in lockstep and give the parity guard one symbol to look for.
There was a problem hiding this comment.
Fixed in d374dea. scrub_staged(text, *, marker=...) is in the seam. send_message and both voice sends use it, and the parity guard counts it as a scrub call.
| Raises ``idempotency_service.EffectInProgressError`` when a voice note for this | ||
| turn is already being sent; otherwise never raises (returns a not-delivered | ||
| result the caller reports so the agent replies with text).""" | ||
| # ent#279 / #4228: scrub staged credential values at the TOP, like |
There was a problem hiding this comment.
Altitude: the leak is "agent text reaches TTS unscrubbed", but the fix is placed on two callers rather than at the synthesis chokepoint (tts_service.synthesize_mp3 / synthesize_voice_note). Any other or future caller of TTS with agent-authored text bypasses it. Scrubbing in tts_service (plus here for the audit preview and cap) would close the class rather than these two instances.
There was a problem hiding this comment.
Fixed in d374dea. tts_service.synthesize_mp3, and so synthesize_voice_note, now scrubs for any caller and is pinned in _REQUIRED_SCRUBBERS. test_synthesize_mp3_scrubs_for_a_caller_that_did_not passes it raw text. The voice sends still scrub first, for the audit preview.
| # 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.
Voice-specific gap: _renditions covers raw / JSON-escaped / base64, but a voice note is exactly where an agent reformats a value for speech (spelled out with spaces or dashes, "p-l-u-m ...", NATO letters, case changes). Those renditions pass the scrub and are spoken. At minimum worth a test documenting the limit, or a whitespace/separator-insensitive match for the voice sink.
There was a problem hiding this comment.
Not changed in code; the limit is documented in the flow doc's residuals instead (bd0f0f2, on #4361). A match that ignores separators and case is a new matching design, with its own false-positive risk on every sink. A test asserting that a spelled-out value is spoken would also pin a leak as behaviour. I can file it as its own issue if you want it tracked.
| assert m.spoken == [captured["text"]] | ||
| # Today both pass the text through unchanged (the seam's stage side fails | ||
| # closed, so no NEW value is staged while the store is down). | ||
| assert captured["text"] == text |
There was a problem hiding this comment.
This pins the fail-open passthrough of an already-staged value (the secret is spoken during a Redis outage) as required behaviour. Asserting parity (m.spoken == [captured["text"]]) is enough; asserting == text makes any later hardening (e.g. failing closed for voice, or a cached value set) break the test.
There was a problem hiding this comment.
Fixed in d374dea. The test now asserts only parity with send_message.
…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.
… 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.
|
merge-train 2026-11-10: ejected. Rides the next train once fixed. Every new scrub is covered by tests that run it (each mutation went red), and all 9 of dolho's points are addressed on New guessing oracle on Workspace read-aloud.
The staged store is shared by every agent. This breaks the PR's own rule ("a cost cap judges the text as written") and is the class dolho raised, now reachable by an external principal.
|
|
Landed inside #4361, which was stacked on this branch and has now merged to |
Fixes #4228
Journey Impact: none: a fix inside the two voice sends; no journey's promise changes. A voice note still reaches the person, only a staged credential value in its text is no longer spoken
What
send_messageremoves every staged credential value (the ent#279 scrub seam) from a message before it is delivered. The two voice sends did not.send_voice_reply(a reply into the current conversation) andsend_proactive_voice(the addressed path from #3768, used by schedules, loops and reminders) passed the agent's raw text to text-to-speech. So a credential an agent had fetched could:voice.ogg,message_preview. That row is written on every outcome past the gate: delivery,not_authorized,rate_limited,recipient_not_linkedandsuppressed. The gate's own refusals (unsupported_channel,text_too_long,voice_disabledand the rest) return before any audit row.How
SPOKEN_PLACEHOLDER(redacted), andscrub_texttakes amarker. Synthesis gets the spoken placeholder, because the stored marker***REDACTED***would be read out as punctuation. The addressed audit preview is stored text and keeps***REDACTED***.synthesis_failed. The cap's answer and the length its guidance quotes do not depend on what is staged. That matters because the store is shared by every agent: an answer that changed with the scrub would let an agent test a guessed value against it.tts_service.synthesize_mp3scrubs too. It, andsynthesize_voice_notethrough it, covers any caller of synthesis, including future ones.scrub_staged(text, *, marker=...)is the one-call form.send_messageand both voice sends use it, withsend_message's behaviour unchanged.send_message. The read side of the seam returns nothing while Redis is down, so nothing is scrubbed then. Its stage side fails closed, so no new value is staged during the outage.test_ent279_scrub_parity.py) pins both voice sends andsynthesize_mp3as direct sinks, and countsscrub_stagedas a scrub call. A removed scrub turns CI red.Files:
src/backend/services/voice_reply_service.pysrc/backend/services/tts_service.pysrc/backend/services/runtime_secret_scrub.pysrc/backend/services/proactive_message_service.py(one line)tests/unit/test_4228_voice_reply_scrub.py(new)tests/unit/test_ent279_scrub_parity.pytests/unit/test_ent279_secret_scrub.py(one patch target)docs/memory/feature-flows/runtime-secret-scrub.md: the voice sends andsynthesize_mp3as speech sinks,scrub_staged, the spoken placeholder and the cap ruleValidation
tests/unit/test_4228_voice_reply_scrub.py: 27 passed. The tests call the real service functions with the real seam module, and each value is staged throughstage_secret._FakeEnc), the db reads, the channel providers and synthesis. Thesynthesize_mp3tests fake only the provider's HTTP client.sanitize_textleaves every test text unchanged.redacted.***REDACTED***, both on delivery and on anot_authorizedrefusal.unsupported_channel,proactive_channel_unsupported) and a gate refusal (tts_unavailable) read the store zero times.synthesize_mp3called directly with raw text: the provider request body holdsredacted. With nothing staged it is unchanged.send_messagepass the same text through.tests/lint_sys_modules.pyreports no new violations. Ruff reports no new findings except import-order (I001) on blocks this change touched.Mutation
Each mutation ran against the new file plus the parity guard, and the file was restored after each.
synthesize_mp3synthesize_mp3test and the parity guardUnverified
redactedin context. No real voice note was synthesized.routers/agents.pypassesbody.textstraight to the two service functions, and they are its only callers.runtime-secret-scrub.md.