Skip to content

loom namespaces-gc matches a prefix as a literal string - #197

Merged
zlareb1 merged 5 commits into
mainfrom
fix/namespaces-gc-prefix-literal
Nov 3, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
fix/namespaces-gc-prefix-literal

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

loom namespaces-gc --prefix and --exclude-prefix now match the prefix as a literal string. Before, an _ in a prefix matched any character, so --prefix lme_run --erase could also erase an idle namespace named lmeXrun....

Why

Failing case: loom namespaces-gc --prefix lme_run --erase with idle, unregistered namespaces lme_run1 and lmeXrun1. Both were candidates, and both were erased.

Pattern: _gc_candidates matched each prefix with namespace LIKE {p:String} and built the pattern as p.replace("%", r"\%") + "%". That escaped % but not _ or \, and _ is a LIKE wildcard. The exclude side had the same flaw, in the safe direction: --exclude-prefix lme_r also fenced off lmeXr.... Loom should delete only what its writer asked to delete, so the include side broke that rule. The default bench prefixes all end in -, so the default scan was not affected.

Fix: both predicates now use startsWith(namespace, {p:String}), which has no metacharacters, and the prefix is bound as given. _gc_memoryless_explicit and loom namespaces-adopt --prefix already used str.startswith, and the namespace_gc worker reads the registry rather than matching a prefix, so nothing else in the command matches with LIKE.

Scope and risk

This changes server/cli/hygiene.py::_gc_candidates only. A prefix now matches only names that start with that exact text. No op, setting or stored data changes.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: a plain revert. Nothing is left behind.

Tests

  • tests/unit/test_namespaces_gc_prefix_sql.py (new) runs the scan on clickhouse-local against the real loom.memory and loom.namespaces tables. On main it failed: --prefix lme_r returned {lme_r1, lmeXr1, lme%r2}, and --exclude-prefix lme_r dropped lmeXr1. With the fix both tests pass.
  • tests/unit/test_erasure_namespace_list.py drops its SQL-text asserts on the prefix predicates, which the new test now covers on real tables.
  • make format-check lint typecheck passed. The unit tests for the erasure, bench-namespace and namespace-gc areas, plus test_public_copy.py, passed (121 tests).

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I checked the failing test against main and every other prefix match in the command.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed. (format, lint, typecheck and the touched areas' unit tests ran locally; the full unit suite runs in CI.)
  • Generated files are regenerated in this PR, not by hand (none affected).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited (none).
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version (none).
  • The frontend builds, if frontend/ changed (unchanged).
  • Docs under docs/ describe the system as it now is.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

🤖 Generated with Claude Code

zlareb1 and others added 5 commits November 3, 2026 09:55
The candidate scan matched --prefix and --exclude-prefix with LIKE and escaped only %, so _ in a prefix was a wildcard: --prefix lme_run --erase also erased an idle namespace named lmeXrun..., and --exclude-prefix fenced off names outside its prefix. The scan now uses startsWith, which has no metacharacters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…rts the clickhouse-local test covers are gone

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…d-namespace test passes no unused exclude

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 77a6c58 into main Nov 3, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/namespaces-gc-prefix-literal branch November 3, 2026 18:01
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
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