Repository navigation
Closed
Labels
Description
Summary
The src/backend/db/agents.py file has grown to ~1000 lines with 12+ distinct functional areas mixed into a single AgentOperations class. This violates single responsibility principle and makes the codebase harder to navigate and maintain.
Current State
The file contains these unrelated concerns in one class:
| Section | Lines | Purpose |
|---|---|---|
| Ownership Management | 42-113 | Owner registration, access control |
| Sharing Management | 165-296 | Share/unshare agents by email |
| API Key Settings | 298-324 | Platform API key toggle |
| Autonomy Mode | 326-362 | Scheduled task autonomy |
| Resource Limits | 364-414 | Memory/CPU limits |
| Full Capabilities | 416-461 | Container security settings |
| Read-Only Mode | 463-516 | Filesystem protection |
| Parallel Capacity | 518-580 | Max concurrent tasks |
| Execution Timeout | 582-629 | Task timeout settings |
| Batch Metadata | 631-667 | N+1 query optimization |
| Agent Rename | 669-849 | Cross-table rename |
| Avatar Identity | 851-993 | Avatar prompts and defaults |
Proposed Refactor
Split into focused modules under src/backend/db/agent_settings/:
src/backend/db/
├── agents.py # Core ownership + access control only
└── agent_settings/
├── __init__.py # Re-export for backwards compatibility
├── sharing.py # Agent sharing operations
├── resources.py # Memory, CPU, timeout, parallel capacity
├── security.py # Full capabilities, read-only mode
├── autonomy.py # Autonomy mode settings
├── avatar.py # Avatar identity management
└── metadata.py # Batch queries, rename operations
Acceptance Criteria
- Each module handles a single concern
-
AgentOperationsclass remains as facade for backwards compatibility - All existing tests pass without modification
- No API changes - purely internal refactor
- Each new module has clear docstrings
Technical Notes
- The
_user_opsdependency injection pattern should be preserved - Database connection pattern (
get_db_connection()) is consistent across all methods - Some methods have cross-cutting concerns (e.g.,
get_all_agent_metadatajoins multiple tables)
Priority
P1 - Important for maintainability but not blocking any features.
Activity
vybe commentedon Mar 13, 2026
Implemented in this session. Split db/agents.py (~1000 lines) into 6 focused mixin modules under db/agent_settings/. AgentOperations remains as facade class with identical method signatures for full backwards compatibility.
fix(brain-orb): post-voice processing as observable execution + write…