can1357/oh-my-pi · error · ToolError
Grep timed out after ${SEARCH_GREP_TIMEOUT_MS / 1000}s; narr
Error message
Grep timed out after ${SEARCH_GREP_TIMEOUT_MS / 1000}s; narrow paths or pattern, or scope with `glob` first What it means
The grep operation exceeded the fixed internal timeout (SEARCH_GREP_TIMEOUT_MS) — usually because the pattern or path scope caused a very large scan. The tool converts the abort into an actionable error suggesting you narrow paths or pattern, or pre-filter with the `glob` option.
Source
Thrown at packages/coding-agent/src/tools/grep.ts:1244
contextBefore: normalizedContextBefore,
contextAfter: normalizedContextAfter,
maxColumns: DEFAULT_MAX_COLUMN,
mode: effectiveOutputMode,
maxCountPerFile: nativeMaxCountPerFile,
signal,
timeoutMs: SEARCH_GREP_TIMEOUT_MS,
},
undefined,
);
skippedOversizedCount = result.skippedOversized ?? 0;
}
}
} catch (err) {
if (err instanceof Error && /^regex(?: parse)? error/i.test(err.message)) {
throw new ToolError(err.message.replace(/^regex(?: parse)? error:?\s*/i, "Invalid regex: "));
}
if (err instanceof Error && err.message.includes("Aborted: Timeout")) {
throw new ToolError(
`Grep timed out after ${SEARCH_GREP_TIMEOUT_MS / 1000}s; narrow paths or pattern, or scope with \`glob\` first`,
);
}
throw err;
}
let virtualResult: GrepResult;
try {
virtualResult = await searchVirtualResources(
virtualResources,
normalizedPattern,
ignoreCase,
effectiveMultiline,
normalizedContextBefore,
normalizedContextAfter,
INTERNAL_TOTAL_CAP,
signal,
);
} catch (err) {View on GitHub (pinned to 9690622007)
Solutions
- Narrow `path` to the specific directory or files you care about
- Add a `glob` filter (e.g. "*.ts") to skip irrelevant files before scanning
- Make the pattern more specific (anchor it, add required literals) instead of broad wildcards
Example fix
// before
await grep({ pattern: "config", path: "." });
// after
await grep({ pattern: "config", path: "src", glob: "*.ts" }); Defensive patterns
Strategy: fallback
Try / catch
try {
return await grep({ pattern, path: "." });
} catch (err) {
if (err instanceof ToolError && err.message.startsWith("Grep timed out")) {
return await grep({ pattern, path: "src", glob: "*.ts" }); // narrower retry
} else throw err;
} Prevention
- Always scope large-repo searches with path and/or glob (exclude node_modules, dist)
- Prefer specific anchored patterns over broad wildcards to cut scan cost
When it happens
Trigger: grep over a huge directory tree (node_modules, dist, monorepo root) with a broad pattern like "e" or ".*"; pathological regex causing heavy backtracking over many files.
Common situations: Forgetting to exclude build/vendor directories in a large repo; searching the workspace root instead of a subdirectory; regex quantifier nesting that scales badly.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Browser open timed out after ${timeoutMs}ms
- timed out: {command}
- AnthropicConnectionTimeoutError
- Kimi device flow timed out
- xAI device-code request failed: ${error instanceof Error ? e
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/38860261c031184c.
Report an issue: GitHub.