Repository navigation
fix(skills): cap every SKILL.md read at 1 MiB - #620
Merged
Merged
Conversation
load_skill read SKILL.md with read_to_string and only then truncated the body, so in the default open mode a cloned repo with one huge skills/x/SKILL.md was read into memory at every session start (the discovery listing loads every skill). Every SKILL.md read now goes through one capped reader: the opened file's length is checked first and the read stops one byte past the cap, so a growing file cannot allocate more either. An oversized skill is left out of the listings with a startup note and refused by load_skill; the approved-hash gate refuses an oversized SKILL.md too. The reader refuses non-regular files and opens with O_NONBLOCK, so a FIFO named SKILL.md no longer hangs a session. tole skills index and the skill approvals file use the same reader (1 MiB).
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Every SKILL.md read now goes through one capped reader, with a 1 MiB limit. A huge SKILL.md is never read into memory: it is left out of the skill listings with a startup note, and
load_skillrefuses it. The skill approvals file is capped the same way.Why
This was found while fixing the same read-then-check pattern in #617, the Cora finding on
read_package.load_skillread SKILL.md withread_to_stringand only then cut the body to 16 KiB. In the default (open) mode, the discovery listing loads every discovered skill at every session start. So a cloned repo with one hugeskills/x/SKILL.mdwas read into memory for every user; a sparse multi-GiB file costs almost nothing in git. This has been there since #161.Changes
skills.rs:read_file_capped(path, limit): the shared reader.limitbefore reading.read_capped, which stops one byte pastlimit(take(limit + 1)), so a file that grows after the check cannot allocate more.O_NONBLOCK, so a FIFO named SKILL.md is refused instead of blocking the session.ReadCapError::{TooLarge, Io}.load_skill: reads through it withMAX_SKILL_FILE_BYTES(1 MiB). An oversized SKILL.md is an error naming the file (... is over 1048576 bytes). Every caller therefore leaves the skill out: the listings,select,skill_searchandLocalIndex.listing_notes(workspace): one note per discovered skill skipped for size, checked from the file length without reading the file. Session startup prints them.read_cappedmoved here fromskill_approval.rs, so the gated walk and this reader share it.skill_approval.rs:Gate::Approvedrefuses an approved package whose SKILL.md is over 1 MiB, even though the 4 MiB package cap allows it.Approvals::loadreads through the capped reader (MAX_APPROVALS_BYTES, 1 MiB).tole-cliskill_recall.rs:skills_sectionadds the listing notes to the startup notes.index_all(tole skills index) reads SKILL.md through the capped reader.Not in this PR:
--skill <file>(owner-named,main.rs) still usesread_to_string. Persona files already have their own 64 KiB cap.Testing
All run locally on head 106044a (one commit on develop 4f73cff):
cargo test --workspacepasses: 1460 passed, 0 failed (82 suites).cargo test -p tole-core --no-default-featurespasses: 490 passed, 0 failed.cargo test -p tole-cli --no-default-featurespasses: 427 passed, 0 failed.cargo fmt --all -- --checkpasses.cargo clippy --workspace --all-targets -- -D warningspasses, and so docargo clippy -p tole-core --no-default-features --all-targetsandcargo clippy -p tole-cli --no-default-features.cora review --no-llm --base origin/develop(cora v0.20.0): "No issues found". The LLM review is CI Cora Review.New tests:
skills::tests::an_oversized_skill_md_is_refused_skipped_and_noted: a SKILL.md of 1 MiB + 1 is refused byload_skill, missing fromavailable_skillsandindex_block, and named inlisting_notes. The approved gate refuses it even with its hash approved.skills::tests::read_file_capped_refuses_huge_files_and_non_files: a 1 TiB sparse file is refused from its length, the exact-limit and over-limit cases are checked, and a FIFO is refused without blocking.skill_approval::tests::approvals_round_trip_replace_revoke_and_fail_closed: extended so that an oversized approvals file is refused.skill_recall::tests::an_oversized_skill_is_noted_and_never_indexed: the session note is present, andtole skills indexskips the skill.Red/green: the new API was first added in its naive form (read everything, then compare). The three core tests failed against it: the oversized SKILL.md loaded, the 1 TiB read errored instead of reporting
TooLarge, and the approvals file said "malformed" instead of "over". With the capped reader wired in, all pass.Mutants: 7 of 9 killed.
takeremoved)an_over_budget_file…: the panic-past-cap reader)load_skillreads uncappedindex_allreads uncappedavailable_skillsalready skips an oversized skill beforeindex_allreads itRelated Issues
Follow-up to #617 (#591, epic #589). The issue goes back to #161 (skills loading).
Checklist
fix/skill-read-cap)develop