You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
code_search fails with exit 128 when a regex-mode search term contains an unbalanced parenthesis #1340
open-code-review v1.12.4 (f1101fd) darwin/arm64, built at 2026-09-16T09:58:39Z
Operating System
macOS (Apple Silicon)
Installation Method
npm (global)
LLM Provider
Other OpenAI-compatible endpoint
Bug Description
In regex mode (use_perl_regexp: true), code_search passes the model's search_text verbatim to git grep -P. A search term containing an unbalanced ( fails PCRE compilation, so the tool returns exit 128 instead of running the search.
Models search for literals like Set("gorm: when reviewing GORM code, so this comes up often. In one review run, 31 of 348 code_search calls failed this way (about 9%); in another, 11 of 236.
Steps to Reproduce
Run ocr review -f json --audience agent on a changeset that leads the model to search for a literal containing (. A Go codebase using GORM's db.Set("gorm:...") triggers it quickly.
Or run the underlying command directly, in any repo:
The same term under default BRE does not error, because a bare ( is a literal there. Only the -P path fails, and -P is what regex-mode code_search uses.
Expected Behavior
Either run the search as a literal match (for example fall back to git grep -F when the regex fails to compile), or validate the regex first and return an error the model can act on.
An AI coding agent working for me collected the failure counts from ocr's session logs. The reproduce command and its output above were run and verified directly in a terminal.
Additional Context
Failures return in milliseconds, so nothing stalls. The cost is one wasted agent round-trip per failure: the model retries with different terms or falls back to reading files chunk by chunk, which slows the review and weakens the search. Escaping all metacharacters is not a good fix, since regex mode is intentional and models pass alternations like a|b|c. Falling back to git grep -F on a compile error, and telling the model about the fallback, keeps both uses working. Related earlier git grep argument-handling bugs in code_search: #645, #53.
changed the title [-]code_search: 正则模式下含未闭合括号的搜索词使 git grep -P 直接 exit 128[/-][+]code_search fails with exit 128 when a regex-mode search term contains an unbalanced parenthesis[/+]on Sep 17, 2026
Opened #1351 for this. On the PCRE compile failure the search is retried as a fixed string with every other argument unchanged (case sensitivity, pathspec, ref, --untracked/--no-index), and the result opens with a note that repeats git's reason (missing closing parenthesis) so the model can escape the pattern if it really wanted a regex.
Two things the fix deliberately does not do: a pattern PCRE accepts is never retried, and failures that are not about the pattern (unresolvable ref, invalid pathspec) still return exactly the same error as before, because git diagnoses those before it compiles patterns.
Second reporter, on a different platform and a much later version. Still
reproduces on v1.13.8 (windows/amd64), and the current main still has no
retry on a PCRE compile failure — gitGrep in internal/tool/code_search.go
retries only on isNotGitRepoError (the --no-index path), so a rejected
pattern goes straight to git grep failed: exit status 128.
I note #1351 was closed without merging, so I assume the fix is still open for
whoever picks it up.
Independent data
A different corpus, collected from an automated review harness that invokes ocr review per run. 99 stored ocr.json manifests, 3,896 code_search calls,
24 failures (0.62%) — lower than your 9%, and the gap is itself informative:
these are mostly C#/TypeScript/Angular repositories rather than Go, so the rate
appears to track how often a language's idioms put a bare ( inside a search
literal, not anything about the harness.
20 of the 24 are the unbalanced-paren case you describe. The distinct rejected
patterns:
public Commit(
public GitHubCommit(
public GitHubCommitStats(
GitHubCommitStats(
GetValue(string
GetValue(string propertyName, StringComparison
WithNpm(bool
saveAction =|onSave(
cdkDropList|moveItemInArray|drop(
moveUp|moveDown|swap(|Up(index|Down(index
GetById|Show|Get(
ResolveStruct|ResolveText|Build(
login(authService
public.*class NhSetPropertyCalls|Apply(
new ContentBlockModels.StickySidebarLayoutContent|StickySidebarLayoutContent(
export abstract class NhBaseApiService|class BaseApiService|apiService.put<T|put<T>(
fake0001|recorder.SessionId ==|Equal(.*SessionId
changedProperties.Select(x =>|messageArguments: changedProperties
QueryExecutionException(.*ex\)
replace(/^www\./i
This supports the point in your Additional Context that blanket escaping is the
wrong fix: 10 of the 20 carry a deliberate | alternation, and two
(Equal(.*SessionId, QueryExecutionException(.*ex\)) use .* and an escaped
paren. The model wanted a regex; it just appended a trailing ( to a method
name. A -F retry preserves both intents, whereas escaping would break the
alternations.
A second failure class the same retry would cover
Four of my 24 are not unbalanced parens. Two are a different PCRE rejection:
[ocr] ✘ code_search failed: git grep failed: exit status 128:
fatal: -e option, '\u200d': PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u
[ocr] ✘ code_search failed: git grep failed: exit status 128:
fatal: -e option, 'C\u200dursor': PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u
The model was searching for a zero-width joiner by its JavaScript/C# escape
form, \u200d. PCRE2 spells that \x{200d}, so the pattern is rejected at
compile time exactly like an unbalanced paren — same exit 128, same -e option
prefix, same wasted round trip. A literal retry handles it correctly too, since \u200d as a fixed string is what a model looking for the characters \u200d
in source would usually want anyway.
Worth mentioning because a fix scoped narrowly to paren balancing would miss it,
whereas "retry as -F when PCRE rejects the pattern" catches both without
enumerating PCRE's rules.
Impact in an automated setting
Agreeing with your framing and adding one consequence specific to unattended use.
These reviews run under a fixed per-review time cap. A wasted round trip is not
just slower — it competes directly with coverage, and a review that reaches the
cap is reported as partial. In the day I looked at most closely, 5 of 17
reviews ended partial with at least one file receiving no verdict at all. I
cannot attribute those caps to code_search failures specifically, and I am not
claiming that: at 0.62% the direct time cost is small, and the honest statement
is that the failures and the caps coexist rather than that one caused the other.
The clearer cost is the one you already named: the model loses its best search
tool for that turn and falls back to reading files, which is more expensive in
both tokens and wall clock than the fix would be.
Resolved by #1811, which implements the actionable-error option from this report. An invalid regex still fails, but the diagnostic now explains how to escape a literal parenthesis or set use_perl_regexp=false if the whole search term is literal. There is no automatic fallback. Regression tests verify that correcting the parenthesis preserves intended alternation and wildcard matches. Thanks for the examples and failure data.
I hit the same class of failure with \u00A0 on OpenCodeReview v1.14.4 (d4f568f, Linux amd64) and Git 2.47.3. In this run, OCR exited nonzero and our review service marked the entire review as failed.
Redacted production log (retry guidance omitted):
ERROR [REDACTED] OCR review failed (no fallback): OCR review failed: [ocr] code_search failed: git grep failed: exit status 128: fatal: -e option, '\u00A0': PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u
To reproduce the underlying Git error, run this from a repository root, using any existing text file in place of README.md:
I reproduced exit 128 in the affected container. The review invocation was ocr review --from <base> --to HEAD --format json --audience agent. The trigger during the review is a code_search call with arguments like these:
{"search_text":"\\u00A0","use_perl_regexp":true}
The Git command isolates the search error. Reproducing the full review failure also requires the model to issue that tool call. The retry hint added by #1811 was present in the production log, but OCR still exited nonzero in this run. Could this pattern error be returned to the model as a recoverable tool result so it can retry and finish the review?
Activity
[-]code_search: 正则模式下含未闭合括号的搜索词使 git grep -P 直接 exit 128[/-][+]code_search fails with exit 128 when a regex-mode search term contains an unbalanced parenthesis[/+]LiRunGuo commentedon Sep 17, 2026
Opened #1351 for this. On the PCRE compile failure the search is retried as a fixed string with every other argument unchanged (case sensitivity, pathspec, ref,
--untracked/--no-index), and the result opens with a note that repeats git's reason (missing closing parenthesis) so the model can escape the pattern if it really wanted a regex.Two things the fix deliberately does not do: a pattern PCRE accepts is never retried, and failures that are not about the pattern (unresolvable ref, invalid pathspec) still return exactly the same error as before, because git diagnoses those before it compiles patterns.
sommmen commentedon Nov 17, 2026
Second reporter, on a different platform and a much later version. Still
reproduces on
v1.13.8(windows/amd64), and the currentmainstill has noretry on a PCRE compile failure —
gitGrepininternal/tool/code_search.goretries only on
isNotGitRepoError(the--no-indexpath), so a rejectedpattern goes straight to
git grep failed: exit status 128.I note #1351 was closed without merging, so I assume the fix is still open for
whoever picks it up.
Independent data
A different corpus, collected from an automated review harness that invokes
ocr reviewper run. 99 storedocr.jsonmanifests, 3,896code_searchcalls,24 failures (0.62%) — lower than your 9%, and the gap is itself informative:
these are mostly C#/TypeScript/Angular repositories rather than Go, so the rate
appears to track how often a language's idioms put a bare
(inside a searchliteral, not anything about the harness.
20 of the 24 are the unbalanced-paren case you describe. The distinct rejected
patterns:
This supports the point in your Additional Context that blanket escaping is the
wrong fix: 10 of the 20 carry a deliberate
|alternation, and two(
Equal(.*SessionId,QueryExecutionException(.*ex\)) use.*and an escapedparen. The model wanted a regex; it just appended a trailing
(to a methodname. A
-Fretry preserves both intents, whereas escaping would break thealternations.
A second failure class the same retry would cover
Four of my 24 are not unbalanced parens. Two are a different PCRE rejection:
The model was searching for a zero-width joiner by its JavaScript/C# escape
form,
\u200d. PCRE2 spells that\x{200d}, so the pattern is rejected atcompile time exactly like an unbalanced paren — same exit 128, same
-e optionprefix, same wasted round trip. A literal retry handles it correctly too, since
\u200das a fixed string is what a model looking for the characters\u200din source would usually want anyway.
Worth mentioning because a fix scoped narrowly to paren balancing would miss it,
whereas "retry as
-Fwhen PCRE rejects the pattern" catches both withoutenumerating PCRE's rules.
Impact in an automated setting
Agreeing with your framing and adding one consequence specific to unattended use.
These reviews run under a fixed per-review time cap. A wasted round trip is not
just slower — it competes directly with coverage, and a review that reaches the
cap is reported as
partial. In the day I looked at most closely, 5 of 17reviews ended
partialwith at least one file receiving no verdict at all. Icannot attribute those caps to
code_searchfailures specifically, and I am notclaiming that: at 0.62% the direct time cost is small, and the honest statement
is that the failures and the caps coexist rather than that one caused the other.
The clearer cost is the one you already named: the model loses its best search
tool for that turn and falls back to reading files, which is more expensive in
both tokens and wall clock than the fix would be.
Environment
@alibaba-group/open-code-review1.13.8 (win32-x64 native binary)mainstill lacks the retryocr review --from <sha> --to <sha> …, non-interactiveocr.jsonmanifests'tool_calls.failure_detailslizhengfeng101 commentedon Nov 24, 2026
Resolved by #1811, which implements the actionable-error option from this report. An invalid regex still fails, but the diagnostic now explains how to escape a literal parenthesis or set
use_perl_regexp=falseif the whole search term is literal. There is no automatic fallback. Regression tests verify that correcting the parenthesis preserves intended alternation and wildcard matches. Thanks for the examples and failure data.lee259 commentedon Nov 26, 2026
I hit the same class of failure with
\u00A0on OpenCodeReview v1.14.4 (d4f568f, Linux amd64) and Git 2.47.3. In this run, OCR exited nonzero and our review service marked the entire review as failed.Redacted production log (retry guidance omitted):
To reproduce the underlying Git error, run this from a repository root, using any existing text file in place of
README.md:I reproduced exit 128 in the affected container. The review invocation was
ocr review --from <base> --to HEAD --format json --audience agent. The trigger during the review is acode_searchcall with arguments like these:{"search_text":"\\u00A0","use_perl_regexp":true}The Git command isolates the search error. Reproducing the full review failure also requires the model to issue that tool call. The retry hint added by #1811 was present in the production log, but OCR still exited nonzero in this run. Could this pattern error be returned to the model as a recoverable tool result so it can retry and finish the review?