SIGN IN SIGN UP

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.
T
thushanth-bengre-langchain committed
590c2a5042473f096d5fac5ddbb4be96e2ace0f2
Parent: 064b172
Committed by GitHub <noreply@github.com> on 8/4/2026, 6:27:03 PM