Skip to content

fix: stop observation dedup from merging "port 80" into "port 8080" - #2

Merged
bugstan merged 4 commits into
n2ns:mainfrom
RooAC:fix/dedup-word-boundary
Oct 27, 2026
Merged

bugstan merged 4 commits into
n2ns:mainfrom
RooAC:fix/dedup-word-boundary

Conversation

@RooAC

@RooAC RooAC commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Summary

containsSimilar used a plain substring check, so deduplicateObservations treated an observation as a duplicate whenever its text appeared anywhere inside another one, even in the middle of a word or number. Distinct facts were silently merged and the shorter one was dropped when they were written through n2n_add_observations / n2n_create_entities:

deduplicateObservations(["API listens on port 80", "API listens on port 8080"])
// before: ["API listens on port 8080"]   ("port 80" is lost)
deduplicateObservations(["Requires Node 1.2", "Requires Node 1.20"])
// before: ["Requires Node 1.20"]
deduplicateObservations(["cat", "Uses a concatenation step"])
// before: ["Uses a concatenation step"]

The containment check now only matches when the contained text does not start or end in the middle of a Latin word or a number. Intended merges still work ("version 2.4" vs "version 2.4.1", "version 2.4.1" vs "version 2.4.1 released"), and text written without spaces (e.g. Chinese, 使用redis vs 使用redis缓存) keeps plain substring matching.

Testing

  • Added tests in src/test/similarity.test.ts; the new word-boundary tests fail on main and pass with this change.
  • npm run lint, npm test (111 passed), npm run build and npm run pack:dry-run pass locally.
  • npm run check stops at npm run audit because of existing advisories in transitive dependencies of @modelcontextprotocol/sdk (body-parser, fast-uri, qs); this is also the case on main and is unrelated to this change.

Checklist

  • Tests were added or updated where needed.
  • Documentation was updated where behavior changed. (CHANGELOG.md and docs/CHANGELOG_zh.md)
  • npm run check passes locally. (see audit note above)

@bugstan
bugstan merged commit 97f26cb into n2ns:main Oct 27, 2026
0 of 2 checks passed
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.

2 participants