Skip to content

fix(memory): count Unicode letters in entity name length checks - #413

Open
Afloat16 wants to merge 3 commits into
simplexai-labs:mainfrom
Afloat16:afloat/entity-name-unicode-letters
Open

Afloat16 wants to merge 3 commits into
simplexai-labs:mainfrom
Afloat16:afloat/entity-name-unicode-letters

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Count Unicode letters and numbers when applying the existing minimum length for non-Han entity names, while retaining Han thresholds, ambiguous-name exclusion and case-sensitive single words. Ordinary one-word aliases in scripts with letter case remain excluded.

Qualifying accented Latin, Cyrillic and Arabic names can participate in inferred memory relations and flashback retrieval. Names without Han still need at least four letters or digits; this change does not lower the threshold for short Hangul or kana names.

How it was verified

Original comparison base: 77abdcb37f779f9c9d2de89fa245efa88d3f6584. Linux, Node 26.5.0 and pnpm 11.7.0.

  • The original length-check regressions: four non-ASCII names fail on the comparison base, while seven controls pass. The initial implementation passed all 27 inferred-edge, graph-build and flashback tests.

  • Review 6052805628, P2: added four regressions for capitalized and lowercase ordinary aliases in Cyrillic and Greek. Against f0cab93e45ac540710184bc10ca16ee5535604f4, the three complete related test files produced 4 failed / 29 passed. With Unicode uppercase/lowercase categories in the plain-word alias filter, all 33 tests passed. Positive controls retain all-uppercase Cyrillic aliases, uncased Arabic aliases, and existing Unicode entity titles.

  • Focused command: pnpm --filter @linger/node-services exec vitest run tests/memory/inferred-edges.test.ts tests/memory/graph-build.test.ts tests/memory/flashback.test.ts --maxWorkers=1.

  • P3: narrowed the title and README to the length-check behavior and documented the unchanged minimums. No new script-specific thresholds were added.

  • git diff --check passed. The repository's scripts/ci/check-changed-files.sh 77abdcb37f779f9c9d2de89fa245efa88d3f6584 --worktree passed formatting, lint and English-only checks on the final tree. All new non-ASCII test inputs use escaped code points.

  • Focused tests for the changed behavior

  • make check BASE=origin/<target-branch> or the fast checks of every touched app

  • No contract regeneration required

Current owning-package gate

On the tree published as 7d187509eff1a7ba8182390a6e40e7ecb6c62a4a, pnpm --filter @linger/node-services check completed with exit 0. Feature-catalog verification, TypeScript checking and lint passed; Vitest finished with 268 files passed, 8 skipped; 2,722 tests passed, 51 skipped. The normal project configuration and a task-local temporary directory were used, including the real-process lane. Dependencies were installed in this isolated worktree with the frozen lockfile. No timeout or skip configuration was changed.

The published tree 96efb064698f4663a7a74e4390d058f592f34067 matches the locally checked tree. This completes the fast check for the only affected app. Repository-wide and live-service/E2E gates are separate and are not claimed here.

Boundary

The nearest behavior documentation is updated. No dependency or wire-contract change. This patch adds no network round trip or file walk to the user message to provider_ready path.

@Afloat16
Afloat16 marked this pull request as ready for review November 25, 2026 06:17

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with nits (1 P2, 1 P3)

Scope: base main, merge base 77abdcb3, 1 commit, 3 files reviewed. I loaded ponytail-review (sections 1–3) and did not load coderbook or karpathy-guidelines. The review ran alone in a separate session.

Findings

P2

apps/node-services/src/memory/graph/inferred-edges.ts:28 — the plain-word alias filter only knows ASCII, and this change lets non-Latin aliases through to it

plainWordPattern = /^[A-Z]?[a-z]+$/u is the rule that keeps an ordinary one-word alias such as "Sequence" from being treated as a name. Before this change, an alias written only in Cyrillic or Greek letters was dropped by the length check in normalizedName, because it had 0 ASCII letters. So the filter never had to deal with those scripts. Now the length check counts \p{L}\p{N}, and those aliases pass it, but plainWordPattern still does not match them:

"Sequence"                    plainWord=true   oldLen=8  newLen=8
"Проект" (Проект, "Project")  plainWord=false  oldLen=0  newLen=6

Example: a project has the frontmatter alias Проект. Every Session page that starts a sentence with "Проект ..." now gets a mention edge to that project, and flashback (flashback/service.ts:196, flashback/suggest.ts:105) suggests it. That is the "an epic effort" false positive the doc comment says is prevented. The README line "Existing short-name, case and ambiguous-name filters still apply" is true, but the plain-word filter does not hold for the newly admitted names.

Fix: make the pattern Unicode-aware, /^\p{Lu}?\p{Ll}+$/u. Then add a test that mirrors the existing "Sequence" alias case (tests/memory/inferred-edges.test.ts:138) with a Cyrillic word written as escaped code points. Arabic and other scripts without letter case still pass the filter, and that is acceptable.

P3

apps/node-services/src/memory/graph/inferred-edges.ts:148 — dense scripts other than Han still use the Latin 4-character minimum

Only Han gets the 2-character minimum. Names in other dense scripts still need 4 letters:

김민수 (Korean, 3 syllables) -> 3   rejected
さくら (kana, 3 characters)   -> 3   rejected

A typical three-syllable Korean name, or a three-kana Japanese name, still never matches. That does not live up to the title "match entity names across Unicode scripts". Either apply the Han minimum to Hangul and kana too (\p{Script=Hangul}, \p{Script=Hiragana}, \p{Script=Katakana}), or narrow the title and the README sentence to the scripts that are actually covered. Nothing regresses here, since these names were also rejected before.

Verified as fine

  • Name matching already uses Unicode word boundaries: namePattern (inferred-edges.ts:159) uses (?<![\p{L}\p{N}])…(?![\p{L}\p{N}]), so the new names in José, Cyrillic and Arabic match as whole words. One-word names compile without the i flag, so they stay case-sensitive in Cyrillic too.
  • Emoji and punctuation do not count toward the minimum. \p{L}\p{N} excludes them, and the new emoji test covers this. Decomposed accents (\p{M}) are stripped too, without making a Latin name too short.
  • ASCII names behave as before: for pure ASCII input, [^\p{L}\p{N}] after toLowerCase() keeps the same characters as [^a-z0-9].
  • The function's only callers, graph/build.ts:60, flashback/service.ts:196 and flashback/suggest.ts:105, need no change. Its signature is unchanged.
  • The README under src/memory/ is updated. There are no contract, env or dependency changes, and the user message → provider_ready path is untouched.
  • No CJK text in added lines or in the commit message. The tests use escaped code points.

Process notes

  • One commit, no merge commits or fixup commits.

CI

The checks that ran (repository-gate, changes, check (web)) passed. The rest were skipped by path. The PR CI does not run the node-services suite. The author reports pnpm --filter @linger/node-services check passing on this head. I did not rerun it, because the worktree has no node_modules. I checked the length and plain-word behaviour directly with node -e on the same regexes.

Automated review by Claude Code


Automated review of f0cab93 by Claude Code.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes (1 P0) — the logic is right; the only blocker is a formatting failure that keeps repository-gate red.

Scope: follow-up on f0cab93, now reviewing 687655d. Base main, merge base 77abdcb, 2 commits, 3 files. Loaded the helper skills coderbook (§2, §3, §5), ponytail-review (§1–3) and karpathy-guidelines (§2–3). This review ran in a separate session.

Previous findings

  • P2: plain-word alias filter only recognized ASCII. Resolved. apps/node-services/src/memory/graph/inferred-edges.ts:28 is now /^\p{Lu}?\p{Ll}+$/u. New tests cover lowercase and capitalized Cyrillic and Greek aliases, which are now filtered, and all-caps Cyrillic and uncased Arabic aliases, which are kept (inferred-edges.test.ts:170-211). Without this change, the old ASCII pattern would let Проект through, and the first it.each would see an extra projects/research edge.
  • P3: Hangul and kana names still need 4 characters, which contradicts the "across Unicode scripts" claim. Resolved through docs. The README (apps/node-services/src/memory/README.md:17-22) now says the PR admits accented Latin, Cyrillic and Arabic names and does not lower the threshold for short Hangul or kana names. The mentionEdges doc comment now says "4 letters or digits in other scripts". The PR body only claims accented, Cyrillic and Arabic names.

Findings

P0

  • apps/node-services/tests/memory/inferred-edges.test.ts:193: the new test is not Prettier-formatted, so repository-gate fails.
    • Evidence: the CI log for make check-repository-gate shows [warn] apps/node-services/tests/memory/inferred-edges.test.ts — Code style issues found, followed by Error 1. I reproduced it locally with prettier --check.
    • Cause: Prettier wants the two-element it.each([...]) array on one line, with the test name and callback as wrapped arguments.
    • Impact: main requires this check, so the PR cannot merge.
    • Fix: run pnpm exec prettier --write apps/node-services/tests/memory/inferred-edges.test.ts and amend the change into the commit that adds the test.

Verified as fine

  • normalizedName (inferred-edges.ts:141-151):
    • Names without Han count code points of \p{L}\p{N} against the existing minimum of 4.
    • Names containing Han keep the 2-character rule.
    • The spread [...] counts astral characters as one, not as UTF-16 code units.
  • namePattern (inferred-edges.ts:154-161) already used Unicode-aware (?<![\p{L}\p{N}]) boundaries. Non-Latin one-word names therefore match whole words, and their case stays sensitive because the i flag is only added for names that contain whitespace.
  • Plain-word filtering applies only to aliases, not titles (inferred-edges.ts:118-120), as before. Uncased scripts (Arabic \p{Lo}) never match \p{Lu}?\p{Ll}+, so their one-word aliases are kept. That matches the README sentence "plain-word aliases in scripts with letter case".
  • entityNamePatterns is the single source for both mention edges and flashback, so both paths pick up the change. There are no other callers of normalizedName or plainWordPattern.
  • No contract, env, dependency or cross-app change. The doc comment and README were updated in the same PR. No CJK in added lines or commit messages.

Process notes

  • The branch is 338 commits behind main and needs a rebase.
  • 687655d ("preserve Unicode plain-word alias filtering") only patches behaviour introduced in f0cab93 in response to review. main takes rebase merges, so squash it into f0cab93 (for example with git rebase -i --autosquash).
  • Both commits have no body that explains what changed and why.

CI

  • Fails: repository-gate (Prettier on the test file, as above).
  • Passes: changes and check (web). All other jobs were skipped by the path plan.
  • No node-services job ran in CI for this head. Locally, I ran vitest run tests/memory/inferred-edges.test.ts: 17/17 passed.

Automated review by Claude Code


Automated review of 687655d by Claude Code.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve (0 findings)

Scope: follow-up on 687655d. Base main, merge base 77abdcb3; 3 commits, 3 files reviewed at 7d187509. Helper skills were not loaded in this headless run; the review used the linger-pr-review checklist directly. It ran in a separate session.

Previous findings

  • P0: new it.each block not Prettier-formatted (apps/node-services/tests/memory/inferred-edges.test.ts): Resolved. 7d187509 reformats it, and prettier --check with the repo-pinned 3.8.4 passes on all three changed files. repository-gate is green.

Findings

None.

Verified as fine

  • Length threshold (apps/node-services/src/memory/graph/inferred-edges.ts:145-149): non-Han names now count code points matching \p{L}\p{N} and still need at least 4. Digits counted before too ([^a-z0-9]), so ASCII names behave as they did. Emoji and punctuation don't count, and the new emoji test covers that. Han keeps the 2-character rule.
  • Plain-word alias filter (inferred-edges.ts:28): /^\p{Lu}?\p{Ll}+$/u keeps the old ASCII behaviour ([A-Z]?[a-z]+ is a subset) and now also drops ordinary capitalised or lowercase one-word aliases in other cased scripts. Uncased scripts (Arabic) and all-caps aliases are kept. Tests cover all three cases (Cyrillic and Greek dropped; all-caps Cyrillic and Arabic kept).
  • Whole-word boundaries (inferred-edges.ts:159): namePattern was already Unicode-aware ((?<![\p{L}\p{N}])...(?![\p{L}\p{N}]), u flag), so newly admitted non-Latin names match on whole words without further changes. One-word names stay case-sensitive (gu).
  • Scripts without spaces (kana, Thai): 4+ letter names are now admitted, but the whole-word lookarounds stop them matching inside running text. The result is a missed match, never a false one, and neither script matched on the base before this PR. The README says as much.
  • Callers: entityNamePatterns is used by mentionEdges (inferred-edges.ts:59), flashback/suggest.ts:105 and flashback/service.ts:196. All of them go through the same normalizedName and namePattern, so graph edges and flashback cues stay consistent.
  • Docs: apps/node-services/src/memory/README.md describes the new rule, matching the code.
  • Repo rules: no CJK in added lines or commit messages, no config, env var or contract change, and nothing added to the provider_ready path.

Process notes

  • 687655d6 (plain-word alias fix) and 7d187509 (formatting) only patch f0cab93e from this same PR. main takes rebase merges, so consider squashing them (git rebase -i --autosquash).
  • The commit author is linked to GitHub (Afloat16).

CI

  • repository-gate and check (web) pass. Every other app check was skipped by the change plan, and no node-services check appears in this run.
  • Run locally: vitest run tests/memory/inferred-edges.test.ts tests/memory/flashback.test.ts tests/memory/graph-build.test.ts, 3 files / 33 tests, all passed. prettier --check (3.8.4) on the changed files also passed.

Automated review by Claude Code


Automated review of 7d18750 by Claude Code.

@Afloat16 Afloat16 changed the title fix(memory): match entity names across Unicode scripts fix(memory): count Unicode letters in entity name length checks Nov 25, 2026
@Afloat16

Copy link
Copy Markdown
Contributor Author

Addressed P2 and P3 from review 6052805628 in 7d187509eff1a7ba8182390a6e40e7ecb6c62a4a.

The plain-word alias filter now uses /^\p{Lu}?\p{Ll}+$/u, so ordinary capitalized/lowercase Cyrillic and Greek aliases follow the existing ASCII rule. Four new public-behavior regressions failed on the previous head; after the fix the complete inferred-edge, graph-build and flashback files pass 33/33. All-uppercase Cyrillic aliases, uncased Arabic aliases and existing Unicode entity titles remain covered.

The title and README now describe the Unicode length check and its existing thresholds. Names without Han still need four letters or digits; short Hangul/kana names receive no new special case.

The complete pnpm --filter @linger/node-services check passed on the published tree: 268 files / 2,722 tests passed, 8 files / 51 tests skipped, with typecheck, feature-catalog verification and lint passing. No timeout or skip settings were changed. The repository's changed-file formatting, lint and English-only checks also passed on the final tree.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve (0 findings)

Scope: base main, merge base 77abdcb3, 3 commits, 3 files (inferred-edges.ts, its test, memory/README.md). Follow-up on 7d187509: the head is the same commit as last time, so there are no new changes. I re-ran the assumption check over the whole merge-base diff. Helper skills: coderbook, ponytail-review, karpathy-guidelines (guidance only). Ran in a separate session.

Previous findings

The previous review of 7d18750 had no findings, so there is nothing to track.

Findings

None.

Verified as fine

  • Length check. normalizedName (apps/node-services/src/memory/graph/inferred-edges.ts:141-151) now counts code points matching \p{L}\p{N} for names without Han and keeps the Han rule of 2 or more characters. I checked it in Node: José/Éric count 4, Алина 5, أحمد 4, and four rocket emoji count 0, so the emoji name is rejected. This matches the new tests.
  • Plain-word alias filter. /^\p{Lu}?\p{Ll}+$/u (inferred-edges.ts:28) is applied only to aliases (inferred-edges.ts:118-120). Titles are not filtered, so a title such as José is still matched. Cyrillic and Greek ordinary words (Проект, σχέδιο) are now filtered like ASCII Sequence. All-uppercase ПРОЕКТ and Arabic أحمد, which has no letter case, stay. The one behavior change is for accented Latin one-word aliases: Renée was admitted before and is now filtered. This is consistent with the stated rule that ordinary one-word aliases in cased scripts are excluded.
  • Whole-word matching. namePattern (inferred-edges.ts:154-160) already used \p{L}\p{N} lookarounds, so non-Latin names get correct word boundaries with no further change. One-word names stay case-sensitive (gu flags).
  • Callers. All three consumers go through entityNamePatterns: graph/build.ts:60 (via mentionEdges), flashback/service.ts:196 and flashback/suggest.ts:105. They pick up the rule consistently, with no second copy of the rule to drift.
  • PR description vs. diff. No threshold is lowered for Hangul or kana: the minimum stays at 4 letters, and unspaced text rarely satisfies the word-boundary lookarounds anyway. No contract, env or dependency change. The README is updated in the same PR. Test inputs use escaped code points, and there is no CJK in added lines or commit messages.
  • Tests. The regressions cover the four admitted scripts, the emoji/punctuation negative case, filtered cased aliases (both capitalized and lowercase), and kept uncased or uppercase aliases.

Process notes

  • The branch is 338 commits behind main. main requires up-to-date branches, so it needs a rebase (merge state: BLOCKED).
  • 687655d6 (review follow-up to the alias filter) and 7d187509 (formatting of those tests) only patch the PR's own first commit f0cab93e. Consider squashing them with git rebase -i --autosquash before the rebase merge.
  • All commits are linked to Afloat16. There are no merge commits.

CI

repository-gate, changes and check (web) pass; the other app checks were skipped by path. By design, CI does not run check-node-services (see the ci.yml header), so the touched memory tests are not covered by CI. The author reports a local pnpm --filter @linger/node-services check pass. I did not run Vitest because deps are not installed in this worktree. Instead, I checked the regex and length logic directly in Node against the test inputs, and it matches the expected results.

Automated review by Claude Code


Automated review of 7d18750 by Claude Code.

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