BUG-HUNT: [Data Integrity] Database timestamp corruption in SkillService._load_from_db #7057

Open
opened 2026-04-10 07:27:30 +00:00 by HAL9000 · 1 comment
Owner

Bug Report: [Data Integrity] — Database Timestamp Corruption in SkillService

Severity Assessment

  • Impact: Loss of historical creation/modification timestamps, data integrity corruption
  • Likelihood: High - happens on every service startup when database persistence is enabled
  • Priority: High

Location

  • File: src/cleveragents/application/services/skill_service.py
  • Function/Class: SkillService._load_from_db
  • Lines: 145-152

Description

The _load_from_db method incorrectly overwrites actual skill creation and modification timestamps with the current time when loading skills from the database into memory cache. This causes permanent loss of historical timestamp data.

Evidence

In _load_from_db method:

def _load_from_db(self) -> None:
    """Pre-load all skills from the database into the in-memory cache."""
    if self._skill_repo is None:
        return
    try:
        db_skills: list[Skill] = self._skill_repo.list_all()
        now = datetime.now()  # BUG: Uses current time instead of actual timestamps
        for skill in db_skills:
            self._skills[skill.name] = skill
            self._created_at[skill.name] = now    # BUG: Overwrites real creation time
            self._updated_at[skill.name] = now    # BUG: Overwrites real update time
        logger.debug("Loaded %d skills from database", len(db_skills))
    except Exception:
        logger.warning("Failed to load skills from database", exc_info=True)

Expected Behavior

When loading skills from the database, the actual creation and modification timestamps should be preserved and loaded into the in-memory cache.

Actual Behavior

All skills loaded from the database get their timestamps set to the current time (when the service starts), losing the actual creation and modification history.

Suggested Fix

The SkillRepository should expose the actual timestamps, and the service should use them:

def _load_from_db(self) -> None:
    """Pre-load all skills from the database into the in-memory cache."""
    if self._skill_repo is None:
        return
    try:
        # Repository should return skills with timestamp metadata
        db_skills_with_metadata = self._skill_repo.list_all_with_metadata()
        for skill_data in db_skills_with_metadata:
            skill, created_at, updated_at = skill_data
            self._skills[skill.name] = skill
            self._created_at[skill.name] = created_at or datetime.now()
            self._updated_at[skill.name] = updated_at or datetime.now()
        logger.debug("Loaded %d skills from database", len(db_skills_with_metadata))
    except Exception:
        logger.warning("Failed to load skills from database", exc_info=True)

Alternatively, store timestamps in the domain model or use a separate metadata lookup.

Category

data-flow

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be
created for TDD. The test will use tags: @tdd_issue, @tdd_issue_,
and @tdd_expected_fail to prove the bug exists before fixing it.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: bug-hunter
Worker Type: Module Scanner | Tag: [Bug Hunt Cycle 2 Batch 3] | Worker: 18 Skills Framework

## Bug Report: [Data Integrity] — Database Timestamp Corruption in SkillService ### Severity Assessment - **Impact**: Loss of historical creation/modification timestamps, data integrity corruption - **Likelihood**: High - happens on every service startup when database persistence is enabled - **Priority**: **High** ### Location - **File**: `src/cleveragents/application/services/skill_service.py` - **Function/Class**: `SkillService._load_from_db` - **Lines**: 145-152 ### Description The `_load_from_db` method incorrectly overwrites actual skill creation and modification timestamps with the current time when loading skills from the database into memory cache. This causes permanent loss of historical timestamp data. ### Evidence In `_load_from_db` method: ```python def _load_from_db(self) -> None: """Pre-load all skills from the database into the in-memory cache.""" if self._skill_repo is None: return try: db_skills: list[Skill] = self._skill_repo.list_all() now = datetime.now() # BUG: Uses current time instead of actual timestamps for skill in db_skills: self._skills[skill.name] = skill self._created_at[skill.name] = now # BUG: Overwrites real creation time self._updated_at[skill.name] = now # BUG: Overwrites real update time logger.debug("Loaded %d skills from database", len(db_skills)) except Exception: logger.warning("Failed to load skills from database", exc_info=True) ``` ### Expected Behavior When loading skills from the database, the actual creation and modification timestamps should be preserved and loaded into the in-memory cache. ### Actual Behavior All skills loaded from the database get their timestamps set to the current time (when the service starts), losing the actual creation and modification history. ### Suggested Fix The `SkillRepository` should expose the actual timestamps, and the service should use them: ```python def _load_from_db(self) -> None: """Pre-load all skills from the database into the in-memory cache.""" if self._skill_repo is None: return try: # Repository should return skills with timestamp metadata db_skills_with_metadata = self._skill_repo.list_all_with_metadata() for skill_data in db_skills_with_metadata: skill, created_at, updated_at = skill_data self._skills[skill.name] = skill self._created_at[skill.name] = created_at or datetime.now() self._updated_at[skill.name] = updated_at or datetime.now() logger.debug("Loaded %d skills from database", len(db_skills_with_metadata)) except Exception: logger.warning("Failed to load skills from database", exc_info=True) ``` Alternatively, store timestamps in the domain model or use a separate metadata lookup. ### Category data-flow ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter **Worker Type**: Module Scanner | **Tag**: [Bug Hunt Cycle 2 Batch 3] | **Worker**: 18 Skills Framework
Author
Owner

Verified — Data integrity bug: database timestamp corruption in SkillService._load_from_db. MoSCoW: Must-have. Priority: High.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Data integrity bug: database timestamp corruption in SkillService._load_from_db. MoSCoW: Must-have. Priority: High. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#7057
No description provided.