Skip to content

perf(kb): an idle backend sweeps every Redis fact about every 3 s (SCAN + HGETALL ×3,742 per 30 s) — keyword fallback with an unidentified caller #19726

Open

Description

@mrveiss

Problem

While the system is idle, the backend sweeps every knowledge fact in Redis roughly every 3 seconds. This is a constant load that nobody asked for.

A 30 s Redis MONITOR sample on 2026-10-26 recorded 10 full sweeps of db 1, about one every 3 s:

  • 137 × SCAN MATCH fact:* COUNT 100
  • 138 × MULTI/EXEC
  • 3,742 × HGETALL fact:<id>

That is all 514 facts, roughly 7 times per sweep. Everything came from a single backend connection. There were no writes, and no knowledge HTTP requests at the same time.

What is known

  • The pattern matches knowledge/search_components/keyword_search.py:212 → process_keyword_batch (:171-174): a SCAN with COUNT 100, then one pipelined HGETALL per page.
  • At the same time, embeddings fail on this node (bug(kb): embedding model resolves to a chat model (phi3:mini) — vectorization fails with 'server does not support embeddings', facts stored unsearchable #18834), and the backend logs "Vector store not available, using basic search fallback". So semantic retrieval falls back to this full keyword scan, and does so on every query.
  • The caller that repeats every ~3 s has not been identified. The background vectorizer runs every 300 s (background_vectorization.py:42), so it does not fit. Candidates to rule in or out: a UI poll, a chat or agent loop issuing searches, and a health or metrics probe.

Acceptance criteria

  • The ~3 s caller is identified, with file:line, and recorded here.
  • An idle backend issues no fact:* sweep. A test or probe pins this.
  • Keyword fallback is bounded (an index or a cap) rather than a full HGETALL scan per query. The bound comes from config.
  • Host: a 30 s MONITOR sample on an idle node shows no HGETALL fact:* stream.

Activity

  1. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Measured on 2026-11-02 on the dev host, read-only.

    The stream is live and heavier than filed: over 30 s, HGETALL rose by 39,572, about 1,300 a second, with 3,113 keys in db 1.

    Where it came from now: the connections belong to the man-page indexer (index_all_man_pages.py, started by the tasks.refresh_system_knowledge Celery task), not the backend. It had run for over 8 hours at about 93% CPU, and 20 stack samples of the backend process showed no KB code. Stack samples of the indexer show recompute_corpus_stats (keyword_search.py:124).

    Mechanism: _schedule_bm25_refresh (knowledge/facts.py:384) starts a new full recompute for each stored fact, without waiting for earlier ones.

    Not established: whether the 2026-10-26 sample had this same cause. That sample recorded no writes and one connection; this one has several connections, and I didn't count writes. So the first criterion stays open until a sample with no indexer running is clean.

    I didn't stop the running job. The fix is in the linked PR.

  2. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    The fix is in #20672.

  3. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Re-measured the same day, after the indexer had ended: HGETALL rose by 0 over 20 s, with the backend still running and 3,113 keys in db 1. So today's stream was the indexer, and the backend alone produces none of it right now.

    That is one 20 s sample, not the criterion's 30 s MONITOR, and it was taken before the fix is on any host. A sample after the next update still has to show the same. Whether the 2026-10-26 sample had this cause is still not established.

  4. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Verified against main at the merge train (PR #20707), merge 1416e3d202. Only boxes with code evidence are ticked.

    AC Evidence
    The ~3 s caller is identified, with file:line, and recorded here. NOT delivered. Not ticked. Comments on the issue trace a 2026-11-02 stream to the man-page indexer via _schedule_bm25_refresh (knowledge/facts.py, ~384) into recompute_corpus_stats (keyword_search.py:124), but the issue states it is not established that the 2026-10-26 ~3 s sample had that cause.
    An idle backend issues no fact:* sweep. A test or probe pins this. delivered. KeywordSearcher.request_refresh/_run_refreshes (keyword_search.py:163-185) recompute only when a write asked; test test_no_write_means_no_sweep in keyword_refresh_19726_test.py:46. Scope: the recompute path, not a search by a user.
    Keyword fallback is bounded (an index or a cap) rather than a full HGETALL scan per query. The bound comes from config. delivered. KEYWORD_SEARCH_MAX_SCAN = env_int_clamped("AUTOBOT_KB_KEYWORD_SEARCH_MAX_SCAN", 10000, ...) (keyword_search.py:32), applied at search (:255); test test_keyword_search_stops_at_the_configured_cap; env registered in autobot_shared/env_registry_knowledge.py. Note the default 10,000 exceeds the reported fact count.
    Host: a 30 s MONITOR sample on an idle node shows no HGETALL fact:* stream. NOT delivered. Not ticked: a host criterion, needs a 30 s MONITOR sample on an idle node after an update; a merge is not host evidence.
  5. mrveiss commented on Nov 3, 2026

    @mrveiss
    OwnerAuthor

    Host check on 2026-11-03 at 08:08 Riga, read-only, on the local node at 1416e3d202, which includes #20672. The deployed keyword_search.py and facts.py are byte-identical to that commit, the backend restarted at 07:36, and no man-page indexer is running.

    A 30 s MONITOR sample: 686 commands, 0 HGETALL fact:* and 0 SCAN over fact:*. The rest is SCAN over other keys (412), PING, queue pops and GET, and the backend log shows only health and metrics requests in that time. The host criterion is ticked.

    Still open: the first criterion. Today's caller was the indexer (recompute_corpus_stats, started per stored fact from knowledge/facts.py _schedule_bm25_refresh), but whether the 2026-10-26 sample had the same cause is still not established.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't workingperformancephase:M1.8Knowledge base: upload, web sources and chat retrieval work end to endpriority: high

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions