phacility/phabricator · warning · PhutilSearchQueryCompilerSyntaxException

Query is too long (%s bytes, maximum is %s bytes).

Error message

Query is too long (%s bytes, maximum is %s bytes).

What it means

Phabricator's search query compiler (PhutilSearchQueryCompiler, used by Ferret full-text search and all `*.search` query fields) refuses to tokenize queries longer than 1024 bytes before doing any parsing. The hard cap exists because every token is compiled into an SQL fulltext/ferret query, and unbounded queries would produce enormous SQL. The thrown type is PhutilSearchQueryCompilerSyntaxException.

Source

Thrown at src/applications/search/compiler/PhutilSearchQueryCompiler.php:112

    $results = $this->tokenizeQuery($query);

    $tokens = array();
    foreach ($results as $result) {
      $tokens[] = PhutilSearchQueryToken::newFromDictionary($result);
    }

    return $tokens;
  }

  private function tokenizeQuery($query) {
    $maximum_bytes = 1024;

    if ($query === null) {
      $query = '';
    }
    $query_bytes = strlen($query);
    if ($query_bytes > $maximum_bytes) {
      throw new PhutilSearchQueryCompilerSyntaxException(
        pht(
          'Query is too long (%s bytes, maximum is %s bytes).',
          new PhutilNumber($query_bytes),
          new PhutilNumber($maximum_bytes)));
    }

    $query = phutil_utf8v($query);
    $length = count($query);

    $enable_functions = $this->getEnableFunctions();

    $mode = 'scan';
    $current_operator = array();
    $current_token = array();
    $current_function = null;
    $is_quoted = false;
    $tokens = array();

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Shorten the query to under 1024 bytes - split it into several narrower searches (one per project, author, or keyword set) instead of one giant term list.
  2. If you are calling the compiler programmatically, pre-check strlen($query) > 1024 and reject or truncate with a friendly message before calling compile*().
  3. For repeated bulk searching, switch to Conduit search methods with structured constraints (projects, statuses, authors) instead of one giant free-text blob.
  4. Do not raise the 1024-byte cap in the compiler - downstream SQL size limits are the reason it exists.

Example fix

// before
$compiled = $compiler->compileQuery($field, $query);

// after
if (strlen($query) > 1024) {
  throw new Exception('Search query too long; split it into multiple searches.');
}
$compiled = $compiler->compileQuery($field, $query);
Defensive patterns

Strategy: validation

Validate before calling

$MAX = 1024;
if (strlen($query) > $MAX) {
  return $this->newDialog()->setTitle(pht('Query Too Long'))
    ->appendParagraph(pht('Keep queries under %s bytes.', new PhutilNumber($MAX)));
}

Type guard

function isBoundedQuery($q, $max = 1024) { return is_string($q) && strlen($q) <= $max; }

Try / catch

try {
  $compiled = $compiler->compileQuery($field, $raw_query);
} catch (PhutilSearchQueryCompilerSyntaxException $ex) {
  // user input error: show message, keep the form populated
  $errors[] = $ex->getMessage();
}

Prevention

When it happens

Trigger: Calling compileQuery()/tokenizeQuery() (directly or via a search engine saving a query, e.g. Maniphest `query=...` saved search or Conduit `maniphest.query` with a long `query` parameter) with input whose strlen() exceeds 1024 bytes - e.g. pasting a stack trace, a paragraph of text, or hundreds of space-separated terms into the global search box and saving it as a named query.

Common situations: Users pasting logs/error text into the search box; scripts piping file contents as search terms through Conduit; saved queries that worked until the term list grew past the limit; multi-byte UTF-8 content (the limit is bytes, not characters, so CJK text hits it ~3x sooner).

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/d72533430d321b30. Report an issue: GitHub.