Skip to content

An entity name longer than 256 characters once normalised is no entity, and a point write refuses one - #366

Merged
zlareb1 merged 9 commits into
mainfrom
fix/entity-cap-test
Nov 7, 2026
Merged

zlareb1 merged 9 commits into
mainfrom
fix/entity-cap-test

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 7, 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):

An entity name longer than 256 characters once normalised (NFKC turns a fi ligature into fi) is treated like one longer than 256 as written: it is no entity, and a point write's fact subject or object of that kind is refused with a message that says so.

Why

canonical_entity checked MAX_ENTITY_CHARS (256) on the raw text only. NFKC can lengthen text: 256 fi ligatures (U+FB01) normalise to 512 characters of fi. That text was returned and stored, and a second pass (a query seed, or the existing row a triple repair canonicalises again) returned '', against the function's documented idempotence and the cap's comment that it is a wire bound.

One predicate, fits_entity, now applies the cap to the raw and the normalised text, and three places use it:

  • canonical_entity: text past the cap once normalised is no entity.
  • names_only (facet triples and a search's entity_filter): it kept a name by its raw length, so 129 ligatures passed and were stored as a 258-character facet node, or bound as a filter, that a second pass turns into '', so no seed can reach it. Such a name is now left out, as a name past 256 as written already was, and the search falls back to the parsed entities.
  • The point-write fact validator (memory.set, memory.update, memory.update_by_id relations): a subject or object of 200 ligatures was accepted and stored as a 400-character entity. It is now refused with '…' is longer than 256 characters once normalised, checked before the canonical-length check, whose "stored as ''" message would name the wrong cause.

The test that guarded this area, test_normalising_a_huge_entity_is_linear, fed 20 000 to 32 000 characters, all over the cap, so it compared '' with ''. It is replaced by tests that reach the normaliser. Input is capped at 256 characters and the lines-executed counter cannot see regex backtracking, so no timing bound remains.

Scope and risk

server/memory/domain/graph_quality.py (canonical_entity, names_only, the new fits_entity), the fact validator in server/memory/api/models_crud.py, and docs/features/entity-graph.md. Only names that grow past 256 characters under NFKC are affected.

Compatibility, rollout and rollback

  • Wire: a point write whose relations subject or object is at most 256 characters but longer once normalised is now refused (it was accepted and stored unnormalised). During a rolling upgrade build N-1 still accepts it; nothing stored is changed or deleted.
  • Operator steps: none. Rollback: revert.

Tests

  • tests/unit/test_memory_entities_canonical.py: 256 ligatures and 129 ligatures are no entity; 128 ligatures, İ × 200 and the other lengthening cases are non-empty fixed points; a 256-character name in each of the old timing shapes is a non-empty fixed point. The ligature cases fail on main.
  • tests/unit/test_code_facets.py: a facet of 129 ligatures mints no node (fails on main: the node is 258 characters).
  • tests/unit/test_entity_stopwords_and_embed_batch.py: an entity_filter of 129 ligatures falls back to the parsed entities (fails on main).
  • tests/unit/test_point_write_relation_names.py: a 200-ligature subject or object is refused as longer than 256 once normalised (accepted on main).
  • Those four files and test_doc_links.py: pass.

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 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.
  • Generated files are regenerated in this PR, not by hand.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version.
  • The frontend builds and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 2 commits November 7, 2026 11:58
…ixed point at the cap

The timing test fed 20 000 to 32 000 characters to canonical_entity_text,
which returns '' for text over MAX_ENTITY_CHARS (256) before the normaliser
runs, so it compared '' with '' and timed four len() checks. The test now
asserts the cap itself and that a name of exactly 256 characters in each
of the old shapes is non-empty and a fixed point.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…o canonicalising stays idempotent

canonical_entity checked MAX_ENTITY_CHARS on the raw text only. NFKC can
lengthen it: 256 U+FB01 ligatures normalise to 512 characters of 'fi',
which were returned and stored, and a second pass returned ''. The
normalised text is now checked against the cap too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title test_memory_entities_canonical checks the entity length cap and the fixed point at the cap An entity whose normalised text passes the length cap is no entity, so canonicalising stays idempotent Nov 7, 2026
zlareb1 and others added 2 commits November 7, 2026 12:20
…sed text too

names_only kept a name by its raw length, so a facet or an entity filter of
129 ligatures passed it, canonicalised to '' and fell back to the raw text,
which was stored or bound unnormalised. A point write's fact part of 200
ligatures was refused as 'stored as ''' (articles, possessives and
punctuation are dropped), which named the wrong cause. One predicate,
fits_entity, now decides for canonical_entity, names_only and the
validator, and the validator says the part is longer than 256 characters
once normalised.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…rmalised

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title An entity whose normalised text passes the length cap is no entity, so canonicalising stays idempotent An entity name longer than 256 characters once normalised is no entity, and a point write refuses one Nov 7, 2026
zlareb1 and others added 5 commits November 7, 2026 12:34
…is named for what it refuses

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ds past the cap mints no node

facet_triples and the co-occurrence projection stored a commit: or error:
concept as concept.lower(), never normalised, so 'commit:' + 249 'İ'
(256 characters, fitting the cap) became a 505-character node and a
ligature stayed unfolded. code_facet_node folds it (fold_case), checks the
cap on what it stores, and both write sides use it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…that folds past the cap mints no node"

This reverts commit 5fbdcb8.

Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit fa1f513 into main Nov 7, 2026
38 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 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