Skip to content

Design review: pre-mortem report + safe type/exception tightening - #3

Merged
zolizoli merged 1 commit into
mainfrom
design-review
Jun 29, 2026
Merged

Design review: pre-mortem report + safe type/exception tightening#3
zolizoli merged 1 commit into
mainfrom
design-review

Conversation

@zolizoli

Copy link
Copy Markdown
Member

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, passing ty + ruff ANN/D).

PRE-MORTEM.md

Ten fragilities, ranked. The headline findings (all needs-human-decision, behaviour-changing, so not touched here):

  1. Degenerate word similarity on few-document corporacosine_similarity_matrix makes word vectors of dimension = #documents, so build_semantic_graph over a short corpus returns an artifactually dense graph (555 edges / 81 nodes from ~12 sentences).
  2. Dense embedder matrices.toarray() materialises (n_docs × n_vocab) float64; OOM risk that contradicts the "memory-efficient" positioning.
  3. transform() before fit() raises sklearn's NotFittedError, not the documented RuntimeError (vocabulary guards; transform doesn't).
  4. 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)

  • Removed a stale # type: ignore[name-defined] on Tokenizer._token_text (mypy-era leftover; ty passes without it).
  • Tightened knn_mask: np.ndarrayNDArray[np.bool_].

Verification

Notes

  • uv.lock pre-existing 0.1.0→0.1.1 drift left untouched.
  • Do not merge — part of the docs / design / tests review queue.

🤖 Generated with Claude Code

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>
@zolizoli
zolizoli merged commit 845a9f0 into main Jun 29, 2026
4 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.

1 participant