Skip to content

Avoid exponential backtracking in fuzzy completion - #2176

Open
anishpentyala wants to merge 2 commits into
prompt-toolkit:mainfrom
anishpentyala:fix/fuzzy-match-backtracking
Open

anishpentyala wants to merge 2 commits into
prompt-toolkit:mainfrom
anishpentyala:fix/fuzzy-match-backtracking

Conversation

@anishpentyala

Copy link
Copy Markdown

Fuzzy completion can stall on a short repeated-character query even with only one candidate. The generated subsequence regex explores combinations when the final character is missing.

Match the same leftmost, shortest subsequence without backtracking, retaining case-insensitive Unicode and newline behavior. Adds a bounded subprocess regression and comparisons against the previous regex on seeded inputs.

Validation:

  • Full suite: 158 tests pass on Python 3.13.18; independently checked on Python 3.10.
  • Regression reproduces a timeout on unchanged main.
  • Changed-file Ruff lint/format and targeted mypy checks pass.
  • Seeded parity checks against the previous regex include Unicode, metacharacters and newlines.

This is separate from the asynchronous completion work in #2144, though it touches nearby code.

Refactor fuzzy matching to use individual character patterns for improved Unicode handling and performance.
Add tests for fuzzy completer functionality and behavior.
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