# Fix nested request rate limiting deadlock for subagent edit_file \(\#47232\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/21050e2d372b358357c62ee242c16c454b0a2813)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 21050e2d372b358357c62ee242c16c454b0a2813

Requested commit: 21050e2d372b358357c62ee242c16c454b0a2813

Commit: 21050e2d372b358357c62ee242c16c454b0a2813

Tree: d654aa916041d7de1e2fcc71642e6d87813db870

Author: Richard Feldman

Committer: GitHub

## Message

```
Fix nested request rate limiting deadlock for subagent edit_file (#47232)

## Problem

When subagents use the `edit_file` tool, it creates an `EditAgent` that
makes its own model request to get the edit instructions. These "nested"
requests compete with the parent subagent conversation requests for rate
limiter permits.

The rate limiter uses a semaphore with a limit of 4 concurrent requests
per model instance. When multiple subagents run in parallel:

1. 3 subagents each hold 1 permit for their ongoing conversation streams
(3 permits used)
2. When all 3 try to use `edit_file` simultaneously, their edit agents
need permits too
3. Only 1 edit agent can get the 4th permit; the other 2 block waiting
4. The blocked edit agents can't complete, so their parent subagent
conversations can't complete
5. The parent conversations hold their permits, so the blocked edit
agents stay blocked
6. **Deadlock**

## Solution

Added a `bypass_rate_limit` field to `LanguageModelRequest`. When set to
`true`, the request skips the rate limiter semaphore entirely. The
`EditAgent` sets this flag because its requests are already "part of" a
rate-limited parent request.

(No release notes because subagents are still feature-flagged.)

Release Notes:
- N/A

---------

Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
```

## Parents

- [ff35da22fbe67a65632a8009827f114262c76e4d](https://git.cafe/gitcafe/zed/commit/ff35da22fbe67a65632a8009827f114262c76e4d?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/21050e2d372b358357c62ee242c16c454b0a2813?format=markdown)
