Files
deepagentsjs/libs/deepagents/src
thushanth-bengre-langchain 590c2a5042 fix(deepagents): prevent stack overflow in CompositeBackend grep/glob (#723)
## Summary

- Fixes `RangeError: Maximum call stack size exceeded` from
`CompositeBackend.glob`/`grep` when a broad search (e.g.
`**/*.{ts,tsx,...}` at `/`) returns hundreds of thousands of entries.
Root cause: results were merged with `push(...entries)`, which passes
each entry as a separate function argument and overflows V8's
argument-stack limit. Now accumulated with a plain loop.
- Ports the Python SDK's grep match-count cap (`ef591e7`): optional
`maxCount` backend param / `max_count` tool arg, `grepMaxCount`
middleware option (default 1000, `null` disables), `truncated` flag on
`GrepResult`/`GlobResult`, and a truncation note in the grep tool
output. `CompositeBackend` splits the budget across routes and
OR-propagates `truncated`.

## Backward compatibility

- `truncated` is optional; `maxCount` defaults to unset everywhere. No
required changes for existing or new users.

## Test plan

- [x] Regression test: mocked backend returning 200k entries —
`glob`/`grep` complete without `RangeError` (verified it fails with the
old spread).
- [x] Cap enforcement, `truncated` propagation across composite routes,
middleware note rendering.
- [x] `pnpm test` (format + lint + all lib tests) passes.
2026-08-04 11:27:03 -07:00
..
2026-01-09 15:10:42 -08:00
2026-01-09 15:10:42 -08:00