openclaw - ✅(Solved) Fix [Bug] read tool allows offset beyond file length causing crash [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#62466Fetched 2026-04-08 03:03:55
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Timeline (top)
cross-referenced ×2referenced ×2

Error Message

  • Tool returns error instead of graceful truncation

Fix Action

Fixed

PR fix notes

PR #62491: fix(read): gracefully clamp offset beyond EOF instead of crashing

Description (problem / solution / changelog)

Summary

Fixes #62466.

When the read tool is called with an offset that exceeds the file's actual line count, the upstream @mariozechner/pi-coding-agent library throws:

Offset 1830 is beyond end of file (1829 lines total).

This error was never caught by openclaw's wrapper, so the tool call failed entirely instead of returning a graceful result.

Changes

  • src/agents/pi-tools.read.ts — added parseOffsetBeyondEofTotalLines helper that parses the upstream error message, then added try/catch in both call sites inside executeReadWithAdaptivePaging:

    • hasExplicitLimit path (line ~228): catches the error, clamps offset to totalLines, retries once.
    • adaptive paging loop (line ~253): same on page 0 (user-supplied offset); on page > 0 (mid-pagination EOF) returns the content aggregated so far instead of crashing.
    • Also removes a pre-existing unnecessary String() cast flagged by the linter.
  • src/agents/pi-tools.read.offset-beyond-eof.test.ts — new test file with 4 cases:

    1. offset = fileLines + 1 → resolves, returns content from last line
    2. offset far beyond EOF → resolves, returns content from last line
    3. Empty file + offset > 0 → resolves gracefully (upstream returns empty content, not an error)
    4. Explicit limit + offset beyond EOF → resolves, returns content from last line

Test plan

  • All 4 new tests pass: npx vitest run src/agents/pi-tools.read.offset-beyond-eof.test.ts --config vitest.agents.config.ts
  • No regressions in the full agents suite (pre-existing failures are unrelated to this change)

🤖 Generated with Claude Code

Changed files

  • src/agents/pi-tools.read.offset-beyond-eof.test.ts (added, +108/-0)
  • src/agents/pi-tools.read.ts (modified, +43/-3)

PR #62504: fix: read tool without path now returns explicit error

Description (problem / solution / changelog)

Summary

This PR fixes #62462 by preventing silent success when the read tool is invoked without a required path.

Changes

  • Convert warning-only missing-path handling in embedded read-tool start flow into an explicit required-parameter error.
  • Update handler tests to assert failure semantics for missing path.
  • Add a regression test for wrapped read-tool execution when path is missing.

Validation

  • node scripts/run-vitest.mjs run --config vitest.config.ts src/agents/pi-tools.create-openclaw-coding-tools.adds-claude-style-aliases-schemas-without-dropping-g.test.ts src/agents/pi-embedded-subscribe.handlers.tools.test.ts
  • pnpm -s vitest run src/agents/pi-tools.params.test.ts
  • pnpm -s vitest run src/agents/pi-tool-definition-adapter.after-tool-call.fires-once.test.ts src/agents/pi-embedded-subscribe.handlers.tools.media.test.ts src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.calls-onblockreplyflush-before-tool-execution-start-preserve.test.ts

Notes

Repository-wide lint/build checks in this branch baseline currently fail due unrelated pre-existing issues.

Changed files

  • src/agents/pi-embedded-subscribe.handlers.tools.test.ts (modified, +5/-5)
  • src/agents/pi-embedded-subscribe.handlers.tools.ts (modified, +9/-4)
  • src/agents/pi-tools.create-openclaw-coding-tools.adds-claude-style-aliases-schemas-without-dropping-g.test.ts (modified, +76/-0)
  • src/agents/pi-tools.read.ts (modified, +74/-3)

Code Example

[tools] read failed: Offset 1830 is beyond end of file (1829 lines total) raw_params={"offset":1830,"limit":20,"file_path":"/Users/jayden/.openclaw/workspace/AUDIT_LEDGER.md"}
RAW_BUFFERClick to expand / collapse

Bug Description

The read tool accepts an offset parameter that exceeds the file's actual line count, causing the tool to fail with 'Offset X is beyond end of file'.

Log Evidence

[tools] read failed: Offset 1830 is beyond end of file (1829 lines total) raw_params={"offset":1830,"limit":20,"file_path":"/Users/jayden/.openclaw/workspace/AUDIT_LEDGER.md"}

Impact

  • Tool returns error instead of graceful truncation
  • No automatic truncation to max available offset

Suggested Fix

  • When offset > file length, truncate to last line instead of failing
  • Or: auto-adjust offset to max available

extent analysis

TL;DR

Truncating the offset to the last line of the file or auto-adjusting it to the maximum available offset can resolve the issue.

Guidance

  • Verify the file's line count before attempting to read from it to ensure the offset is within bounds.
  • Consider implementing a check to truncate the offset to the last line of the file when it exceeds the file's length.
  • Auto-adjusting the offset to the maximum available offset is another viable solution to prevent the tool from failing.
  • Review the tool's documentation to ensure it clearly communicates the expected behavior when the offset exceeds the file's length.

Example

def read_file(file_path, offset, limit):
    with open(file_path, 'r') as file:
        lines = file.readlines()
        max_offset = len(lines) - 1
        if offset > max_offset:
            offset = max_offset
        # proceed with reading the file from the adjusted offset

Notes

The suggested fix assumes that the tool is designed to read files line by line. If the tool uses a different reading mechanism, the solution may need to be adjusted accordingly.

Recommendation

Apply a workaround by truncating the offset to the last line of the file or auto-adjusting it to the maximum available offset, as this approach ensures the tool's functionality is preserved even when the provided offset exceeds the file's length.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING