forked from 1b-agent/opencadstudio-upstream
The recursion-depth guard fixes the parser stack overflow, but user input actually flows through eval_to_string (command line, viewport, dynamic input — synchronous on the UI thread). Its embedded-expression fallback re-tokenises every (start, end) window, so cost is ≈O(n³): a few-KB paste of non-evaluable text or deeply nested parens froze the app for seconds to minutes even though eval_number fast-returns None in microseconds (measured: "x"×3200 → 16 s, 4 KB of parens → 51 s). Cap the fallback scan at MAX_EVAL_SCAN_LEN (256) — whole-string numbers and expressions of any length still evaluate via the fast paths; only the mixed free-text scan is bounded, returning long input unchanged. Clarify that MAX_RECURSION counts parser frames (256 ≈ 41 nested parens, not 256 levels). Add regression tests: the 41/42 nesting boundary, unary-chain and function-arg-nesting rejection, and an eval_to_string over-cap promptness test (50k junk + 100k nested parens return instantly). Co-Authored-By: Claude Opus 4.8 <[email protected]>