{"record":{"id":"d72533430d321b30","repo":"phacility/phabricator","slug":"query-is-too-long-s-bytes-maximum-is-s-bytes","errorCode":null,"errorMessage":"Query is too long (%s bytes, maximum is %s bytes).","messagePattern":"Query is too long \\((.+?) bytes, maximum is (.+?) bytes\\)\\.","errorType":"validation","errorClass":"PhutilSearchQueryCompilerSyntaxException","httpStatus":null,"severity":"warning","filePath":"src/applications/search/compiler/PhutilSearchQueryCompiler.php","lineNumber":112,"sourceCode":"    $results = $this->tokenizeQuery($query);\n\n    $tokens = array();\n    foreach ($results as $result) {\n      $tokens[] = PhutilSearchQueryToken::newFromDictionary($result);\n    }\n\n    return $tokens;\n  }\n\n  private function tokenizeQuery($query) {\n    $maximum_bytes = 1024;\n\n    if ($query === null) {\n      $query = '';\n    }\n    $query_bytes = strlen($query);\n    if ($query_bytes > $maximum_bytes) {\n      throw new PhutilSearchQueryCompilerSyntaxException(\n        pht(\n          'Query is too long (%s bytes, maximum is %s bytes).',\n          new PhutilNumber($query_bytes),\n          new PhutilNumber($maximum_bytes)));\n    }\n\n    $query = phutil_utf8v($query);\n    $length = count($query);\n\n    $enable_functions = $this->getEnableFunctions();\n\n    $mode = 'scan';\n    $current_operator = array();\n    $current_token = array();\n    $current_function = null;\n    $is_quoted = false;\n    $tokens = array();\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/search/compiler/PhutilSearchQueryCompiler.php#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["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.","If you are calling the compiler programmatically, pre-check strlen($query) > 1024 and reject or truncate with a friendly message before calling compile*().","For repeated bulk searching, switch to Conduit search methods with structured constraints (projects, statuses, authors) instead of one giant free-text blob.","Do not raise the 1024-byte cap in the compiler - downstream SQL size limits are the reason it exists."],"exampleFix":"// before\n$compiled = $compiler->compileQuery($field, $query);\n\n// after\nif (strlen($query) > 1024) {\n  throw new Exception('Search query too long; split it into multiple searches.');\n}\n$compiled = $compiler->compileQuery($field, $query);","handlingStrategy":"validation","validationCode":"$MAX = 1024;\nif (strlen($query) > $MAX) {\n  return $this->newDialog()->setTitle(pht('Query Too Long'))\n    ->appendParagraph(pht('Keep queries under %s bytes.', new PhutilNumber($MAX)));\n}","typeGuard":"function isBoundedQuery($q, $max = 1024) { return is_string($q) && strlen($q) <= $max; }","tryCatchPattern":"try {\n  $compiled = $compiler->compileQuery($field, $raw_query);\n} catch (PhutilSearchQueryCompilerSyntaxException $ex) {\n  // user input error: show message, keep the form populated\n  $errors[] = $ex->getMessage();\n}","preventionTips":["Show a live byte counter on long custom query inputs","Pre-trim pasted text; strip newlines from pasted logs before they reach search","Remember the limit is bytes - warn earlier for CJK/UTF-8 content"],"tags":["phabricator","search","query-length","ferret","validation"],"backgroundTag":"query-length-limit-exceeded","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}