Design review: pre-mortem report + safe type/exception tightening - #3
Merged
Conversation
Add PRE-MORTEM.md — a fragility map of the package. The codebase is in good shape (specific exception handlers throughout, clean ty/ruff), so the review is mostly semantic/operational findings rather than mechanical fixes. Headline fragilities flagged for a human decision: degenerate word-similarity on few-document corpora, dense embedder matrices (OOM), transform-before-fit raising the wrong error type, and the kNN path silently degrading to threshold-only. Safe, behaviour-preserving fixes applied here: - Remove a stale `# type: ignore[name-defined]` on Tokenizer._token_text (mypy-era leftover; ty passes without it). - Tighten knn_mask: np.ndarray -> NDArray[np.bool_] in build_semantic_graph. Everything that would change public behaviour is left untouched and listed under "needs human decision" in PRE-MORTEM.md. make ci green (118 tests, ty + ruff clean). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2 of the docs/design/test hardening pass — design review. The deliverable is
PRE-MORTEM.md, a fragility map of the package; the code changes are deliberately tiny because the codebase is already clean (specific exception handlers throughout, passingty+ruffANN/D).PRE-MORTEM.mdTen fragilities, ranked. The headline findings (all needs-human-decision, behaviour-changing, so not touched here):
cosine_similarity_matrixmakes word vectors of dimension = #documents, sobuild_semantic_graphover a short corpus returns an artifactually dense graph (555 edges / 81 nodes from ~12 sentences)..toarray()materialises(n_docs × n_vocab)float64; OOM risk that contradicts the "memory-efficient" positioning.transform()beforefit()raises sklearn'sNotFittedError, not the documentedRuntimeError(vocabularyguards;transformdoesn't).build_semantic_graph(k_neighbors=...)re-fits the embedder and silently degrades to threshold-only if the shape check fails.Plus operational items: runtime NLTK download + unwrapped unsupported-language error, unguarded
disparity_integral, in-place mutation footgun, pickle RCE, percentile tie-bias, chunk mid-token split.Safe fixes applied (behaviour-preserving)
# type: ignore[name-defined]onTokenizer._token_text(mypy-era leftover;typasses without it).knn_mask: np.ndarray→NDArray[np.bool_].Verification
make cigreen — 118 tests pass,ty+ruffclean.mkdocs buildclean (docs unchanged on this branch; strict-mode enablement lives in the docs PR Docs overhaul: contract docstrings + rebuilt quickstart/tutorials/troubleshooting #2).Notes
uv.lockpre-existing 0.1.0→0.1.1 drift left untouched.🤖 Generated with Claude Code