{"record":{"id":"39e8d54935ca7e8a","repo":"can1357/oh-my-pi","slug":"offset-start-line-is-beyond-end-of-output-tota","errorCode":null,"errorMessage":"Offset {start_line} is beyond end of output ({total_lines} lines) for {output_id}","messagePattern":"Offset (.+?) is beyond end of output \\((.+?) lines\\) for (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/eval/py/prelude.py","lineNumber":241,"sourceCode":"                try:\n                    selected_content = (\n                        json.dumps(result_value, indent=2)\n                        if result_value is not None\n                        else \"null\"\n                    )\n                except (TypeError, ValueError):\n                    selected_content = str(result_value)\n\n            # Handle offset/limit\n            elif offset is not None or limit is not None:\n                start_line = max(1, offset or 1)\n                if start_line > total_lines:\n                    _emit_status(\n                        \"output\",\n                        id=output_id,\n                        error=f\"Offset {start_line} beyond end ({total_lines} lines)\",\n                    )\n                    raise ValueError(\n                        f\"Offset {start_line} is beyond end of output ({total_lines} lines) for {output_id}\"\n                    )\n\n                effective_limit = (\n                    limit if limit is not None else total_lines - start_line + 1\n                )\n                end_line = min(total_lines, start_line + effective_limit - 1)\n                selected_lines = raw_lines[start_line - 1 : end_line]\n                selected_content = \"\\n\".join(selected_lines)\n                range_info = {\n                    \"start_line\": start_line,\n                    \"end_line\": end_line,\n                    \"total_lines\": total_lines,\n                }\n\n            # Strip ANSI codes if requested\n            if format == \"stripped\":\n                import re","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/eval/py/prelude.py#L223-L259","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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`."],"exampleFix":"// before\nmeta = output([\"x\"], format=\"json\")\ncontent = output([\"x\"], offset=500)\n\n// after\nmeta = output([\"x\"], format=\"json\")\noffset = min(500, meta[\"line_count\"])\nif offset >= 1:\n    content = output([\"x\"], offset=offset)","handlingStrategy":"validation","validationCode":"meta = output([\"x\"], format=\"json\")\nif offset > meta[\"line_count\"]:\n    offset = max(1, meta[\"line_count\"])","typeGuard":null,"tryCatchPattern":"try:\n    content = output([\"x\"], offset=offset, limit=limit)\nexcept ValueError as e:\n    if \"beyond end\" in str(e):\n        content = output([\"x\"])  # artifact shorter than expected; read whole","preventionTips":["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."],"tags":["python","validation","out-of-range","eval"],"backgroundTag":"offset-out-of-range","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}