Skip to content

fix(memories): list_banks NameError on per-bank capability check - #3381

Merged
nicoloboschi merged 1 commit into
feat/pluggable-memories-providerfrom
fix/list-banks-bank-id-nameerror
Aug 11, 2026
Merged

fix(memories): list_banks NameError on per-bank capability check#3381
nicoloboschi merged 1 commit into
feat/pluggable-memories-providerfrom
fix/list-banks-bank-id-nameerror

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Problem

GET /v1/default/banks returns HTTP 500 for every org:

NameError: name 'bank_id' is not defined
  File ".../engine/retain/bank_utils.py", line 467, in list_banks
    if not _store.writes_memory_rows_in_sql_for(bank_id):

Introduced with per-bank store capabilities (#3350). Inside list_banks, the per-row loop
variable is row["bank_id"] — there is no bare bank_id in scope. Because the argument is
evaluated before the call, this raises for every org on the very first bank, regardless of
what the store's capability would have returned. The line immediately below already uses
row["bank_id"] correctly.

Found live: routing a dev org's memories to an out-of-SQL store (memlake), the bank list 500'd
while single-bank reads worked.

Fix

One line: pass row["bank_id"].

Test

Adds tests/test_list_banks_non_sql_store.py: swaps in a store reporting
writes_memory_rows_in_sql_for -> False and asserts list_banks (a) doesn't raise, (b) consults
the capability + count_memories with the correct per-bank id, and (c) sources fact_count from
the store. That non-SQL branch is exactly where the bug lived and was previously untested.

list_banks consulted the per-bank capability with a bare bank_id that is not
in scope inside the per-row loop (the row's id is row["bank_id"]). Since the
argument is evaluated before the call, this raised
NameError: name 'bank_id' is not defined for every org on the first bank —
GET /banks 500'd outright — regardless of the store's capability.

Introduced with per-bank store capabilities (#3350). Fix uses row["bank_id"];
adds a regression test covering the non-SQL store branch (fact_count sourced
from the store's count_memories), which is where the bug lived.
@nicoloboschi
nicoloboschi merged commit e00ef17 into feat/pluggable-memories-provider Aug 11, 2026
nicoloboschi added a commit that referenced this pull request Aug 11, 2026
Re-applies the per-bank store-capability seam onto current main. The pluggable
memories backend (#2917) is on main, but the per-bank capabilities landed later
on feat/pluggable-memories-provider (#3350, plus fix #3381) while main advanced
~179 commits.

A pluggable memories store may keep memory rows outside SQL and/or own the
document store. The process-level flags writes_memory_rows_in_sql /
owns_document_store gain per-bank forms — writes_memory_rows_in_sql_for(bank_id)
and owns_document_store_for(bank_id), defaulting to the class attrs — and every
bank-scoped call site in memory_engine, consolidation/consolidator, retain/* and
reflect/tools consults the per-bank form. Process-level maintenance gates keep
reading the class attr.

Also two NameError fixes of the same class (a bare bank_id where the in-scope
variable differs): list_banks (row["bank_id"], originally #3381) and get_chunk
(chunk["bank_id"], newly surfaced by pyflakes while rebasing).

Conflict resolution: only consolidation/consolidator.py conflicted — main added
consolidation sites since the branch; all are bank_id-scoped, so all convert to
the per-bank form.

Validation: pyflakes on all changed engine files reports 0 undefined names;
py_compile clean; per-bank + list_banks unit tests included.
nicoloboschi added a commit that referenced this pull request Aug 11, 2026
Re-applies the per-bank store-capability seam onto current main. The pluggable
memories backend (#2917) is on main, but the per-bank capabilities landed later
on feat/pluggable-memories-provider (#3350, plus fix #3381) while main advanced
~179 commits.

A pluggable memories store may keep memory rows outside SQL and/or own the
document store. The process-level flags writes_memory_rows_in_sql /
owns_document_store gain per-bank forms — writes_memory_rows_in_sql_for(bank_id)
and owns_document_store_for(bank_id), defaulting to the class attrs — and every
bank-scoped call site in memory_engine, consolidation/consolidator, retain/* and
reflect/tools consults the per-bank form. Process-level maintenance gates keep
reading the class attr.

Also two NameError fixes of the same class (a bare bank_id where the in-scope
variable differs): list_banks (row["bank_id"], originally #3381) and get_chunk
(chunk["bank_id"], newly surfaced by pyflakes while rebasing).

Conflict resolution: only consolidation/consolidator.py conflicted — main added
consolidation sites since the branch; all are bank_id-scoped, so all convert to
the per-bank form.

Validation: pyflakes on all changed engine files reports 0 undefined names;
py_compile clean; per-bank + list_banks unit tests included.
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.

1 participant