Skip to content

refactor(storage): rename internal validate_namespace -> _is_valid_ns_chars#505

Merged
memtomem merged 2 commits intomainfrom
refactor/disambiguate-storage-validate-namespace
Apr 26, 2026
Merged

refactor(storage): rename internal validate_namespace -> _is_valid_ns_chars#505
memtomem merged 2 commits intomainfrom
refactor/disambiguate-storage-validate-namespace

Conversation

@memtomem
Copy link
Copy Markdown
Owner

Summary

Why

The two functions had:

  • Same name (validate_namespace)
  • Different signatures (bool vs. raises)
  • Different contracts (legacy SQLite charset regex vs. shape-aware caller-input gate with agent-runtime: strict-arity)

Stack traces and grep results pointed at validate_namespace without telling you which one. That ambiguity gets worse as the strict validator becomes the load-bearing public-surface gate (mem_session_start, mem_agent_share, mem_ns_*, …) — it should own the name.

Why this side, not the other

Side Call sites Locked-in by Rename cost
memtomem.constants.validate_namespace 12+ across 6 modules test_validate_namespace_architectural_guard.py AST-matches literal callee name High — guard + every site, immediately on top of #491#503
memtomem.storage.sqlite_namespace.validate_namespace 1 internal (_ensure_valid_namespace) + 0 external (verified by grep) nothing Low — 5-line change, no behavior shift

Test plan

  • uv run ruff check packages/memtomem/src/memtomem/storage/... — clean
  • uv run ruff format --check ... — already formatted
  • uv run pytest -m "not ollama" — 2887 passed
  • CHANGELOG ### Internal entry added under [Unreleased] documenting rename rationale
  • CI green on remote

🤖 Generated with Claude Code

pandas-studio and others added 2 commits April 26, 2026 18:29
…_chars

Disambiguates from the strict caller-input validator in
memtomem.constants introduced by PR #491-#503. The two had the same
name but different signatures and contracts (charset-only bool vs.
shape-aware raises), which made debugging harder when stack traces
or grep results pointed at "validate_namespace" without telling
you which one.

The storage helper has no in-tree callers outside its sibling
_ensure_valid_namespace wrapper. It was nominally exported via
memtomem.storage.sqlite_backend.__all__, but a repo-wide grep
showed zero external imports — internal-only rename, no behavior
change.

Renamed the storage side rather than the constants side because
test_validate_namespace_architectural_guard.py AST-matches the
literal callee name "validate_namespace" against declared surfaces;
renaming that side would mean changing the guard plus 12+ call
sites across 6 modules immediately on top of #491-#503.

Co-Authored-By: Claude <[email protected]>
…nion

Per PR #505 review: the rename docstring on
``_is_valid_ns_chars`` already explains how it relates to the strict
public-surface ``constants.validate_namespace``, but the back-link
was missing. A future reader landing on either function should be
able to find the other without grep — this closes the gap from the
constants side and makes the cross-reference symmetric.

Co-Authored-By: Claude <[email protected]>
@memtomem memtomem merged commit 675babb into main Apr 26, 2026
7 checks passed
@memtomem memtomem deleted the refactor/disambiguate-storage-validate-namespace branch April 26, 2026 09:38
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants