Skip to content

fix(sdk): read_file pagination skipping lines after wrapping - #3641

Merged
Mason Daugherty (mdrxy) merged 4 commits into
mainfrom
mdrxy/sdk/fix-pagination-numbers
May 27, 2026
Merged

fix(sdk): read_file pagination skipping lines after wrapping#3641
Mason Daugherty (mdrxy) merged 4 commits into
mainfrom
mdrxy/sdk/fix-pagination-numbers

Conversation

@mdrxy

Copy link
Copy Markdown
Member

Closes #2453


read_file applies row-based truncation twice: once when the backend slices raw lines by offset/limit, then again after format_content_with_line_numbers wraps long lines into continuation rows. When a wrapped line inflates the row count past limit, real source lines fall off the page — and the next page resumes from offset + limit, skipping them entirely.

_truncate now takes the row-based limit as optional. The new-style ReadResult path (the backend has already paginated by source lines) drops the row chop and keeps only the byte-budget cap. The legacy str backend path keeps the row-based behavior, since those backends still format with line numbers inline.

limit now bounds source lines, not formatted rows — a wrapped 15k-char line with limit=3 renders all of its continuation chunks alongside the surrounding source lines instead of silently dropping the tail. The read_file tool description is updated to match.

Carries forward the fix originally proposed in #2452 by Farri Mohajerani (@farrimoh); that PR was closed and could not be reopened, so the patch was rewritten against current main with farrimoh credited as a co-author on the commit.

Co-authored-by: farrimoh <farri.mohajerani@gmail.com>
@github-actions github-actions Bot added deepagents Related to the `deepagents` SDK / agent harness fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: S 50-199 LOC labels May 27, 2026
@mdrxy
Mason Daugherty (mdrxy) merged commit 390551d into main May 27, 2026
43 checks passed
@mdrxy
Mason Daugherty (mdrxy) deleted the mdrxy/sdk/fix-pagination-numbers branch May 27, 2026 21:02
Mason Daugherty (mdrxy) added a commit that referenced this pull request May 28, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Everything below this line will be the GitHub release body._

---


##
[0.6.5](deepagents==0.6.4...deepagents==0.6.5)
(2026-05-28)

### Features

* `RubricMiddleware` for self-evaluated agent iteration
([#3529](#3529))
([5b8d44d](5b8d44d))
* Log when grep falls back from ripgrep
([#3593](#3593))
([379b1ff](379b1ff))

### Bug Fixes

* Use `file_path` kwarg in `read_file` examples
([#3630](#3630))
([97946ee](97946ee))
* `read_file` pagination skipping lines after wrapping
([#3641](#3641))
([390551d](390551d))
* Handle `None` state in messages delta reducer
([#3636](#3636))
([5a6d920](5a6d920))
* Return grep errors for sandbox exec failures
([#3637](#3637))
([f87d61f](f87d61f))

---

_Everything above this line will be the GitHub release body._

---

> [!NOTE]
> A **New Contributors** section is appended to the GitHub release notes
automatically at publish time (see [Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 2).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mason Daugherty <github@mdrxy.com>
Marcelo5444 pushed a commit to Marcelo5444/deepagents that referenced this pull request Jul 30, 2026
…hain-ai#3641)

Closes langchain-ai#2453

---

`read_file` applies row-based truncation twice: once when the backend
slices raw lines by `offset`/`limit`, then again after
`format_content_with_line_numbers` wraps long lines into continuation
rows. When a wrapped line inflates the row count past `limit`, real
source lines fall off the page — and the next page resumes from `offset
+ limit`, skipping them entirely.

`_truncate` now takes the row-based limit as optional. The new-style
`ReadResult` path (the backend has already paginated by source lines)
drops the row chop and keeps only the byte-budget cap. The legacy `str`
backend path keeps the row-based behavior, since those backends still
format with line numbers inline.

`limit` now bounds *source* lines, not formatted rows — a wrapped
15k-char line with `limit=3` renders all of its continuation chunks
alongside the surrounding source lines instead of silently dropping the
tail. The `read_file` tool description is updated to match.

Carries forward the fix originally proposed in langchain-ai#2452 by @farrimoh; that
PR was closed and could not be reopened, so the patch was rewritten
against current `main` with farrimoh credited as a co-author on the
commit.

---------

Co-authored-by: farrimoh <farri.mohajerani@gmail.com>
Marcelo5444 pushed a commit to Marcelo5444/deepagents that referenced this pull request Jul 30, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Everything below this line will be the GitHub release body._

---


##
[0.6.5](langchain-ai/deepagents@deepagents==0.6.4...deepagents==0.6.5)
(2026-05-28)

### Features

* `RubricMiddleware` for self-evaluated agent iteration
([langchain-ai#3529](langchain-ai#3529))
([5b8d44d](langchain-ai@5b8d44d))
* Log when grep falls back from ripgrep
([langchain-ai#3593](langchain-ai#3593))
([379b1ff](langchain-ai@379b1ff))

### Bug Fixes

* Use `file_path` kwarg in `read_file` examples
([langchain-ai#3630](langchain-ai#3630))
([97946ee](langchain-ai@97946ee))
* `read_file` pagination skipping lines after wrapping
([langchain-ai#3641](langchain-ai#3641))
([390551d](langchain-ai@390551d))
* Handle `None` state in messages delta reducer
([langchain-ai#3636](langchain-ai#3636))
([5a6d920](langchain-ai@5a6d920))
* Return grep errors for sandbox exec failures
([langchain-ai#3637](langchain-ai#3637))
([f87d61f](langchain-ai@f87d61f))

---

_Everything above this line will be the GitHub release body._

---

> [!NOTE]
> A **New Contributors** section is appended to the GitHub release notes
automatically at publish time (see [Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 2).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mason Daugherty <github@mdrxy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepagents Related to the `deepagents` SDK / agent harness fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read_file pagination skips lines after wrapping due to double limit application

1 participant