Adding clean-code from sickn33/agentic-awesome-skills in the market
failed with "GitHub's list of sickn33/agentic-awesome-skills's files
wasn't understood: unexpected end of JSON input" (CaiusLuo; stablyai/
orca the same, ye4241). The repository's download is over 200 MB, so
its skills are fetched file by file from GitHub's list of its files
(#1941), and that list is 11.3 MB: apiGet cut every answer at 8 MB and
dropped the read's error, so JSON was handed a cut-off body.
From ye4241's patch on the issue (made on 75e769a9, applied as is):
apiGet takes the most its caller reads and reads one byte past it; a
200 over it is an error naming the cap, a read that breaks is a read
error, a rate limit is told from the status and headers before either,
and only answers up to 8 MB are kept for a 304. The file list's cap is
64 MB (maxTree), lastCommit keeps 8 MB.
That alone wasn't enough for the reporter's case: the 8,589 skills of
that repository come to 287 MB together, over maxFetch, so the install
would then fail as "too big to install". On top of the patch:
- fetchSkillFiles fetches only what the caller reads: the skills under
src.Path, and for the market only the folders named as the skill it
installs (InstallMarketSkill -> cachedProbeFor/probeSkills; such a
probe is kept under its own key so a whole probe never takes it).
When no folder has that name every skill under the path is fetched,
as before.
- with a path (a link to a folder, an update, a check for new skills
under newBase) the list asked for is that folder's own, git's
ref:path (treeUnder; a few KB instead of 11 MB, and small enough to
be kept for a 304). When it can't be had (404, a ref git can't read
that way, cut off) the whole list is read, which says for sure what
is there, so goneFrom never trusts a 404. A rate limit is said at once.
- the fetcher kept one fetch per repository and ref for every skill of
it. A fetch narrowed to one skill's folder is now kept to that folder
(fetcher.get): another skill of the same repository gets a fetch of
its own, where it was read as removed upstream (broken by hand below).
- a CC Switch skill being adopted looks in the whole repository, since
its Path is only the folder's name.
- a probe of a folder whose skills are all too big lists it empty and
names them, as before; the whole repository's still fails.
- GitHub's own truncated list is errTooBig, by path or not
(TestTruncatedListIsTooBig).
- apiGet's client waits 2 minutes, not 20s, for an answer over 8 MB.
docs/subsystems/library.md says how far a big repository is fetched.
Tests (no network; fake codeload, API and raw):
- TestMarketSkillFromAHugeRepository: an 11 MB list, a download over
the limit and skills over it together. The market installs one, raw
is asked only for its files, and UpdateSkills of two of its skills
updates both, each asking for its own folder's list.
- TestRepoTreeBigList, TestApiGetWholeAnswer: ye4241's.
- the fake trees in skilltree_test and skillnew_test answer git's
ref:path as GitHub does (checked against api.github.com: HEAD:skills/
clean-code lists that folder, HEAD:nonexist is 404).
Broken by hand, each red, then restored:
- apiGet back to the 8 MB cut with the error dropped: both
TestRepoTreeBigList and TestMarketSkillFromAHugeRepository fail with
"unexpected end of JSON input".
- no name narrowing: "the skills in vectorize-io/hindsight are too big
to install".
- the fetcher sharing a narrowed fetch: Gone:[hindsight-docs].
- no ref:path list: the update listed ["HEAD" "HEAD"].
Run at this tree (65ee8c65c plus this change):
- gofmt -l internal: clean
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
vet ./...: clean
- go test -count=1 -timeout 45m ./internal/library/: ok 131s
- real: a throwaway realnet test in a sandbox HOME, no GitHub token,
InstallMarketSkill("sickn33/agentic-awesome-skills", "clean-code"):
installed in 15s, SKILL.md 5,202 bytes, Path skills/clean-code;
UpdateSkill then took 0.6s through its folder's list. The same test
at origin/main 65ee8c65c: "unexpected end of JSON input".
Not tried: the full ./... suite (only internal/library changed, other
sessions' suites were running); Windows and Linux runs (vet only); the
GUI (no GUI text changed); stablyai/orca for real.
Co-authored-by: ye4241 <ye4241@users.noreply.github.com>