Skip to content

Recent activity filters on created_at instead of updated_at #811

@groksrc

Description

@groksrc

Bug Description

recent-activity can return misleadingly empty or stale results because the date filter is applied to search_index.created_at instead of search_index.updated_at.

This means notes/entities that were created before the requested timeframe but edited/updated inside the timeframe are excluded from recent activity, even though they are the most important results for a “what changed recently?” query.

Steps to Reproduce

  1. Create an entity/note older than the requested recent-activity timeframe.
  2. Update that existing entity/note within the timeframe.
  3. Query recent activity, for example:
bm tool recent-activity --project main --timeframe 14d

or through the v2 memory/recent activity endpoint that uses the search repository date filter.

Expected Behavior

Recent activity should include entities/notes whose updated_at falls within the requested timeframe, even when their created_at is older.

Unranked recent-activity results should be ordered by recency, e.g. newest updated_at first.

Actual Behavior

The search repository filters after_date against search_index.created_at, so updated older notes are omitted.

In unranked recent-activity calls, ordering is also not recency-first; it sorts by a constant/null rank and id before updated recency is considered.

Suspected Root Cause

Both SQLite and Postgres search repositories use created_at for after_date filtering where recent-activity semantics require updated_at:

  • src/basic_memory/repository/sqlite_search_repository.py
  • src/basic_memory/repository/postgres_search_repository.py

The unranked ordering should prefer:

updated_at DESC, id ASC

rather than rank/id ahead of recency.

Suggested Fix

  • Change after_date filters from created_at >= after_date to updated_at >= after_date in both SQLite and Postgres search repositories.
  • For unranked/recent-activity search, order by updated_at DESC, id ASC.
  • Add regression coverage that verifies:
    • an old-created but recently-updated entity is included,
    • a stale entity outside the timeframe is excluded,
    • results are ordered newest updated_at first.

Validation Notes

A local regression test was drafted against tests/api/v2/test_memory_router.py and passed with the repository changes:

uv run pytest tests/api/v2/test_memory_router.py -q
# 13 passed

uv run pytest \
  tests/services/test_search_service.py::test_after_date \
  tests/api/v2/test_search_router.py::test_search_with_date_filter \
  -q
# 2 passed

Environment

  • Repo: basicmachines-co/basic-memory
  • Observed from local checkout on main around commit dd91b490
  • Affected behavior: Basic Memory recent activity / search date filtering

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds investigationIssue needs further investigation and/or refinement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions