Skip to content

Spelling: bound a word's language and index results by offset - #1767

Merged
dylanmtaylor merged 2 commits into
mainfrom
fix/sec-engine-spell-words
Nov 4, 2026
Merged

dylanmtaylor merged 2 commits into
mainfrom
fix/sec-engine-spell-words

Conversation

@dylanmtaylor

@dylanmtaylor dylanmtaylor commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What was wrong

Spell checking a paragraph:

  • Word language: paragraph_words gave every word its own copy of the run's language string, and imported language values have no length bound. A paragraph of many short words under one huge lang value made one copy per word.
  • Merging results: misspelt merged spelling and repetition results by linearly searching the results kept so far for the same offset. A paragraph of many repeated words (the the the …) made that quadratic.

What changed

  • MAX_LANG_LEN (64 bytes) bounds the language. A run or default language longer than that counts as none (no dictionary is ever found for it) and is not copied into words. BCP 47 tags in documents are a few bytes.
  • Result merging keys an offset → index map. A repeated misspelt word is still reported once, as repeated.
  • Added a test: 100,000 copies of one word under a 1 MB language value. No word carries the value, and 99,999 repeats are found.

Blast radius

deckcraft-engine spelling (review.spelling, the red underlines). Normal language tags behave as before.

Checks run

  • cargo fmt -p deckcraft-engine --check
  • cargo clippy -p deckcraft-engine --all-targets -- -D warnings
  • cargo test -p deckcraft-engine

Checks not run

  • The full cargo xtask ci

Summary by CodeRabbit

  • Bug Fixes
    • Spell checking now handles very long language tags more reliably, avoiding their propagation through word-level checks.
    • Repeated words in a paragraph are reported consistently, with duplicate results consolidated.
    • Improved reliability when processing paragraphs with many repeated words and unusually large language tags.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Spell processing now limits language tags to 64 bytes and uses word start positions to replace duplicate results. A regression test covers oversized language tags and repeated words.

Changes: Spell processing

Layer / File(s) Summary
Language limits and repeated-word results
crates/engine/src/spell.rs
Oversized default and run-level language tags resolve to empty strings. Result folding tracks word start positions and replaces existing results at matching positions. A regression test covers 100,000 repeated words and oversized language tags.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: silvertree2010, echelon

Merge Risk: Minimal · up to 206aa

No merge-blocking issue is established for this change; the command-side performance concern predates it.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names two changes: bounding a word's language value and indexing spelling results by offset. The raw summary confirms both. paragraph_words now caps language tags at 64 bytes, and misspelt n…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names two changes: bounding a word's language value and indexing spelling results by offset. The raw summary confirms both. paragraph_words now caps language tags at 64 bytes, and misspelt now deduplicates by start position with a position-to-result index. The title is specific and accurate, though it does not mention the regression test or the repeated-word dedup behavior, which is expected for a short title.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between aa13eeb and 206aab8.

Files selected for processing: 1
  • crates/engine/src/spell.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@dylanmtaylor
dylanmtaylor merged commit 0233d29 into main Nov 4, 2026
9 of 10 checks passed
@dylanmtaylor
dylanmtaylor deleted the fix/sec-engine-spell-words branch November 4, 2026 00:59
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