xai-org/x-algorithm · error · RegexTimeoutException

regex match being interrupted. Tmeout: %s.

Error message

regex match being interrupted. Tmeout: %s.

What it means

InterruptibleCharSequence wraps the input of a regex match and periodically (every 64 chars via the bitmask check) polls a timeout Future; if the timeout completed, the match is aborted with RegexTimeoutException. This prevents catastrophic-backtracking regexes from hanging threads.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/InterruptibleCharSequence.java:26

  private long checker = 0L;

  public InterruptibleCharSequence(CharSequence underlying, Timeout timeout) {
    super();
    this.underlying = underlying;
    this.timeout = timeout;
  }

  @Override
  public int length() {
    return underlying.length();
  }

  @Override
  public char charAt(int index) {

    if ((++checker & 0x3FL) == 0) {
      if (timeout.isDone()) {
        throw new RegexTimeoutException(
            String.format(
                "regex match being interrupted. Tmeout: %s.", timeout
            ));
      }
    }
    return underlying.charAt(index);
  }

  @Override
  public CharSequence subSequence(int start, int end) {
    if (underlying instanceof InterruptibleCharSequence) {
      return underlying.subSequence(start, end);
    } else {
      return new InterruptibleCharSequence(underlying.subSequence(start, end), timeout);
    }
  }

  @Override

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Simplify the regex to reduce backtracking (anchor it, remove nested quantifiers, use possessive quantifiers/atomic groups)
  2. Increase the timeout if the match is legitimately expensive
  3. Pre-cap input length before matching
  4. Consider substring pre-filtering before applying the regex

Example fix

// before
Pattern p = Pattern.compile("(a+)+b"); // catastrophic
// after
Pattern p = Pattern.compile("a*+b|a+b"); // possessive / simplified
Defensive patterns

Strategy: retry

Validate before calling

if (input.length() > MAX_LEN) input = input.substring(0, MAX_LEN);

Try / catch

catch (RegexTimeoutException e) { /* fall back to a simpler/safe regex or reject the input */ }

Prevention

When it happens

Trigger: Running Pattern.matcher over an InterruptibleCharSequence where matching takes longer than the configured timeout — long inputs with backtracking-prone patterns (nested quantifiers, alternation overlap).

Common situations: User-supplied or LLM-generated regexes with catastrophic backtracking; unexpectedly large input strings after a data change; a timeout set too low for legitimate workloads.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/1abb88ad71789c7d. Report an issue: GitHub.