Skip to content

Fix embeddings healthcheck missing-summaries filter - #3686

Merged
blarghmatey merged 1 commit into
mainfrom
fix-missing-summaries-healthcheck-filter
Jul 27, 2026
Merged

Fix embeddings healthcheck missing-summaries filter#3686
blarghmatey merged 1 commit into
mainfrom
fix-missing-summaries-healthcheck-filter

Conversation

@blarghmatey

Copy link
Copy Markdown
Member

What are the relevant tickets?

N/A

Description (What does it do?)

_missing_summaries() in vector_search/tasks.py calls ContentSummarizer.get_unprocessed_content_file_ids(self, overwrite, learning_resource_ids=None, content_file_ids=None), but was passing a LearningResource queryset positionally:

def _missing_summaries():
    summarizer = ContentSummarizer()
    return summarizer.get_unprocessed_content_file_ids(
        LearningResource.objects.filter(require_summaries=True)
        .filter(Q(published=True) | Q(test_mode=True))
        .values_list("id", flat=True)
    )

That queryset landed in the overwrite parameter instead of learning_resource_ids. Since a non-empty queryset is truthy, this silently set overwrite=True, which skips the "only unprocessed" filter (Q(summary="") | Q(flashcards=[])) inside get_unprocessed_content_file_ids. And because learning_resource_ids was never actually passed, the require_summaries=True scoping was lost entirely.

The net effect: the embeddings_healthcheck Sentry alert this feeds (vector_search/tasks.py) was counting every content file across every learning resource — including ones that already have summaries and ones from resources that don't even require summaries — as "missing," rather than just genuinely unprocessed content on resources that require summaries.

Fix: pass both arguments as keywords (overwrite=False, learning_resource_ids=resource_ids). Also added a short-circuit for the case where no learning resources currently require summaries — get_unprocessed_content_file_ids treats an empty learning_resource_ids list the same as None (no restriction) rather than "match nothing," so without the short-circuit that edge case would still fall through to scanning every resource.

This was flagged by Sentry's bug-prediction bot as a review comment on #3683 — it's a pre-existing bug (introduced in commit 3ba27bdc4e, 2025-11-07) unrelated to that PR's changes, so it's being fixed here separately.

Screenshots (if appropriate):

N/A - no UI changes

How can this be tested?

Added two regression tests to vector_search/tasks_test.py:

  • test_embeddings_healthcheck_excludes_already_summarized — a content file that already has a summary and flashcards should not be counted as missing.
  • test_embeddings_healthcheck_summaries_scoped_to_require_summaries — a content file belonging to a learning resource with require_summaries=False should not be counted as missing.

Both fail against the old code (the first because overwrite ends up truthy, the second because learning_resource_ids is never applied) and pass with the fix.

Ran the full vector_search/tasks_test.py suite: docker compose run --rm web uv run pytest vector_search/tasks_test.py -q — 45 passed, including the existing test_embeddings_healthcheck_missing_summaries test.

ruff check --select F401,F821 and ruff format --diff are clean on both touched files.

Additional Context

No behavior change outside of _missing_summaries() / the embeddings_healthcheck task — this only affects what gets reported to Sentry, not any content-processing task itself.

…ries

get_unprocessed_content_file_ids(self, overwrite, learning_resource_ids=None,
content_file_ids=None) was being called with a queryset passed positionally,
which landed in the `overwrite` parameter instead of `learning_resource_ids`.
Because a non-empty queryset is truthy, this silently set overwrite=True,
skipping the "only unprocessed" filter, and `learning_resource_ids` was never
passed at all, so the require_summaries=True scoping was lost entirely. The
embeddings_healthcheck Sentry alert this feeds was therefore counting
already-summarized content files across every learning resource, not just
missing summaries for resources that require them.

Pass both arguments as keywords, and short-circuit when no learning
resources currently require summaries, since
get_unprocessed_content_file_ids treats an empty learning_resource_ids list
the same as None (no restriction) rather than "match nothing".

Flagged by Sentry's bug-prediction bot on #3683 as a
pre-existing issue unrelated to that PR's changes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 27, 2026 18:51
@github-actions

Copy link
Copy Markdown

OpenAPI Changes

No changes detected

View full changelog

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug in the embeddings_healthcheck path where _missing_summaries() was passing a LearningResource queryset positionally into ContentSummarizer.get_unprocessed_content_file_ids, causing incorrect scoping and effectively treating all content files as “missing summaries” in Sentry.

Changes:

  • Pass overwrite=False and learning_resource_ids=... as keyword arguments to get_unprocessed_content_file_ids to avoid positional mis-binding.
  • Add a short-circuit in _missing_summaries() to return [] when no learning resources require summaries (preventing an unintended “scan everything” behavior).
  • Add regression tests ensuring the healthcheck excludes already-summarized content files and is scoped to require_summaries=True resources.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
vector_search/tasks.py Fixes _missing_summaries() argument binding and adds an empty-scope short-circuit to keep the healthcheck correctly scoped.
vector_search/tasks_test.py Adds regression coverage for the corrected scoping and overwrite behavior in embeddings_healthcheck.

@shanbady
shanbady self-requested a review July 27, 2026 19:01

@shanbady shanbady left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@blarghmatey
blarghmatey merged commit c9815ec into main Jul 27, 2026
15 checks passed
@blarghmatey
blarghmatey deleted the fix-missing-summaries-healthcheck-filter branch July 27, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants