Repository navigation
feat(voice): proactive voice notes — address send_voice_reply by role or email (ent#700) - #3768
Conversation
… or email send_voice_reply could only speak into the conversation an execution row was stamped with, so a scheduled run got `not_a_channel_turn` while send_message to the same person delivered. The tool now also takes an address — `to` (a role, the ent#606 shape) or deprecated `recipient_email` — plus `channel` (telegram | whatsapp), so any run can speak. - Addressed sends pass the proactive-text gates: can_agent_message_email consent, the per-recipient hourly rate limit (one budget across text and voice), and a PROACTIVE_MESSAGE audit row (modality: voice). - Recipient resolution is one service rule shared with send_message: role_addressing.resolve_single_recipient (extracted from routers/messages.py, Invariant #1); role refusals name the role, never a person. - Effect dedup on the resolved (recipient, channel). Pre-send refusals and transient delivery failures (send_failed, delivery_error — both paths) release the claim so a retry in the same run tries again; config misses stay recorded. - Over-TTS_MAX_CHARS text is refused before synthesis as `text_too_long` + `max_chars` (was indistinguishable from synthesis_failed); an unaddressed non-channel call keeps `not_a_channel_turn` but now carries guidance. - ProactiveMessageService gate helpers are public: check_rate_limit, increment_rate_limit, audit_send. - Slack proactive voice returns `proactive_channel_unsupported` (deferred). Mutation-checked: removing the consent check, the rate-limit check, the claim release (pre-send and transient, each path), the router's addressed branch, the `to` branch, or the several-people refusal each turns tests in tests/unit/test_ent700_proactive_voice.py red. Related: Abilityai/trinity-enterprise#700 Partially addresses #2999 (AC 3, AC 5) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Resolve by running |
|
Resolve by merging |
obasilakis
left a comment
There was a problem hiding this comment.
Requesting changes. The head is 166 commits behind dev and conflicts in src/backend/routers/messages.py and tests/registry.json; two of the findings below turn CI red after the merge.
- High
src/backend/services/role_addressing.py:178-212,src/backend/routers/messages.py:130:devadded the ent#904 rule (nobody holdsprimary→ fall back to the agent's owner, or refuse with a specific message when the owner has no email).resolve_single_recipientlacks it, so taking the PR side of the conflict removes it fromsend_messageandtest_ent904_primary_unseated.pyfails. Resolved correctly, voice still refusesto=primaryasrole_unassignedon a fresh install while text reaches the owner, which is the operator daily-brief case. Move the fallback intoresolve_single_recipientso both paths get it. - High
src/backend/services/proactive_message_service.py:112and the other two renames:dev'stests/unit/test_3746_telegram_long_replies.py:233-236monkeypatches_check_rate_limit,_increment_rate_limitand_audit_send.setattrraises on the missing attributes after merge, with no textual conflict to flag it. Update that test or keep private aliases. - Medium
src/backend/services/voice_reply_service.py:68:send_failedreleases the claim, and the rate counter increments only on delivery. WhatsApp outside Twilio's 24h window (63016) and a Telegram user who blocked the bot fail every time, so each retry pays for a new ElevenLabs synthesis and a hosted media file with no budget cap. The in-session path also changes to release onsend_failed, which AC 4 says stays unchanged. Release only ondelivery_error, or count failed sends against the budget; keep the in-session behaviour; add guidance for the 24h-window failure. - Medium
src/backend/services/voice_reply_service.py:249: dedup is keyed per execution, and a scheduler retry creates a new execution row (retry_of_execution_id). A brief that spoke and then failed later speaks again on retry, so AC 3 is open. Acceptidempotency_key/idempotency_ttlon the addressed path as text does (ent#665), or document the limit in FR-10. - Low
src/backend/routers/agents.py:1612: thenot_a_channel_turnguidance points agents atrecipient_email. Nameto(primary) first and assert ontointest_2157/test_ent700. - Low
src/mcp-server/src/tools/voice.ts:109:channeldescription says "Requiresrecipient_email"; should read "Requirestoorrecipient_email". - Low
tests/unit/test_ent700_proactive_voice.py:79-140: claim release is tested against a fake_Guard. Add one test on the realeffect_guardwith the SQLite idempotency store for the rate-limit release and the replay.
Checked and fine: an agent key speaks only as itself and keeps ent#629 reach; the consent check runs before anything email-dependent; role refusals never name the resolved email; public docs carry ticket references only.
Keeps dev's can_open_agent / resolve_role_id_for_ask beside the extracted resolver, and moves the ent#904 owner stand-in from routers/messages.py into role_addressing.resolve_single_recipient, so send_message keeps it and send_voice_reply gains it (review item 1). dev's #3746 test now patches the public proactive helpers: its setattr on the private names would raise after the merge, with no textual conflict to flag it (review item 2). tests/registry.json rebuilt from the merge stages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A provider refusal (send_failed) stays recorded on the addressed path and says why with guidance, naming WhatsApp's 24-hour window; only delivery_error releases the claim, so a retry never pays for a synthesis that will be refused. - The in-session path records every delivery outcome again, as it did before (AC 4). - The addressed path takes idempotency_key / idempotency_ttl (ent#665) because a scheduler retry is a new execution row. A suppressed note answers delivered=true, sent=false; only a delivered note spends the key; voice keys do not collide with text keys. Model, route, service and MCP tool. - not_a_channel_turn guidance names `to` first; the channel description names both address forms. - Tests: the owner stand-in by voice, and claim release, replay and key behaviour on the real effect_guard and idempotency store. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e (ent#700) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Addressed the requested changes from the 2026-10-28 review. Head is
Docs are in Results: Tier 1 passed at this head, including Choices to check
Limits on item 3
Outside this review, not changed: Please re-review. |
Dismissed at the operator's instruction to merge. Items 1-7 are addressed at 92a7155; see the item-by-item comment on this PR. Post-merge review is welcome.
Summary
Gives
send_voice_replyan addressing surface so a run with no inbound conversation (a schedule, a loop, a reminder, an agent-to-agent task) can speak. This is shape (a) of the issue. Before this change a scheduled run gotnot_a_channel_turnfromsend_voice_reply, whilesend_messagefrom the same run reached the same person on the same channel.Fixes abilityai/trinity-enterprise#700
Partially addresses #2999 (AC 3, AC 5)
Merge timing: after 1.0.0 (not release-critical).
Behaviour
Addressing.
send_voice_replynow takes an optional address pluschannel(telegram|whatsapp). The address is either:to, a role (primary|approver|viewer, the ent#606 shape), orrecipient_email(deprecated; logged when an agent key uses it).Use one or the other, never both. Without an address, the in-session reply is unchanged (FR-1..FR-9).
Same gates as proactive text. An addressed note must pass:
db.can_agent_message_emailconsent;send_message, so it is not a cheaper way around the limit;PROACTIVE_MESSAGEaudit row withmodality: voice.The agent-level and per-channel voice flags still apply.
One resolver.
role_addressing.resolve_single_recipientis extracted fromrouters/messages.py(Invariant Fix: Add missing Docker labels to system agent container #1), and both routes use it. A role that several people fill, or that nobody fills, is refused by role and never names a person. The voice route returns these refusals fail-soft withguidance.Destination. The recipient's verified chat link, found with the same lookup
send_messageuses. Never the execution row.Dedup (feat: effect-scoped idempotency keys for outbound side effects #1084).
(recipient email, channel).rate_limited,recipient_not_linked) anddelivery_errorrelease the claim on the addressed path, so a retry in the same run tries again.send_failed) and configuration misses (no_binding, …) stay recorded: a retry fails the same way and would pay for another synthesis.send_failedcarriesguidance, naming WhatsApp's 24-hour window.Idempotency key (ent#665). A scheduler retry is a new execution row, so the addressed path also takes
idempotency_key/idempotency_ttl: one note per (agent, recipient, key) across runs. A suppressed call answersdelivered: true, sent: false, so the agent does not repeat it in text. Only a delivered note spends the key, and voice keys do not collide with text keys.Owner stand-in (ent#904).
primarywith no seat reaches the agent's owner, now inresolve_single_recipient, so text and voice share it.resolveis unchanged, so asks and gate approvals keep their rule.Named refusals with
guidance(bug(voice): agents tell Workspace clients the surface is text-only — portal TTS is never advertised, and the channel/portal voice gates disagree #2157 pattern):not_authorized,rate_limited,recipient_not_linked,proactive_channel_unsupported(Slack);role_unassigned/role_resolves_to_several;not_a_channel_turn, now with guidance on how to address someone (bug(voice): send_voice_reply cannot deliver from a scheduled execution — the destination is read only from an inbound channel stamp, and the refusal names the trigger instead of the constraint #2999 AC 3).Cost cap. Text over
TTS_MAX_CHARSis refused before synthesis astext_too_longwithmax_chars, on both paths. It used to look the same assynthesis_failed(bug(voice): send_voice_reply cannot deliver from a scheduled execution — the destination is read only from an inbound channel stamp, and the refusal names the trigger instead of the constraint #2999 AC 5). Callers keep notes short; there is no chunked multi-note send.Public helpers. The
ProactiveMessageServicegate helpers are now public:check_rate_limit,increment_rate_limit,audit_send. The private names are gone and every reference is updated.MCP tool.
voice.tsgainsto,recipient_emailandchannel(Invariant feat: SMARTS trading pipeline with Telegram notifications and Miro visualization #13). The tool refuses a half or double address locally and passesguidanceandmax_charsthrough.Deferred (follow-ups filed)
Docs
docs/memory/requirements/public-access.md)architecture/{api-endpoints,mcp-server,backend}.md: which triggers can deliver voiceuser-docs/advanced/voice-replies.mdTest evidence
New file
tests/unit/test_ent700_proactive_voice.py(58 tests on SQLite), including claim release, replay and key behaviour on the realeffect_guardand idempotency store.Mutation checks. Each change was made in a scratch copy, the named tests went red, and the file was restored byte-identical:
totest_ent606_role_addressing.py)Updated tests:
test_2157_portal_narration.py: the no-guidance assertion is reversed per bug(voice): send_voice_reply cannot deliver from a scheduled execution — the destination is read only from an inbound channel stamp, and the refusal names the trigger instead of the constraint #2999 AC 3. It now checks the guidance mentions addressing and never the speaker control.Affected unit files after merging
dev(voice, proactive, role addressing, idempotency;-n 8): 2387 passed, 5 skipped, 1 failed. The failure istest_1310_auth_consolidation.py::test_admin_sites_admit_admin[sqlite-avatar.generate_default_avatars], the read-only/datafailure already noted here as environmental; it was not re-run ondevthis time.Tier 1 at
92a715527: the required checks,pytest (head, seed 12345)andregression diffall passed.MCP:
npm test1151 pass, 0 fail (includessrc/tools/voice.test.ts);tsc --noEmitis clean.Not run: live-stack tests.
🤖 Generated with Claude Code