Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
every `scan_interval_seconds` while the worker is busy too, not only
between drains.

### Security

- **The `[nltk]` extra now pins NLTK 3.10.4** (was 3.9.4). 3.9.4's
`PorterStemmer.stem()` can be driven into a slow path by a crafted word
(PYSEC-2026-3738, fixed in 3.10.3), and the `nltk` tokenizer stems every
token of ingested text. The two releases tokenize alike except for a word
right after an opening quote (`'cause`), which 3.9.4 dropped: 449 of
83,484 LoCoMo and LongMemEval texts change. Turn-level BM25 over the 1,977
LoCoMo questions with evidence is unchanged (Hit@5 60.09% -> 60.04%, MRR
0.4600 -> 0.4600).

### Upgrade

- A store indexed with `[tokenizer] name = "nltk"` should run
`everos cascade rebuild` after upgrading, so stored tokens and query
tokens come from the same NLTK release. On Linux and macOS, NLTK 3.10 also
refuses data another account could write: if the `nltk` tokenizer now
reports its data missing, run `chmod -R go-w` on the data directory the
error names. The default `jieba` tokenizer is unaffected.

## [1.7.1] - 2026-11-20

EverOS 1.7.1 writes each conversation's memory in its own language: a short
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ help:

# Sync deps from uv.lock; CI calls this directly. --frozen means "lock is the
# source of truth — fail rather than update it". Then fetch the NLTK data the
# nltk tokenizer reads, into the venv where NLTK looks for it.
# nltk tokenizer reads, into the venv where NLTK looks for it, private to its
# owner: NLTK >= 3.10 will not read data another account could write, which a
# group-writable checkout (umask 002) would otherwise give it.
install-deps:
uv sync --frozen
uv run --frozen python -m nltk.downloader -q -e -d .venv/nltk_data punkt_tab stopwords
chmod -R go-w .venv/nltk_data

# One-stop dev setup: deps + pre-commit hooks (both pre-commit and commit-msg
# stages — gitlint runs on commit-msg).
Expand Down
6 changes: 6 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ pip install "everos[nltk]"
python -m nltk.downloader punkt_tab stopwords
```

On Linux and macOS, NLTK 3.10 and later will not read data that another
account could write (a group or world write bit, or another owner), and that
data then reads as missing. Keep the data directory private to its owner
(`chmod -R go-w <dir>`); the startup error names the directory when this is
the cause.

The LanceDB keyword index lowercases, Snowball-stems and ASCII-folds tokens on
both the indexed and the query side, so on that backend `nltk` tokens are
stemmed a second time; matching stays symmetric.
Expand Down
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ otel = [
"opentelemetry-exporter-otlp-proto-http>=1.27.0",
]
milvus = ["pymilvus>=3.0.0"]
# NLTK keyword tokenizer (`[tokenizer] name = "nltk"`). Pinned to the release the
# EverAlgo LoCoMo harness used: tokens change across NLTK releases, and the
# indexed side and the query side must produce the same ones.
nltk = ["nltk==3.9.4"]
# NLTK keyword tokenizer (`[tokenizer] name = "nltk"`). Pinned exactly: tokens
# change across NLTK releases, and the indexed side and the query side must
# produce the same ones. 3.10.4 fixes a PorterStemmer DoS (PYSEC-2026-3738) on
# the path every token takes; a store indexed under another release needs
# `everos cascade rebuild`.
nltk = ["nltk==3.10.4"]
Comment thread
gloryfromca marked this conversation as resolved.
Resolved

[project.urls]
Homepage = "https://evermind.ai"
Expand Down Expand Up @@ -566,6 +568,6 @@ dev = [
"opentelemetry-exporter-otlp-proto-http>=1.27.0",
"pymilvus>=3.0.0",
# The NLTK tokenizer tests must run, not skip, so the [nltk] extra is present too.
"nltk==3.9.4",
"nltk==3.10.4",
"hypothesis>=6.100",
]
31 changes: 26 additions & 5 deletions src/everos/component/tokenizer/nltk_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* The ``punkt_tab`` and ``stopwords`` NLTK data must already be installed.
Nothing is downloaded at runtime: a missing resource fails at construction.
* The token stream depends on the NLTK release, so the ``[nltk]`` extra pins
the one the harness used.
one exactly. It is 3.10.4, newer than the harness's 3.9.4: it fixes
a PorterStemmer denial of service, and the two differ only on a word right
after an opening quote (``'cause``), which 3.9.4 dropped.
"""

from __future__ import annotations

__all__ = ["NltkTokenizer"]

import os
from collections.abc import Sequence
from typing import Final

Expand Down Expand Up @@ -78,12 +81,30 @@ def _require_data() -> None:
CapabilityError: Naming every missing resource and the install command.
"""
missing = [name for name, path in _REQUIRED_DATA.items() if not _has(path)]
if missing:
if not missing:
return
# On POSIX, NLTK >= 3.10 skips data another account could write (a group or
# world write bit, or a foreign owner), so data that is there reads as
# missing; say so instead of asking for a download that would not help.
refused = sorted(
{root for root in nltk.data.path for n in missing if _on_disk(root, n)}
)
if refused:
raise CapabilityError(
f"The nltk tokenizer needs NLTK data that is not installed: "
f"{', '.join(missing)}. Install with: "
f"python -m nltk.downloader {' '.join(missing)}"
f"The nltk tokenizer found NLTK data ({', '.join(missing)}) under "
f"{', '.join(refused)} but NLTK will not read it: another account "
"could write it. Make it private to its owner: "
f"chmod -R go-w {' '.join(refused)}"
)
raise CapabilityError(
f"The nltk tokenizer needs NLTK data that is not installed: "
f"{', '.join(missing)}. Install with: "
f"python -m nltk.downloader {' '.join(missing)}"
)


def _on_disk(root: str, name: str) -> bool:
return os.path.exists(os.path.join(root, *_REQUIRED_DATA[name].split("/")))


def _has(resource: str) -> bool:
Expand Down
44 changes: 43 additions & 1 deletion tests/unit/test_component/test_tokenizer/test_nltk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

from __future__ import annotations

import os
import sys
import warnings
from pathlib import Path

import nltk
import pytest

from everos.component.tokenizer import build_tokenizer
from everos.component.tokenizer import build_tokenizer, nltk_provider
from everos.component.tokenizer.nltk_provider import NltkTokenizer
from everos.config import TokenizerSettings
from everos.core.errors import CapabilityError
Expand Down Expand Up @@ -51,6 +53,17 @@ def test_tokens_match_the_everalgo_harness(text: str, expected: list[str]) -> No
assert NltkTokenizer().tokenize(text) == expected


def test_a_word_after_an_opening_quote_is_kept() -> None:
"""NLTK 3.10 splits a leading quote off a word; 3.9.4 dropped the word.

The one token difference between the two releases on LoCoMo + LongMemEval
text (449 of 83,484 texts). The harness above ran 3.9.4, so it has no
such case; this pins the pinned release's behaviour.
"""
text = "Camping with my fam, 'cause nature helps."
assert NltkTokenizer().tokenize(text) == ["camp", "fam", "caus", "natur", "help"]


def test_tokenize_batch_preserves_order() -> None:
texts = ["What did Melanie paint?", "", "swimming lessons"]
assert NltkTokenizer().tokenize_batch(texts) == [
Expand All @@ -69,11 +82,40 @@ def _missing(resource: str) -> None:
raise LookupError(resource)

monkeypatch.setattr(nltk.data, "find", _missing)
monkeypatch.setattr(nltk.data, "path", []) # nothing on disk either
with pytest.raises(CapabilityError) as err:
NltkTokenizer()
assert "python -m nltk.downloader punkt_tab stopwords" in str(err.value)


@pytest.mark.skipif(os.name != "posix", reason="NLTK checks ownership on POSIX only")
def test_data_another_account_could_write_is_named_with_the_fix(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
"""NLTK >= 3.10 skips group- or world-writable data, so it reads as missing.

The error must say why and how to fix it, not ask for a download.
"""
root = tmp_path / "nltk_data"
for resource in ("tokenizers/punkt_tab/english", "corpora/stopwords"):
(root / resource).mkdir(parents=True)
monkeypatch.setattr(nltk.data, "path", [str(root)])

for d in [root, *root.rglob("*")]:
d.chmod(0o775)
with (
pytest.warns(RuntimeWarning, match="NLTK will not read"),
pytest.raises(CapabilityError) as err,
):
nltk_provider._require_data()
assert f"chmod -R go-w {root}" in str(err.value)
assert "nltk.downloader" not in str(err.value)

for d in [root, *root.rglob("*")]:
d.chmod(0o755)
nltk_provider._require_data() # the same data, private: accepted


def test_the_factory_builds_nltk_when_selected() -> None:
tokenizer = build_tokenizer(TokenizerSettings(name="nltk"))
assert isinstance(tokenizer, NltkTokenizer)
Expand Down
11 changes: 6 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.