Skip to content

fix(skills): copy cached skill summary fields so they stop pinning whole SKILL.md files - #52336

Merged
nwparker merged 1 commit into
stablyai:mainfrom
xwc2020-2:fix/skill-summary-retention
Nov 29, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
xwc2020-2:fix/skill-summary-retention

Conversation

@xwc2020-2

@xwc2020-2 xwc2020-2 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When Orca reads a skill file, it keeps only the skill's short name and description. Those short pieces of text were still tied to the whole file behind the scenes, so the entire file stayed in memory as long as the summary did. This change keeps separate copies of the name and description, so the file can be freed. Nothing you see changes. Orca just uses less memory when you have many large skills.

What Changed

  • Before: summarizeSkillMarkdown and declaredSkillMetadata in src/shared/skills/discovery/skill-metadata.ts returned name and description built with trim(), slice, regex groups and split. V8 stores these as sliced strings that point back to the full decoded SKILL.md. Each cached summary therefore kept the whole file text alive (up to the 256 KiB native read cap, or the whole file in the Claude command catalog).
  • After: both functions pass the two fields through the existing shared helper ownRetainedString (src/shared/text/own-retained-string.ts). The helper makes a flat copy with a UTF-16LE round trip that is checked against a test string first, and it skips strings too short to be slices. The returned text is identical.
  • Because the fix is in the shared summarizer, it covers every caller: native discovery (readSkillSummary and the scan cache), WSL observation, the Claude command-folder catalog, package and bundle work, and bot skill scans (admittedSkill in bot-skill-projects, bot-own-skills and bot-share-skills).
  • 1 file, +5/-3.

Why

A read-size limit does not stop a sliced string from holding on to the whole decoded document. The original PR added a local Buffer round trip in skill-discovery-summary.ts, which fixed the native discovery path only. This version reuses the existing shared helper at the producer, so there is no duplicate copier and every consumer is covered.

Linked Issue

Fixes #52334

Visual Proof

N/A. There is no UI or interaction change. Only the in-memory representation of identical metadata changes. Heap measurements are under Testing.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • Reproduced on macOS arm64 with node --expose-gc. 200 SKILL.md files of about 200 KB each, results kept, retained heap measured after GC, main vs this branch:

    • summarizeSkillMarkdown with plain, quoted, folded >-, heading/paragraph fallback and list fallback frontmatter: 38.6 MiB vs 0.0 to 0.25 MiB. CRLF+BOM was 0.4 MiB on both, because that shape never pinned the file on main.
    • declaredSkillMetadata followed by oneLine (same as admittedSkill): 38.6 MiB vs 0.2 MiB.
    • The real readSkillSummary called 320 times on a 250 KB SKILL.md: 51.5 MiB vs 0.3 MiB.
  • Output text matches main exactly, including lone surrogates, CJK, emoji, quoted values and BOM stripping.

  • No regression test is committed. A test that fails on revert would need --expose-gc heap measurement, which is not reliable in vitest. A text-fidelity test was tried and removed because it also passes on main.

  • vitest on src/main/skills/discovery, src/shared/skills, src/shared/text and src/main/skills/command-catalog: 36 of 38 pass. The 2 failures are in bot-linked-skills-discovery.test.ts, which reads real home skills, and they fail the same way on main with this file reverted.

  • oxlint, oxfmt --check, the anti-slop and native-plugin oxlint configs, ast-grep, and the changed-code quality gate are clean on the touched file.

  • Platforms: macOS only. The change is platform-neutral string handling in shared code.

Performance

Small, bounded per-call cost on a cold path. Median per call, main vs branch (summarizeSkillMarkdown):

  • typical skill: 0.41 vs 0.63 us
  • 250 KB ASCII description: 117 vs 169 us (single-call max 0.36 ms)
  • 240K-char Unicode description: 239 vs 280 us (max 0.35 ms)
  • 250 KB heading+paragraph fallback: 109 vs 213 us (max 0.59 ms)

declaredSkillMetadata is similar: typical 0.37 vs 0.65 us, worst case under 0.4 ms.

Both functions run once per SKILL.md per scan, after a file read, in main-process async skill scans (cached, 10 s TTL). They are not on a renderer, terminal-stream, polling or startup-critical path. There is no new I/O, subprocess or polling, the work does not grow with the number of open tabs or worktrees, and nothing comes near 16 ms. In exchange, retained memory drops by about 38 to 51 MiB per 200 to 320 large skills.

Risk

Level: Low. The main risk is the copy changing text. The helper checks a round-trip string with lone surrogates before using Buffer, and falls back to a code-unit copier where Buffer is missing. Alias detection and digests run on the same inputs as before. A plain revert backs this out, with no saved data or protocol changes.

Known follow-ups, out of scope and unchanged from main: WSL observation still keeps slices of WSL stdout through the skillFilePath/canonicalSkillFilePath fields (Windows/WSL only).

Review

Original fix by @xwc2020-2 in #52336. This version moves the copy into the shared summarizer and reuses the existing ownRetainedString helper. Authorship credit is kept via a Co-authored-by trailer.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: no new endpoints, execution or access changes. Cross-platform: pure string handling in shared code. Remote SSH and mobile: the payload shape is unchanged, so older paired clients are not affected. Backwards compatibility: no change to saved data.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the returned metadata stays unchanged while copies stop it from retaining larger Markdown strings.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; the returned metadata stays unchanged while copies stop it from retaining larger Markdown strings.

Summary

The PR copies skill names and descriptions before returning them, so cached summaries can release the larger Markdown text.

  • Skill metadata can stay cached without holding its Markdown document.

Reviews (2) · Last reviewed commit: "fix(skills): copy cached skill summary f..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

skill-metadata.ts now applies ownRetainedString to non-null name and description values returned by summarizeSkillMarkdown and declaredSkillMetadata. The return shapes and fallback conditions remain unchanged.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 4a61f

Skill discovery now keeps only the short name and description strings instead of retaining the whole Markdown body, which lowers memory growth. No behavior change or regression has been identified, so the change looks safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed [#52334] The issue requires that skill-scan cache entries keep only the name and description, not the decoded Markdown body. It also requires unchanged metadata text, modification time, and bundled-sk…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes one file: src/shared/skills/discovery/skill-metadata.ts (+5/-3). The import of ownRetainedString, the explanatory comment, and the wrapping of the retu…
Title check Passed The title names the main change: copying cached skill summary fields so they no longer keep whole SKILL.md files in memory. The raw summary confirms that skill-metadata.ts now routes name and descript…
Description check Passed The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #52334), Visual Proof (N/A with reason), Testing with checkboxes and heap measurements, …
Full details: Linked Issues check

Explanation

[#52334] The issue requires that skill-scan cache entries keep only the name and description, not the decoded Markdown body. It also requires unchanged metadata text, modification time, and bundled-skill identification. At head 4a61ffe, the whole-PR diff against the merge base changes only src/shared/skills/discovery/skill-metadata.ts. summarizeSkillMarkdown and declaredSkillMetadata now wrap each returned non-empty name and description in ownRetainedString. ownRetainedString (src/shared/text/own-retained-string.ts, already present at base) returns short strings (<13 code units) unchanged and copies longer strings through a UTF-16LE Buffer round trip, with a lone-surrogate probe. This creates new flat strings that do not pin the parent document. Empty and null fallbacks are unchanged (name ? ... : null equals name || null). readSkillSummary (src/main/skills/discovery/skill-discovery-summary.ts) is unchanged from base and still spreads the summary, so bundledSkillDiscoveryName still receives the same name and content. updatedAt still comes from fileStat.mtimeMs, and file reads and the 256 KiB limit are unchanged. The earlier detachFromMarkdown helper in the summary reader is no longer present, so the current PR description, which describes that helper, is stale. The requirement is still met by the current code. The retention reduction rests on the author's reported measurements and the copy mechanism; the reproducer was not executed in this review.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes one file: src/shared/skills/discovery/skill-metadata.ts (+5/-3). The import of ownRetainedString, the explanatory comment, and the wrapping of the returned name and description values all serve the objective in #52334 to stop cached summary fields from retaining the decoded Markdown. The helper modules (own-retained-string.ts and owned-utf16-suffix.ts) exist at the merge base and are not part of this diff. declaredSkillMetadata receives the same copy treatment; its values are unchanged, so the wider effect is limited to memory retention. No unrelated file or behavior change appears. The PR description still describes an earlier design (a detachFromMarkdown helper in skill-discovery-summary.ts). That mismatch is documentation drift, not an out-of-scope code change.

Full details: Title check

Explanation

The title names the main change: copying cached skill summary fields so they no longer keep whole SKILL.md files in memory. The raw summary confirms that skill-metadata.ts now routes name and description through ownRetainedString. The title uses the conventional fix(skills) prefix and is 87 characters, which is within a reasonable length.

Full details: Description check

Explanation

The description follows the repository template closely. It covers ELI5, What Changed, Why, Linked Issue (Fixes #52334), Visual Proof (N/A with reason), Testing with checkboxes and heap measurements, Performance with a stated reason, Risk with level Low and a revert path, AI Disclosure, the upstream boundary checkbox, Notes, and Checklist. Some items remain open: the Checklist item for pnpm lint, typecheck, test and build is unchecked, and the Risk section does not name the AI Disclosure content. The template's AI Disclosure section is empty, which is acceptable for an internal contributor, but the description does not state whether that applies. The description is mostly complete, so it passes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aac0bc8f-08fe-4844-b88f-245818e6d6e8
Commits

Reviewing files that changed from the base of the PR and between 9240761 and 4a61ffe.

Files selected for processing: 1

  • src/shared/skills/discovery/skill-metadata.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

…ole SKILL.md files

summarizeSkillMarkdown and declaredSkillMetadata returned V8 sliced
strings of the decoded SKILL.md, so every cached name/description kept
the whole file text alive. Copy both fields with the shared
ownRetainedString helper so the file text can be freed.

Fixes stablyai#52334

Co-authored-by: xwc2020-2 <[email protected]>
@nwparker
nwparker force-pushed the fix/skill-summary-retention branch from 9240761 to 4a61ffe Compare November 29, 2026 07:11
@nwparker nwparker changed the title fix(skills): detach cached summaries from Markdown bodies fix(skills): copy cached skill summary fields so they stop pinning whole SKILL.md files Nov 29, 2026
@nwparker
nwparker merged commit 8e91a75 into stablyai:main Nov 29, 2026
58 of 59 checks passed
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.

[Bug]: Skill discovery summaries retain Markdown bodies and grow the desktop V8 heap

2 participants