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
- Create an entity/note older than the requested recent-activity timeframe.
- Update that existing entity/note within the timeframe.
- 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:
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
Bug Description
recent-activitycan return misleadingly empty or stale results because the date filter is applied tosearch_index.created_atinstead ofsearch_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
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_atfalls within the requested timeframe, even when theircreated_atis older.Unranked recent-activity results should be ordered by recency, e.g. newest
updated_atfirst.Actual Behavior
The search repository filters
after_dateagainstsearch_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_atforafter_datefiltering where recent-activity semantics requireupdated_at:src/basic_memory/repository/sqlite_search_repository.pysrc/basic_memory/repository/postgres_search_repository.pyThe unranked ordering should prefer:
rather than rank/id ahead of recency.
Suggested Fix
after_datefilters fromcreated_at >= after_datetoupdated_at >= after_datein both SQLite and Postgres search repositories.updated_at DESC, id ASC.updated_atfirst.Validation Notes
A local regression test was drafted against
tests/api/v2/test_memory_router.pyand passed with the repository changes:Environment
basicmachines-co/basic-memorymainaround commitdd91b490