Skip to content

fix: remove unreachable created_at backfill in update_task_status #208

@bsbodden

Description

@bsbodden

Problem

update_task_status in agent_memory_server/tasks.py contains dead code at lines 96-97:

# Ensure created_at is always set
if task.created_at is None:
    task.created_at = datetime.now(UTC)

This code is unreachable because Task.created_at is defined as datetime (non-optional) with default_factory=lambda: datetime.now(UTC). If a task somehow has created_at: null in Redis, Task.model_validate_json() raises a ValidationError before this backfill code can execute, making the task permanently unrecoverable.

Root Cause

The Task model field created_at: datetime does not accept None. The Pydantic validator rejects null values before the Python code has a chance to backfill.

Proposed Fix

  1. Remove the dead backfill code from update_task_status
  2. Make created_at explicitly Optional[datetime] with a default_factory, OR keep it non-optional (preferred — created_at should always exist on valid tasks)

Since create_task always produces tasks with created_at set (via default_factory), the simplest fix is to remove the dead code.

Related

Part of #190 (Summary Views and Tasks)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions