[loop-generated] [refactor] Split timmy/memory/crud.py — 395 lines, memory operations bottleneck #1430

Closed
opened 2026-03-24 13:05:07 +00:00 by Timmy · 1 comment
Owner

Overview

The timmy/memory/crud.py module (395 lines) handles all memory persistence operations and has grown into a bottleneck. This module manages user memory, session memory, and memory search operations in a single large file.

Current Issues

  • Single responsibility principle violated (CRUD + search + indexing + validation)
  • Performance bottleneck for memory operations
  • Difficult to maintain and test individual components
  • No clear separation between different memory types

Proposed Structure

Split into focused packages:

src/timmy/memory/
├── __init__.py           # Public API
├── crud/
│   ├── __init__.py       # CRUD operations interface  
│   ├── user_memory.py    # User profile memory operations
│   ├── session_memory.py # Session-specific memory operations
│   └── system_memory.py  # System/agent memory operations
├── search/
│   ├── __init__.py       # Search interface
│   ├── indexing.py       # Memory indexing and search
│   └── ranking.py        # Search result ranking
└── validation/
    ├── __init__.py       # Validation interface
    └── memory_schemas.py # Memory data validation

Implementation Requirements

  1. Preserve ALL existing memory functionality
  2. Maintain backward compatibility for all imports
  3. Add comprehensive test coverage for each component
  4. Include performance benchmarks for memory operations
  5. Update all imports throughout codebase

Acceptance Criteria

  • All memory operations continue working without changes to calling code
  • Test coverage maintained at current level or higher
  • Performance benchmarks show no regression (target: ≤5% performance impact)
  • All existing memory APIs preserved
  • Code organization follows established patterns

Files to Modify

  • src/timmy/memory/crud.py (split into package)
  • Update imports in files that use memory operations
  • Add tests for new package structure
## Overview The timmy/memory/crud.py module (395 lines) handles all memory persistence operations and has grown into a bottleneck. This module manages user memory, session memory, and memory search operations in a single large file. ## Current Issues - Single responsibility principle violated (CRUD + search + indexing + validation) - Performance bottleneck for memory operations - Difficult to maintain and test individual components - No clear separation between different memory types ## Proposed Structure Split into focused packages: ``` src/timmy/memory/ ├── __init__.py # Public API ├── crud/ │ ├── __init__.py # CRUD operations interface │ ├── user_memory.py # User profile memory operations │ ├── session_memory.py # Session-specific memory operations │ └── system_memory.py # System/agent memory operations ├── search/ │ ├── __init__.py # Search interface │ ├── indexing.py # Memory indexing and search │ └── ranking.py # Search result ranking └── validation/ ├── __init__.py # Validation interface └── memory_schemas.py # Memory data validation ``` ## Implementation Requirements 1. Preserve ALL existing memory functionality 2. Maintain backward compatibility for all imports 3. Add comprehensive test coverage for each component 4. Include performance benchmarks for memory operations 5. Update all imports throughout codebase ## Acceptance Criteria - [ ] All memory operations continue working without changes to calling code - [ ] Test coverage maintained at current level or higher - [ ] Performance benchmarks show no regression (target: ≤5% performance impact) - [ ] All existing memory APIs preserved - [ ] Code organization follows established patterns ## Files to Modify - `src/timmy/memory/crud.py` (split into package) - Update imports in files that use memory operations - Add tests for new package structure
Author
Owner

IMPLEMENTATION INSTRUCTIONS FOR KIMI

Step-by-Step Implementation Plan

STEP 1: Analysis

  • Read current src/timmy/memory/crud.py thoroughly
  • Identify all functions and their dependencies
  • Map out current imports and usage patterns across codebase

STEP 2: Create Package Structure

mkdir -p src/timmy/memory/crud
mkdir -p src/timmy/memory/search  
mkdir -p src/timmy/memory/validation

STEP 3: Split Functions by Responsibility

  • user_memory.py: Functions handling user profile memory operations
  • session_memory.py: Functions for session-specific memory
  • system_memory.py: Functions for system/agent memory
  • indexing.py: Memory search and indexing operations
  • ranking.py: Search result ranking and filtering
  • memory_schemas.py: Data validation and schema definitions

STEP 4: Maintain Backward Compatibility

  • Keep original crud.py as an import facade initially
  • Import all split functions back into crud.py
  • Ensure all existing imports continue working unchanged

STEP 5: Testing Strategy

  • Run full test suite before and after split
  • Verify no test failures or behavior changes

Critical Requirements

  1. ZERO Breaking Changes: All existing code must continue working
  2. Import Compatibility: All current imports must remain functional
  3. Test Compatibility: All existing tests must continue passing

SUCCESS CRITERIA

All tests pass
All imports work unchanged
Code organization improved

## IMPLEMENTATION INSTRUCTIONS FOR KIMI ### Step-by-Step Implementation Plan **STEP 1: Analysis** - Read current `src/timmy/memory/crud.py` thoroughly - Identify all functions and their dependencies - Map out current imports and usage patterns across codebase **STEP 2: Create Package Structure** ```bash mkdir -p src/timmy/memory/crud mkdir -p src/timmy/memory/search mkdir -p src/timmy/memory/validation ``` **STEP 3: Split Functions by Responsibility** - **user_memory.py**: Functions handling user profile memory operations - **session_memory.py**: Functions for session-specific memory - **system_memory.py**: Functions for system/agent memory - **indexing.py**: Memory search and indexing operations - **ranking.py**: Search result ranking and filtering - **memory_schemas.py**: Data validation and schema definitions **STEP 4: Maintain Backward Compatibility** - Keep original `crud.py` as an import facade initially - Import all split functions back into `crud.py` - Ensure all existing imports continue working unchanged **STEP 5: Testing Strategy** - Run full test suite before and after split - Verify no test failures or behavior changes ### Critical Requirements 1. **ZERO Breaking Changes**: All existing code must continue working 2. **Import Compatibility**: All current imports must remain functional 3. **Test Compatibility**: All existing tests must continue passing ### SUCCESS CRITERIA ✅ All tests pass ✅ All imports work unchanged ✅ Code organization improved
kimi was assigned by Timmy 2026-03-24 13:06:58 +00:00
kimi was unassigned by Timmy 2026-03-24 19:32:12 +00:00
Timmy closed this issue 2026-03-24 21:54:04 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1430