Skip to content

refactor: split db/schedules.py and replace 15+ param insert signatures with request objects #1027

Closed

Description

@vybe

Summary

The DB layer has two structural smells flagged critical/high by a /refactor-audit scan (2026-06-02): an oversized domain file (db/schedules.py, 1,987 logical lines with 26 long functions) and several insert/delegating signatures with 15–16 positional parameters that should take a request object.

Context

db/schedules.py is the second-worst hotspot (38 findings). The wide signatures (database.py, db/sessions.py, db/chat.py) make call sites fragile — positional-argument mistakes are easy and invisible in review. Both follow the class-per-domain DB pattern (Invariant #2), so the splits are mechanical.

Findings (critical/high)

Oversized DB file:

  • src/backend/db/schedules.py — 1,987 logical lines, 26 long functions, 6 high-complexity

Too many parameters (≥15):

Params Location
16 src/backend/database.py:982 (delegating method)
16 src/backend/db/sessions.py:138 (session insert)
15 src/backend/database.py:933 (delegating method)
15 src/backend/db/chat.py:106 (chat-message insert)

Acceptance Criteria

  • db/schedules.py split into focused modules (e.g. schedules_crud / schedule_executions / schedule_webhooks) composed per Invariant Feature/gemini runtime support #2
  • The 15–16 param insert paths (db/sessions.py, db/chat.py) take a dataclass/Pydantic request object instead of positional args
  • database.py facade delegating methods updated to match (the facade itself may remain)
  • No schema change; no behavior change — /test-runner green
  • /validate-schema and /validate-architecture pass after the split

Technical Notes

  • Pairs with the orchestration issue: a TaskExecutionRequest model would simplify both execute_task(...) (25 params) and these insert call sites.
  • Keep all DDL in db/schema.py and migrations in db/migrations.py (Invariant Feature/vector log retention #3) — this is a code-organization refactor, not a schema change.
  • db/migrations.py (1,998 lines) and db/schema.py (1,123 lines) are intentionally append-only/constant stores — out of scope here.

Activity

  1. added
    priority-p2
    type-refactor
    on Jun 2, 2026
  2. added
    status-in-progress
    on Jun 3, 2026
  3. self-assigned this
    on Jun 3, 2026
  4. added
    theme-reliability
    on Jun 3, 2026
  5. added
    complexity-high
    status-in-dev
    and removed
    status-in-progress
    on Jun 12, 2026
  6. removed
    status-in-dev
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-highpriority-p2theme-reliabilitytype-refactor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions