Skip to content

fix(voip): correct /voip/call path param so outbound calls don't 422 (#1069) - #1071

Merged
vybe merged 2 commits into
devfrom
feature/1069-voip-call-path-param
Jun 4, 2026
Merged

vybe merged 2 commits into
devfrom
feature/1069-voip-call-path-param

Conversation

@vybe

@vybe vybe commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • POST /api/agents/{agent_name}/voip/call returned HTTP 422 on every call (REST and the call_user MCP tool). The handler declared its agent path param via the AuthorizedAgent dependency, whose Path() param is named name — but the route template exposes the segment as {agent_name}, so FastAPI required a name path param that no URL could fill (loc: ["path","name"]).
  • Fix: swap the handler to AuthorizedAgentByName (Path param agent_name), matching the route template and the sibling GET/PUT/DELETE /voip handlers. The two dependencies perform an identical access check (db.can_user_access_agent) — only the path-param name differs, so there is no auth boundary change.
  • The MCP client (client.ts) already targets the correct URL, so no MCP-side change is needed (Invariant feat: SMARTS trading pipeline with Telegram notifications and Miro visualization #13 satisfied).

Changes

  • src/backend/routers/voip.py — AuthorizedAgent → AuthorizedAgentByName (import + POST handler); fixed stale {name} → {agent_name} in the module docstring.
  • tests/unit/test_1069_voip_call_path_param.py (new) — loads the real voip router with the real dependencies module (leaf services stubbed) and asserts FastAPI's flattened dependant for the POST route carries agent_name, not name. Plus a dependency-contract test pinning why the fix works.

Root cause

Method Route template Declared path param (pre-fix)
GET/PUT/DELETE /api/agents/{agent_name}/voip {agent_name} agent_name ✅ (OwnedAgentByName)
POST /api/agents/{agent_name}/voip/call {agent_name} name ❌ (AuthorizedAgent)

Test Plan

  • New regression tests pass (4/4) — mutation-verified: reverting to AuthorizedAgent makes the route-level test fail (assert 'agent_name' in {'name'}).
  • Full unit suite: 1953 passed, 0 failed (only the pre-existing fakeredis-missing collection error in test_dispatch_breaker.py, unrelated to this change).
  • The test loader manually saves/restores only the sys.modules keys it touches — does not poison sibling JWT tests (test_voice_auth, test_websocket_auth).

Fixes #1069

🤖 Generated with Claude Code

Eugene Vyborov and others added 2 commits June 4, 2026 15:07
…1069)

POST /api/agents/{agent_name}/voip/call declared its agent path parameter
via the AuthorizedAgent dependency, whose Path() parameter is named `name`.
The route template exposes the segment as `{agent_name}` (matching the
sibling GET/PUT/DELETE /voip handlers, which use the *_by_name dependency
family), so FastAPI derived a required path param `name` that no URL could
populate — every call, REST and the call_user MCP tool that proxies to it,
failed with HTTP 422 (loc: ["path","name"]).

Swap the handler to AuthorizedAgentByName (Path param `agent_name`, an
identical access check — both call db.can_user_access_agent) so the
dependency's path parameter matches the template. No auth boundary change.
The MCP client already targets the correct URL, so no MCP-side change.

Add tests/unit/test_1069_voip_call_path_param.py: loads the real voip
router with the real dependencies module (leaf services stubbed) and
asserts FastAPI's flattened dependant for the POST route carries
`agent_name`, not `name` — mutation-verified against a revert. The loader
manually saves/restores only the sys.modules keys it touches (not
patch.dict, which clears+restores all of sys.modules and would wipe the
real jose/cryptography imports, breaking later JWT tests).

Fixes #1069

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The voip-telephony flow doc named the outbound-trigger dependency as
AuthorizedAgent in two explicit spots (Entry Points + Security table).
PR #1071 swapped the handler to AuthorizedAgentByName to fix the
{agent_name} path-param mismatch, so update the doc to match. The
{name} URL placeholders are doc-wide generic shorthand and are left
as-is. No index change (bug fix, no new flow or name/description change).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vybe
vybe merged commit fd6ba60 into dev Jun 4, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant