can1357/oh-my-pi · error · ValueError
Offset {start_line} is beyond end of output ({total_lines} l
Error message
Offset {start_line} is beyond end of output ({total_lines} lines) for {output_id} What it means
When `offset`/`limit` are used with `output()`, `offset` is a 1-based line number into the artifact. This ValueError is raised when the requested start line exceeds the artifact's total line count, i.e. you asked to start reading past the end of the file.
Source
Thrown at packages/coding-agent/src/eval/py/prelude.py:241
try:
selected_content = (
json.dumps(result_value, indent=2)
if result_value is not None
else "null"
)
except (TypeError, ValueError):
selected_content = str(result_value)
# Handle offset/limit
elif offset is not None or limit is not None:
start_line = max(1, offset or 1)
if start_line > total_lines:
_emit_status(
"output",
id=output_id,
error=f"Offset {start_line} beyond end ({total_lines} lines)",
)
raise ValueError(
f"Offset {start_line} is beyond end of output ({total_lines} lines) for {output_id}"
)
effective_limit = (
limit if limit is not None else total_lines - start_line + 1
)
end_line = min(total_lines, start_line + effective_limit - 1)
selected_lines = raw_lines[start_line - 1 : end_line]
selected_content = "\n".join(selected_lines)
range_info = {
"start_line": start_line,
"end_line": end_line,
"total_lines": total_lines,
}
# Strip ANSI codes if requested
if format == "stripped":
import reView on GitHub (pinned to 9690622007)
Solutions
- Check the artifact's `line_count` first (read it with `format="json"` and inspect `line_count`), then choose an offset within range.
- Clamp the offset: `offset = min(offset, total_lines)`.
- If you need the tail of the file, fetch the whole artifact or compute offset as `line_count - n + 1`.
Example fix
// before
meta = output(["x"], format="json")
content = output(["x"], offset=500)
// after
meta = output(["x"], format="json")
offset = min(500, meta["line_count"])
if offset >= 1:
content = output(["x"], offset=offset) Defensive patterns
Strategy: validation
Validate before calling
meta = output(["x"], format="json")
if offset > meta["line_count"]:
offset = max(1, meta["line_count"]) Try / catch
try:
content = output(["x"], offset=offset, limit=limit)
except ValueError as e:
if "beyond end" in str(e):
content = output(["x"]) # artifact shorter than expected; read whole Prevention
- Read `line_count` via format="json" before paging, especially on regenerated artifacts.
- Never derive offset from char_count — offsets count lines, 1-based.
- Clamp or recompute offsets whenever the artifact may have changed between runs.
When it happens
Trigger: Calling `output(ids=["x"], offset=500)` when `x.md` has only 120 lines; using a line number from an older run's artifact on a shorter regenerated artifact.
Common situations: Hardcoded page offsets against artifacts whose length changed between runs; computing offset from `char_count` instead of `line_count`; off-by-one confusion between 0-based and 1-based numbering near the file end.
Related errors
- At least one output ID is required
- query cannot be combined with offset/limit
- agent() received invalid arguments: ${result.summary}
- completion() received invalid arguments: ${parsed.summary}
- Output {output_id} is not valid JSON: {e}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/39e8d54935ca7e8a.
Report an issue: GitHub.