sea-loader.js: lexicographical localeCompare in fi() causes -9 to be selected over -10 / -11 in package cache
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 11.2k
- Forks
- 1.9k
- Avg merge
- 14h 16m
- Merged PRs (30d)
- 6
Description
Summary
In sea-loader.js, the local version comparison helper fi(e, t) uses e.localeCompare(t) to compare prerelease / build tag suffixes when major/minor/patch segments match.
Because "1.0.81-9".localeCompare("1.0.81-11") returns 1 (lexicographical sorting where '9' > '1'), the bootstrap loader determines that 1.0.81-9 is newer than 1.0.81-10 or 1.0.81-11. Consequently, even after copilot update successfully downloads and extracts 1.0.81-11 into the package cache (%LOCALAPPDATA%\copilot\pkg\win32-x64\1.0.81-11), launching copilot continues to execute the cached 1.0.81-9 version.
Root Cause Analysis
In sea-loader.js:
function fi(e, t) {
let i = kr(e), r = kr(t);
if (!i && !r) return 0;
if (!i) return -1;
if (!r) return 1;
for (let o = 0; o < 3; o++) {
if (i[o] !== r[o]) return i[o] - r[o];
}
let s = e.includes("-"), n = t.includes("-");
return s !== n ? (s ? -1 : 1) : e.localeCompare(t);
}
kr()parses the first 3 dot-delimited integer segments[major, minor, patch].- When comparing
1.0.81-9and1.0.81-11, the numeric segments[1, 0, 81]match. - Both strings include
-, sos !== nisfalse. - The fallback is
e.localeCompare(t). "1.0.81-9".localeCompare("1.0.81-11")evaluates to1(since'9' > '1').- In
mi("index.js", ...):
The version list is sorted descending usingi.sort((r, s) => { let n = fi(basename(s), basename(r)); return n !== 0 ? n : ...; });fi(), placing1.0.81-9at the top before1.0.81-11. hh()finds1.0.81-9and executes itsindex.js.
Steps to Reproduce
- Have both
1.0.81-9and1.0.81-11in%LOCALAPPDATA%\copilot\pkg\win32-x64\. - Run
copilot --version. - Observed: Outputs
GitHub Copilot CLI 1.0.81-9.. - Explicitly passing
--prefer-version 1.0.81-11(copilot --prefer-version 1.0.81-11 --version) outputsGitHub Copilot CLI 1.0.81-11.. - Renaming/removing
1.0.81-9immediately allows defaultcopilot --versionto outputGitHub Copilot CLI 1.0.81-11..
Suggested Fix
Implement SemVer-compliant prerelease identifier comparison in fi() by splitting the prerelease tag (e.g. on . or -) and comparing numeric identifiers as integers and string identifiers lexicographically:
function comparePrerelease(a, b) {
const parsePart = (p) => /^\d+$/.test(p) ? parseInt(p, 10) : p;
const partsA = a.replace(/^[^-]*-/, '').split('.').map(parsePart);
const partsB = b.replace(/^[^-]*-/, '').split('.').map(parsePart);
const len = Math.max(partsA.length, partsB.length);
for (let i = 0; i < len; i++) {
if (partsA[i] === undefined) return -1;
if (partsB[i] === undefined) return 1;
if (partsA[i] === partsB[i]) continue;
if (typeof partsA[i] === 'number' && typeof partsB[i] === 'number') {
return partsA[i] - partsB[i];
}
return String(partsA[i]).localeCompare(String(partsB[i]));
}
return 0;
}
Environment
- Platform: Windows 11 (
win32-x64) - Copilot CLI:
1.0.81-11binary loading1.0.81-9cached package
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in sea-loader.js with fi(e, t), then trace its use in mi() and hh(). Reproduce with cached versions 1.0.81-9 and 1.0.81-11, and compare copilot --version with --prefer-version. Done means the default loader selects 1.0.81-11 rather than the lexicographically higher 1.0.81-9.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100