Skip to content

Honor view_file line range and cap result size - #303

Merged
zbl94 merged 2 commits into
mainfrom
fix-view-file-line-range
Jul 15, 2026
Merged

Honor view_file line range and cap result size#303
zbl94 merged 2 commits into
mainfrom
fix-view-file-line-range

Conversation

@zbl94

@zbl94 zbl94 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

execViewFile read the whole file and ignored the agent's StartLine/EndLine, so viewing a large file returned its entire content as the tool result -- a ~900KB blob for a 3k-line CSV stalled the following turn.

Implement the Antigravity view_file contract (1-indexed inclusive line range with slice-notation windowing) plus defensive caps:

  • StartLine/EndLine window (neither=first N lines; start-only=next N forward; end-only=previous N backward; both=precise range, capped to N).
  • viewFileMaxLines / viewFileMaxBytes caps so a large file can never blob.

Adds intArg/intArgOK helpers and tests for windowing, byte cap + offset resume, and range honoring.

@zbl94
zbl94 force-pushed the fix-view-file-line-range branch from 80a7415 to 75efc73 Compare July 14, 2026 18:40
@zbl94
zbl94 requested review from joycel-github and wjjclaud July 14, 2026 18:45

@wjjclaud wjjclaud left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where next_content_offset is reported. Is this intentional?

@zbl94

zbl94 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

I don't see where next_content_offset is reported. Is this intentional?

It turns out that this field, next_content_offset was just came up with by the coding LLM. It may not be consumed by the interactions API. I asked it to remove. Updated the PR description as well.

@zbl94
zbl94 requested a review from wjjclaud July 14, 2026 22:18
Comment thread internal/harness/antigravityinteractions/antigravityinteractions_tools.go Outdated
execViewFile read the whole file and ignored the agent's StartLine/EndLine,
so viewing a large file returned its entire content as the tool result --
a ~900KB blob for a 3k-line CSV stalled the following turn.

Implement the Antigravity view_file contract (1-indexed inclusive line range
with slice-notation windowing) plus defensive caps:
- StartLine/EndLine window (neither=first N lines; start-only=next N forward;
  end-only=previous N backward; both=precise range, capped to N).
- viewFileMaxLines / viewFileMaxBytes caps so a large file can never blob.
- ContentOffset honored as the read position within the windowed content.

The result payload is just {"content": ...}; the view_file result schema is
defined server-side, so no extra fields are added.

Adds intArg/intArgOK helpers and tests for windowing, byte cap, offset read,
and range honoring.
@zbl94
zbl94 force-pushed the fix-view-file-line-range branch 4 times, most recently from 623c592 to a5acabf Compare July 15, 2026 07:52
@zbl94
zbl94 requested a review from joycel-github July 15, 2026 08:00
Address review feedback on the byte cap:

- applyByteWindow backs the cut off to the last complete UTF-8 rune so a
  multi-byte character straddling viewFileMaxBytes is never split (raw byte
  slicing could produce invalid UTF-8, corrupting the last char and JSON
  serialization).
- execViewFile returns the metadata the server needs to distinguish a
  complete read from a paginated/byte-truncated one: content, start_line/
  end_line (0-indexed inclusive served range), content_offset,
  line_range_bytes (total bytes of the line range pre-byte-cap), and
  num_lines/num_bytes. The server detects truncation via
  content_offset+len(content) < line_range_bytes and prompts the model to
  resume from that offset.

A paired server change reads these fields instead of hardcoding
start_line=0/end_line=last.

Adds tests for UTF-8 boundary capping, pagination metadata, and resume.
@zbl94
zbl94 force-pushed the fix-view-file-line-range branch from a5acabf to 1d44229 Compare July 15, 2026 08:03
@zbl94
zbl94 merged commit 06f88c2 into main Jul 15, 2026
9 checks passed
rakyll pushed a commit that referenced this pull request Jul 21, 2026
The dummyAgent test fixture defined a HealthCheck method that was never
part of the agent.Agent interface and had no callers. Remove it so the
fixture matches the actual interface (Connect, Close) and nothing else.
rakyll pushed a commit that referenced this pull request Jul 21, 2026
* Honor view_file line range and cap result size

execViewFile read the whole file and ignored the agent's StartLine/EndLine,
so viewing a large file returned its entire content as the tool result --
a ~900KB blob for a 3k-line CSV stalled the following turn.

Implement the Antigravity view_file contract (1-indexed inclusive line range
with slice-notation windowing) plus defensive caps:
- StartLine/EndLine window (neither=first N lines; start-only=next N forward;
  end-only=previous N backward; both=precise range, capped to N).
- viewFileMaxLines / viewFileMaxBytes caps so a large file can never blob.
- ContentOffset honored as the read position within the windowed content.

The result payload is just {"content": ...}; the view_file result schema is
defined server-side, so no extra fields are added.

Adds intArg/intArgOK helpers and tests for windowing, byte cap, offset read,
and range honoring.

* view_file: UTF-8-safe byte cap + pagination metadata

Address review feedback on the byte cap:

- applyByteWindow backs the cut off to the last complete UTF-8 rune so a
  multi-byte character straddling viewFileMaxBytes is never split (raw byte
  slicing could produce invalid UTF-8, corrupting the last char and JSON
  serialization).
- execViewFile returns the metadata the server needs to distinguish a
  complete read from a paginated/byte-truncated one: content, start_line/
  end_line (0-indexed inclusive served range), content_offset,
  line_range_bytes (total bytes of the line range pre-byte-cap), and
  num_lines/num_bytes. The server detects truncation via
  content_offset+len(content) < line_range_bytes and prompts the model to
  resume from that offset.

A paired server change reads these fields instead of hardcoding
start_line=0/end_line=last.

Adds tests for UTF-8 boundary capping, pagination metadata, and resume.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants