Skip to content

fix(skills): cap every SKILL.md read at 1 MiB - #620

Merged
ajianaz merged 1 commit into
developfrom
fix/skill-read-cap
Nov 11, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/skill-read-cap

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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_skill refuses 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_skill read SKILL.md with read_to_string and 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 huge skills/x/SKILL.md was 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.
      • It opens the file (following a symlink, as SKILL.md loading always has), checks the opened file is a regular file, and refuses one whose length is over limit before reading.
      • It reads through read_capped, which stops one byte past limit (take(limit + 1)), so a file that grows after the check cannot allocate more.
      • On unix it opens with O_NONBLOCK, so a FIFO named SKILL.md is refused instead of blocking the session.
      • Errors are ReadCapError::{TooLarge, Io}.
    • load_skill: reads through it with MAX_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_search and LocalIndex.
    • 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_capped moved here from skill_approval.rs, so the gated walk and this reader share it.
  • skill_approval.rs:
    • Gate::Approved refuses an approved package whose SKILL.md is over 1 MiB, even though the 4 MiB package cap allows it.
    • Approvals::load reads through the capped reader (MAX_APPROVALS_BYTES, 1 MiB).
  • tole-cli skill_recall.rs: skills_section adds the listing notes to the startup notes. index_all (tole skills index) reads SKILL.md through the capped reader.
  • Docs: a threat-model note under Skills loading, and CHANGELOG.

Not in this PR: --skill <file> (owner-named, main.rs) still uses read_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 --workspace passes: 1460 passed, 0 failed (82 suites).
  • cargo test -p tole-core --no-default-features passes: 490 passed, 0 failed.
  • cargo test -p tole-cli --no-default-features passes: 427 passed, 0 failed.
  • cargo fmt --all -- --check passes.
  • cargo clippy --workspace --all-targets -- -D warnings passes, and so do cargo clippy -p tole-core --no-default-features --all-targets and cargo 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.
  • Manual smoke test: covered by the tests below, which use real files (sparse files and a FIFO).

New tests:

  • skills::tests::an_oversized_skill_md_is_refused_skipped_and_noted: a SKILL.md of 1 MiB + 1 is refused by load_skill, missing from available_skills and index_block, and named in listing_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, and tole skills index skips 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.

Broken variant Result
read not capped (take removed) killed (an_over_budget_file…: the panic-past-cap reader)
load_skill reads uncapped killed
non-regular files accepted killed (the FIFO case)
no listing note killed
approved gate skips the SKILL.md cap killed
approvals file uncapped killed
session notes dropped killed
length pre-check removed survives: the capped read still refuses one byte past the limit, so the pre-check is an early exit only
index_all reads uncapped survives: available_skills already skips an oversized skill before index_all reads it

Related Issues

Follow-up to #617 (#591, epic #589). The issue goes back to #161 (skills loading).

Checklist

  • Branch name follows convention (fix/skill-read-cap)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR

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).
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit be605c4 into develop Nov 11, 2026
19 of 20 checks passed
@ajianaz
ajianaz deleted the fix/skill-read-cap branch November 20, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants