Skip to content

fix(mental-models): align stale checks with refresh tag scope#2804

Open
r266-tech wants to merge 1 commit into
vectorize-io:mainfrom
r266-tech:r266/mental-model-stale-scope-2800
Open

fix(mental-models): align stale checks with refresh tag scope#2804
r266-tech wants to merge 1 commit into
vectorize-io:mainfrom
r266-tech:r266/mental-model-stale-scope-2800

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Summary

  • make mental-model staleness use the same resolved tag filtering as refresh
  • preserve tagged-model all_strict defaults and explicit tags_match behavior
  • support compound trigger.tag_groups when deciding whether a scheduled refresh is stale
  • keep fact_types as an additional scope constraint

Why

The scheduled-refresh gate and the refresh itself currently resolve tag scope differently. Refresh uses _resolve_refresh_tag_filtering(), including tag_groups and the tagged-model all_strict default, while compute_mental_model_is_stale() ignores tag_groups and defaults tagged models to any.

That can mark a model stale because of an out-of-scope memory, spend an unnecessary refresh LLM call, and then refresh against a different (or empty) corpus. This was surfaced while tracing #2800.

Testing

  • uv run pytest tests/test_mental_models.py::TestMentalModelStaleness -q -n 0 (12 passed)
  • uv run ruff format hindsight_api/engine/memory_engine.py tests/test_mental_models.py
  • uv run ruff check hindsight_api/engine/memory_engine.py

The regression coverage includes default all_strict, explicit any, compound tag groups, untagged/global behavior, and flat/group tag filters composed with fact_types, including multi-group near misses.

Related to #2800.

@koriyoshi2041

Copy link
Copy Markdown
Contributor

Verified this at d0fbf450 on macOS / Python 3.11 with the embedded Postgres and local embedding/reranker fixtures:

  • uv run pytest tests/test_mental_models.py::TestMentalModelStaleness -q -n 0 — 12 passed
  • uv run ruff check hindsight_api/engine/memory_engine.py — passed
  • uv run ruff format --check hindsight_api/engine/memory_engine.py tests/test_mental_models.py — passed

The added cases cover the important scope boundaries: default all_strict, explicit any, compound tag_groups, and composition with fact_types. The stale gate now uses the same resolved filtering helpers as refresh, so an out-of-scope memory no longer schedules a refresh against a different corpus.

One scope note for #2800: this fixes stale-check/refresh disagreement, but it intentionally does not change the refresh recall semantics that produced the reporter's zero-result case; the documented tags_match: any or narrower model tags remain the relevant configuration path there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants