can1357/oh-my-pi · error
pr://${repo}/${parsed.number}/diff/${index} resolved to a mi
Error message
pr://${repo}/${parsed.number}/diff/${index} resolved to a missing slice (parser bug). What it means
This is an internal invariant assertion in fetchAndRenderPrDiff (packages/coding-agent/src/internal-urls/issue-pr-protocol.ts:476). A pr://<repo>/<n>/diff/<index> URL was parsed with a valid slice index (it passed the 1..files.length range check), but the array lookup files[index-1] still returned undefined. Since the range check at line 469 already guarantees index-1 is a valid array position, this can only happen if the files array and the unified diff offsets are inconsistent — hence '(parser bug)'.
Source
Thrown at packages/coding-agent/src/internal-urls/issue-pr-protocol.ts:476
contentType: "text/plain",
size: Buffer.byteLength(content, "utf-8"),
notes: [
freshness,
`Full diff for pr://${repo}/${parsed.number} (${files.length} file${files.length === 1 ? "" : "s"})`,
],
};
}
if (parsed.mode === "slice") {
const index = parsed.index ?? 0;
if (index < 1 || index > files.length) {
throw new Error(
`pr://${repo}/${parsed.number}/diff/${index} is out of range; PR has ${files.length} file${files.length === 1 ? "" : "s"}. Use pr://${repo}/${parsed.number}/diff to list available indices.`,
);
}
const file = files[index - 1];
if (!file) {
throw new Error(`pr://${repo}/${parsed.number}/diff/${index} resolved to a missing slice (parser bug).`);
}
const content = lookup.payload.unified.slice(file.startOffset, file.endOffset);
return {
url: url.href,
content,
contentType: "text/plain",
size: Buffer.byteLength(content, "utf-8"),
notes: [
freshness,
`Showing file ${index}/${files.length}: ${file.path}`,
`Read all: pr://${repo}/${parsed.number}/diff/all`,
],
};
}
// mode === "list"
const header = `# Pull Request Diff: ${repo}#${parsed.number} (${files.length} file${files.length === 1 ? "" : "s"})`;
const body =View on GitHub (pinned to 9690622007)
Solutions
- Report/log this as a bug in issue-pr-protocol.ts — the message explicitly marks it a parser bug; include the URL and the PR number.
- Clear the PR diff cache entry for the repo/PR so a freshly parsed payload with consistent files offsets is fetched, then retry the resolution.
- Inspect parseUrl's slice-index parsing for non-integer or coerced index values and make ParsedPrDiff.index strictly an integer.
- Verify the cache payload schema version matches what getOrFetchPrDiff writes; a stale-format cache can yield inconsistent files arrays.
Example fix
// before
const index = parsed.index ?? 0;
if (index < 1 || index > files.length) { throw ... }
const file = files[index - 1];
if (!file) throw new Error(`... (parser bug).`);
// after
const index = Number.isInteger(parsed.index) ? parsed.index : 0;
if (index < 1 || index > files.length) { throw ... }
const file = files[index - 1];
if (!file) throw new Error(`... (parser bug).`); // now unreachable for fractional/NaN indices Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check the slice index against the fetched payload before requesting the slice URL:
const listing = await prHandler.resolve(parse(`pr://${repo}/${n}/diff`));
const fileCount = Number((listing.content.match(/\((\d+) files?\)/) ?? [])[1] ?? 0);
if (!(index >= 1 && index <= fileCount)) throw new RangeError(`diff/${index} out of range (1..${fileCount})`); Type guard
function isValidSliceIndex(index: unknown, files: readonly unknown[]): index is number {
return typeof index === "number" && Number.isInteger(index) && index >= 1 && index <= files.length;
} Try / catch
try {
const res = await prHandler.resolve(parse(`pr://${repo}/${n}/diff/${i}`));
} catch (err) {
if (/resolved to a missing slice \(parser bug\)/.test(String(err.message))) {
logger.error("issue-pr-protocol parser bug", { url: `pr://${repo}/${n}/diff/${i}` });
// fall back to full diff:
return await prHandler.resolve(parse(`pr://${repo}/${n}/diff/all`));
}
throw err;
} Prevention
- Always fetch the diff listing first and pick an index within the reported file count.
- Report any occurrence of '(parser bug)' upstream — it indicates an internal invariant break, not user error.
- Pin/cache payload format expectations; clear stale caches when upgrading the library.
- Cover parseUrl slice parsing with integer-index tests when modifying the protocol.
When it happens
Trigger: Resolving pr://owner/repo/<n>/diff/<i> where parseUrl produced mode='slice' with an index that passes `index >= 1 && index <= files.length` yet files[index-1] is undefined. In practice only reachable if getOrFetchPrDiff returns a files array whose length changed between the bounds check and the element read (impossible in single-threaded sync code) or if the parsed index is a non-integer/NaN edge that slips the range comparison (e.g. index coercion quirks).
Common situations: Not hit by end-user mistakes; encountered by maintainers while modifying parseUrl or the PrDiffFile offset/segment extraction logic, or if a cached PR diff payload has a files array inconsistent with the unified diff it wraps (e.g. after a cache-format version change).
Related errors
- Invalid issue:// URL: unexpected variant '${parsed.kind}'
- Cache benchmark prefix template is missing its raw prefix pl
- Sloppy edit completed without a result.
- issue:// listing failed: ${message}
- issue:// resolution failed: ${message}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/995f1a8a3cc56d43.
Report an issue: GitHub.