#1073·OpenJarvis

score_complexity: multi-step regex is quadratic on long input (first ... next)

Author: wagnerglorenzCreated Oct 1, 2026Updated Oct 1, 2026

Component: src/openjarvis/learning/routing/complexity.py (_MULTI_STEP_PATTERNS)

\bthen\b.*\bthen\b|\bfirst\b.*\bnext\b|... uses an unbounded .*. score_complexity runs on every jarvis ask with routing enabled, so pasting a long document blocks the CLI.

Reproduction (CPython 3.12, base 5e5f5ef):

python
from openjarvis.learning.routing.complexity import score_complexity
score_complexity("first " * 20000)   # 120 KB: 9.8 s ; 60 KB: 2.6 s ; 30 KB: 0.7 s

Suggested fix: bound the gap (.{0,200}?) or use two search calls. Happy to send a PR with a regression test.

Generated with Claude Code