From 0412589b11bf2fcb08f612580ba490ee7b91da22 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Tue, 27 Oct 2026 16:43:39 -0700 Subject: [PATCH] fix(scan): linear plain-number check for sampler-less texts (#252) The numeric pattern had overlapping quantifiers that backtrack quadratically on a long digit run ending in a non-digit; it now has none. --- tests/test_sampler_less_prompt.py | 8 ++++++++ utils/prompt_pair_resolver.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_sampler_less_prompt.py b/tests/test_sampler_less_prompt.py index 7f6379ab..62ee6fbe 100644 --- a/tests/test_sampler_less_prompt.py +++ b/tests/test_sampler_less_prompt.py @@ -1,5 +1,6 @@ """``sampler_less_prompt``: the one wired text of a graph with no sampler (#252).""" +import time import unittest from utils.prompt_pair_resolver import sampler_less_prompt @@ -31,6 +32,13 @@ class TestSamplerLessPrompt(unittest.TestCase): graph = _guided(**{"1": {"class_type": "Enc", "inputs": {"text": value}}}) self.assertEqual(sampler_less_prompt(graph)["state"], "absent", value) + def test_a_long_digit_run_with_a_letter_is_text_and_fast(self): + text = "9" * 50_000 + "x" + graph = _guided(**{"1": {"class_type": "Enc", "inputs": {"text": text}}}) + started = time.monotonic() + self.assertEqual(sampler_less_prompt(graph)["text"], text) + self.assertLess(time.monotonic() - started, 1.0) + def test_number_like_words_are_prompts(self): for value in ("nan", "inf", "Infinity", "1_000"): graph = _guided(**{"1": {"class_type": "Enc", "inputs": {"text": value}}}) diff --git a/utils/prompt_pair_resolver.py b/utils/prompt_pair_resolver.py index 5ff4324a..15200481 100644 --- a/utils/prompt_pair_resolver.py +++ b/utils/prompt_pair_resolver.py @@ -2580,7 +2580,7 @@ def resolve_text_input( return None -_NUMBER = re.compile(r"[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?") +_NUMBER = re.compile(r"[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?") def _numeric(text: str) -> bool: