Skip to content

refactor: move three 300-line router handlers into services — update_setting, voice_websocket, trigger_webhook #4458

Open

Description

@vybe

Summary

Three router handlers are each over 300 lines and hold the business logic of their feature. Move that logic into services so the routers return to request parsing, auth and response shaping.

Context

Found by the /refactor-audit run of 2026-11-10. Invariant #1 in docs/memory/architecture.md (Router → Service → DB) says routers hold no business logic.

Handler Lines Complexity Location
update_setting 454 36 src/backend/routers/settings/generic.py
voice_websocket 312 34 src/backend/routers/voice.py
trigger_webhook 304 40 src/backend/routers/webhooks.py

The same audit shows the pattern works: public_chat and deploy_system were 268 and 187 lines in June, were moved into services, and neither router handler is flagged now.

update_setting is the generic PUT /api/settings/{key} catch-all. Its length comes from per-key validation and side effects accumulated in one function.

#4418 adds an import contract for the layering. That catches a router importing db/ directly; it does not catch logic written inline in a handler, which is what these three are.

Acceptance Criteria

  • update_setting: per-key validation and side effects live in the settings service layer, dispatched by key; the handler is under 50 lines
  • trigger_webhook: token resolution, idempotency derivation and dispatch live in a service; the handler is under 50 lines
  • voice_websocket: session setup and the relay loop live in a service; the handler keeps only the socket accept, auth and teardown
  • Route paths, registration order, status codes and response bodies are unchanged (Invariant fix: add missing logging_config.py to backend Dockerfile #4; the settings /{key} catch-all stays last, pinned by tests/unit/test_1028_settings_package.py)
  • The db.set_setting sink guard for credential-shaped keys still rejects with 422 on every path through the moved code
  • trigger_webhook still accepts and auto-derives Idempotency-Key (Invariant Unified Executions Dashboard (EXEC-022) #18)
  • Existing tests for the three endpoints pass without loosening an assertion

Technical Notes

Activity

  1. added
    priority-p3
    type-refactor
    theme-devex
    complexity-medium
    status-ready
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumpriority-p3status-readytheme-devextype-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions