Repository navigation
feat(opencode): add offset/limit paging to webfetch - #208
Conversation
Co-authored-by: arena-agent <[email protected]>
| let bytes = 0 | ||
| let cut = false | ||
| for (const line of lines.slice(start)) { | ||
| if (page.length >= limit) break |
There was a problem hiding this comment.
SUGGESTION: limit: 0 yields an empty window with a self-referential continuation notice
limit is NonNegativeInt, so limit: 0 passes validation. The page.length >= limit check breaks on the first iteration, leaving page empty, so last becomes offset - 1 and next becomes offset. The emitted notice reads e.g. "(Showing lines 2-1 of 5. Use offset=2 to continue.)" — a reversed range that instructs the model to re-issue the exact call it just made, which can loop tool calls until the turn budget is exhausted. Consider requiring limit >= 1 (e.g. PositiveInt, or normalizing 0 to 1 alongside the params.offset || 1 coercion). Note read.ts's lines helper has the same edge case, so fixing both tools together keeps their paging semantics aligned.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (3 files)
Fix these issues in Kilo Cloud Previous Review Summaries (3 snapshots, latest commit 6ae26bf)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 6ae26bf)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (3 files)
Fix these issues in Kilo Cloud Previous review (commit 7b73bab)Status: No Issues Found | Recommendation: Merge Files Reviewed (5 files)
Previous reviewStatus: 1 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (5 files)
Reviewed by free · Input: 173.5K · Output: 21.3K · Cached: 14.3K |
- When a window truncates, spill the full converted body through the truncate service like the generic tool wrapper used to, set metadata.outputPath when it was saved, and mention the saved path after the continuation notice. The default (no offset/limit) path is unchanged. - Normalise offset/limit 0 to 1 at runtime; `limit: 0` no longer emits a reversed, self-referential notice. - Report an out-of-range offset as a typed ToolFailure from outside the Effect.orDie boundary instead of dying as a defect. - Split converted lines on /\r?\n/ so CRLF bodies do not keep a trailing \r. - Add tests for the clamp, CRLF bodies, empty bodies with an explicit offset, an offset on the last line, byte-cap resume over mixed long and short lines, and outputPath on a truncated fetch. Co-authored-by: arena-agent <[email protected]>
|
Review fixes pushed in 7b73bab (same branch, PR updates in place). Per item:
New tests: zero-limit clamp, CRLF body, empty body with explicit Verification: |
…h windows - A window that fits webfetch's own line/byte budget now returns empty metadata, so the generic tool wrapper still re-truncates it when it exceeds configured `tool_output` caps. Reporting `truncated: false` previously short-circuited the wrapper and silently ignored those caps. - Reword the description: the converted body is saved when it exceeds the output caps, and the saved path is appended after the notice. - Test: with `tool_output.max_bytes` at 10 KB, a 38 KB window that fits the default caps is capped by the wrapper and yields outputPath. Co-authored-by: arena-agent <[email protected]>
|
Round-2 fixes pushed in 6ae26bf (same branch, PR updates in place):
Verification: |
| let bytes = 0 | ||
| let cut = false | ||
| for (const line of lines.slice(start)) { | ||
| if (page.length >= limit) break |
There was a problem hiding this comment.
WARNING: limit: 0 produces an empty window and a self-referential continuation notice.
limit is NonNegativeInt, so limit: 0 passes schema validation. In windowContent, the check if (page.length >= limit) break fires on the first iteration, leaving page empty. Then last = offset + page.length - 1 = offset - 1 and next = last + 1 = offset, so the notice reads e.g. "(Showing lines 2-1 of 5. Use offset=2 to continue.)" — a reversed range that instructs the model to re-issue the exact call it just made, which can loop tool calls until the turn budget is exhausted.
The Math.max(1, params.limit ?? DEFAULT_LIMIT) normalization at webfetch.ts:184 only clamps the low end for the call; it does not reject 0 at the schema level, so the bad value still reaches windowContent. Consider requiring limit >= 1 (e.g. PositiveInt, or normalizing 0 to 1 alongside the params.offset || 1 coercion). Note read.ts's lines helper has the same edge case, so fixing both tools together keeps their paging semantics aligned.
| if (page.length >= limit) break | |
| if (page.length >= limit) break |
| Math.max(1, params.limit ?? DEFAULT_LIMIT), | ||
| ) | ||
| if (!windowed.ok) return yield* Effect.fail(new ToolFailure({ message: windowed.message })) | ||
| if (!windowed.truncated && params.offset === undefined && params.limit === undefined) { |
There was a problem hiding this comment.
WARNING: Byte-only overflow is silently dropped when neither paging param is supplied.
The early-return at webfetch.ts:187 fires when !windowed.truncated && params.offset === undefined && params.limit === undefined. windowed.truncated is cut || more, where cut tracks the 50 KB byte cap and more tracks leftover lines. If the converted body exceeds 50 KB but fits in one page, cut is true and the early return is skipped — correct. But if the body exceeds 50 KB and the caller did not ask for paging, the early return still fires because more is false, so the wrapper never gets the full body to spill. The model then sees the raw converted output with no continuation notice and no saved-file path, and cannot page further without re-fetching.
The generic wrapper in tool.ts:140 only spills when metadata.truncated is undefined, so webfetch is the sole layer responsible for surfacing byte-cap overflow. Dropping that responsibility for the no-param case breaks the contract the PR description promises ("the converted body is saved to a file"). Guard should also require !cut, or move the byte-cap check before the early return.
| if (!windowed.truncated && params.offset === undefined && params.limit === undefined) { | |
| if (!windowed.truncated && params.offset === undefined && params.limit === undefined && !windowed.cut) |
- Move the offset/limit low-end clamp into `windowContent`, next to the loop
that relies on it, so a decoded 0 can never produce an empty reversed
window ("Showing lines 2-1 ... Use offset=2").
- Return `cut` and `more` from `windowContent` and gate the unchanged-body
fast path on both explicitly, so byte-cap-only overflow can never skip the
saved-file path and continuation notice.
- Regression tests: limit 0 with and without an offset, and a >50 KB body
fetched with no paging params that must spill and report the cap.
Co-authored-by: arena-agent <[email protected]>
|
Kilo Code bot warnings addressed in 8b400a2 (same branch). Two notes on what I found while fixing them: 1. 2. Byte-only overflow without paging params. The guard was already safe: Verification: PR body re-set on |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Issue for this PR
Closes #204
Type of change
What does this PR do?
webfetchreturned the whole converted page in one shot, so a model that wantedlines 4000-6000 of a long document had to re-fetch and re-convert it. It now takes
offset(1-indexed start line) andlimit(defaults to 2000, matchingread'sDEFAULT_READ_LIMIT) and windows the post-conversion content, so a line numbermeans the same thing for
text,markdown, andhtml.Windowed output ends with
read's continuation wording, e.g.(Showing lines 4000-6000 of 12000. Use offset=6001 to continue.), or the byte-capvariant
(Output capped at 50 KB. Showing lines ...). Lines longer than 2000 charsare clipped with the same suffix
readuses, and an offset past the end fails withOffset N is out of range for this content (M lines)as a normal tool failurerather than a defect.
Oversized output still reaches the model. When the window itself cuts content, the
full converted body is spilled through the truncate service and the saved path is
appended after the notice. When the window fits
webfetch's own budget but theresult is bigger than configured
tool_outputcaps, metadata is left empty so thegeneric tool wrapper still caps and saves it as before.
offset/limitstayNonNegativeIntfor parity withread;windowContentclamps their low end so
limit: 0yields a one-line window instead of an empty,reversed notice that asks for the same call again. Supplying neither parameter and
staying inside the caps returns the converted body byte-identically to before.
How did you verify your code works?
bun test test/tool/webfetch.test.ts test/tool/parameters.test.ts-> 81 pass(21 webfetch cases, including paging per format, offset-only defaulting, CRLF
bodies, empty bodies, byte-cap resume over mixed long/short lines,
limit: 0with and without an offset, a >50 KB body with no paging params, a tighter
configured
tool_output.max_bytes, andoutputPathon a truncated fetch).bun test test/tool/-> 505 pass. The 2 failures are pre-existing ondev(
taskwire-shape snapshot, background-subagent registry test); a third shelltest is flaky and passes in isolation.
packages/opencodetsc --noEmitandpackages/coretsgo --noEmitpass.Prettier clean, oxlint 0 errors.
Screenshots / recordings
Not a UI change.
Checklist